https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88727

            Bug ID: 88727
           Summary: Diagnostics improvement: Detection of undefined
                    behaviour. Incomplete type in tenative definition with
                    internal linkage.
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: anders.granlund.0 at gmail dot com
  Target Milestone: ---

Test case (prog.c):

  static struct S s;

  int main()
  {
  }

  struct S { int x; };

Compilation command line:

  gcc prog.c -Wall -Wextra -std=c11 -pedantic-errors 

Observed behaviour:

  No error messages outputes.

Possible improvement of behaviour:

  Outputing an error message about using an incomplete type in the tenative
  definition  static struct S s; .

  The program has undefined behaviour becuase of a violation of 6.9.2/2:

  "If the declaration of an identifier for an object is a tentative definition
   and has internal linkage, the declared type shall not be an incomplete
type."

  GCC detects such undefined behaviour in other cases (for example using the 
  incomplete type int []). It would be good if it could also hande the case in
  the test case for this bug report.

Note:

  Clang detects the undefined behaviour for this program and outputs an error
  message.

Reply via email to