https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91815
Bug ID: 91815 Summary: questionable error on type definition at file scope Product: gcc Version: 10.0 Status: UNCONFIRMED Keywords: rejects-valid Severity: minor Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: ebotcazou at gcc dot gnu.org Target Milestone: --- The C compiler currently rejects the following code: int f (void) { extern int t; extern float v; return (v > 0.0f); } typedef float t; t v = 4.5f; with the message: t.c:9:15: error: 't' redeclared as different kind of symbol 9 | typedef float t; | ^ t.c:3:14: note: previous declaration of 't' was here 3 | extern int t; | This behavior looks questionable and both Clang and MSVC disagree with GCC. And a cursory look at the relevant code in pushdecl seems to point to an overzealous implementation of C99 6.2.7p2, leading to a possible simple fix: Index: c-decl.c =================================================================== --- c-decl.c (revision 275746) +++ c-decl.c (working copy) @@ -3131,7 +3131,8 @@ pushdecl (tree x) what scope they are in; this is what we do here. (C99 6.2.7p2: All declarations that refer to the same object or function shall have compatible type; otherwise, the behavior is undefined.) */ - if (DECL_EXTERNAL (x) || scope == file_scope) + if ((DECL_EXTERNAL (x) || scope == file_scope) + && VAR_OR_FUNCTION_DECL_P (x)) { tree type = TREE_TYPE (x); tree vistype = NULL_TREE;