[Bug c/88727] Diagnostics improvement: Detection of undefined behaviour. Incomplete type in tenative definition with internal linkage. [-Wtentative-definition-incomplete-type]

2021-10-18 Thread jsm28 at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88727

Joseph S. Myers  changed:

   What|Removed |Added

 CC||pavel.morozkin at gmail dot com

--- Comment #3 from Joseph S. Myers  ---
*** Bug 102821 has been marked as a duplicate of this bug. ***

[Bug c/88727] Diagnostics improvement: Detection of undefined behaviour. Incomplete type in tenative definition with internal linkage. [-Wtentative-definition-incomplete-type]

2019-01-09 Thread egallager at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88727

Eric Gallager  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  ---
(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