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

Eric Gallager <egallager at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2019-01-09
                 CC|                            |egallager at gcc dot gnu.org
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=26581
             Blocks|                            |87403
            Summary|Diagnostics improvement:    |Diagnostics improvement:
                   |Detection of undefined      |Detection of undefined
                   |behaviour. Incomplete type  |behaviour. Incomplete type
                   |in tenative definition with |in tenative definition with
                   |internal linkage.           |internal linkage.
                   |                            |[-Wtentative-definition-inc
                   |                            |omplete-type]
     Ever confirmed|0                           |1

--- Comment #2 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Anders Granlund from comment #0)
> 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.

No errors, sure, but I do get a warning from -Wunused-variable:

$ gcc -c -Wall -Wextra -std=c11 -pedantic-errors 88727.c
88727.c:1:17: warning: 's' defined but not used [-Wunused-variable]
 static struct S s;
                 ^
$

> 
> 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.

Confirmed that clang errors, its output is:

$ clang -c -Wall -Wextra -std=c11 -pedantic-errors 88727.c
88727.c:1:17: error: tentative definition of variable with internal linkage has
incomplete non-array type 'struct S'
[-Werror,-Wtentative-definition-incomplete-type]
static struct S s;
                ^
88727.c:1:15: note: forward declaration of 'struct S'
static struct S s;
              ^
1 error generated.
$

Since it's a warning-turned-into-an-error I'm making this block the new-warning
bug.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87403
[Bug 87403] [Meta-bug] Issues that suggest a new warning

Reply via email to