[Bug c/107164] New: No pedantic warning for declaration just referring to a previously-declared enum type

2022-10-05 Thread stephenheumann at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107164

Bug ID: 107164
   Summary: No pedantic warning for declaration just referring to
a previously-declared enum type
   Product: gcc
   Version: 13.0
Status: UNCONFIRMED
  Keywords: accepts-invalid
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: stephenheumann at gmail dot com
  Target Milestone: ---

gcc -std=c17 -pedantic accepts this without any diagnostics:

enum E {a,b,c};
enum E;

C17 section 6.7.2.3 p9 says that an "enum identifier" type specifier using a
tag with an existing declaration visible "specifies the same type as that other
declaration, and does not redeclare the tag". Accordingly, the second line
above does not declare a declarator, a tag, or the members of an enumeration,
and so it violates the constraint in C17 section 6.7 p2.

(The relevant standard text is basically the same from C99 through draft C23.
C90 is less explicit, but I think is intended to behave the same.)

This should at least give a pedantic warning. Perhaps it could be an
always-enabled warning, but I'm not sure if code like the above is supposed to
be allowed as a GCC extension.

[Bug c/107166] New: "useless type name in empty declaration" diagnostic may refer to wrong location

2022-10-05 Thread stephenheumann at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107166

Bug ID: 107166
   Summary: "useless type name in empty declaration" diagnostic
may refer to wrong location
   Product: gcc
   Version: 13.0
Status: UNCONFIRMED
  Keywords: diagnostic
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: stephenheumann at gmail dot com
  Target Milestone: ---

GCC seems to give a "useless type name in empty declaration" diagnostic for any
empty declaration containing a type, but it always just points to the first
token of the declaration, which is not necessarily the type (or may only be a
part of it). E.g.:

static int;
_Alignas(int) char;
long long;

gives the following diagnostics:

:1:1: warning: useless type name in empty declaration
1 | static int;
  | ^~
:2:1: warning: useless type name in empty declaration
2 | _Alignas(int) char;
  | ^~~~
:3:1: warning: useless type name in empty declaration
3 | long long;
  | ^~~~

These could be changed to actually refer to the location of the type
specifier(s), or they could be changed to different diagnostics that already
exist for empty declarations without a type, such as "useless storage class
specifier in empty declaration".

[Bug c/107926] New: wrong error message for excess elements in array initializer using a string literal

2022-11-29 Thread stephenheumann at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107926

Bug ID: 107926
   Summary: wrong error message for excess elements in array
initializer using a string literal
   Product: gcc
   Version: 13.0
Status: UNCONFIRMED
  Keywords: diagnostic
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: stephenheumann at gmail dot com
  Target Milestone: ---

char s[5] = {"abc",1};

gives the following error message:

:1:20: error: excess elements in struct initializer
1 | char s[5] = {"abc",1};
  |^
:1:20: note: (near initialization for 's')

There is no struct involved here, so the message is incorrect. It should
probably be 
"excess elements in array initializer".

[Bug c/108079] New: -Wunused-variable gives misleading duplicate warning for unused static local variable

2022-12-12 Thread stephenheumann at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108079

Bug ID: 108079
   Summary: -Wunused-variable gives misleading duplicate warning
for unused static local variable
   Product: gcc
   Version: 13.0
Status: UNCONFIRMED
  Keywords: diagnostic
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: stephenheumann at gmail dot com
  Target Milestone: ---

For this program:

int main(void) {
static int x;
}

gcc -Wunused-variable reports:

: In function 'main':
:2:20: warning: unused variable 'x' [-Wunused-variable]
2 | static int x;
  |^
: At top level:
:2:20: warning: 'x' defined but not used [-Wunused-variable]

These two warnings are about the same thing, except the second one is
incorrectly labeled "At top level." There should just be one warning, without
"At top level."

C++ does the same thing, except it says "At global scope" instead of "At top
level."

This seems to be a regression that occurred in GCC 6: 5.4 just gives one
warning, but 6.1 also gives the extra one with "At top level."