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

            Bug ID: 99981
           Summary: Misleading "conflicting declaration" error message
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jmarshall at hey dot com
  Target Milestone: ---

For the following C++ snippet,

//// forward.cpp
struct foo;

typedef struct {
    int i;
} foo;

////

both GCC 10.2.0 and current trunk (according to godbolt.org) produce

forward.cpp:5:3: error: conflicting declaration 'typedef struct foo foo'
    5 | } foo;
      |   ^~~
forward.cpp:1:8: note: previous declaration as 'struct foo'
    1 | struct foo;
      |        ^~~

It is a relatively minor issue, but "typedef struct foo foo" in the first
diagnostic is misleading. I would have expected to see "typedef struct ... foo"
or similar.

(If the code had indeed been "typedef struct foo { /*...*/ } foo", there would
be no error.)

Reply via email to