Compiling the invalid code snippet ================== void foo() { i; int i; } ==================
yields the following error message (since GCC 3.4.5): bug.cc: In function 'void foo()': bug.cc:3: error: 'i' was not declared in this scope bug.cc:4: error: redeclaration of 'int i' bug.cc:3: error: '<typeprefixerror>i' previously declared here The error about the redeclaraion is bogus here. It is issued because we created a dummy declaration of 'i' to suppress further error messages about 'i' being not declared. Since the dummy declaration contains an error_mark_node as TREE_TYPE (which btw. causes the <typeprefixerror> part) we should be able to detect this case and skip issuing the redeclaration error message. In fact we do attempt something like this in duplicate_decls: /* If either the type of the new decl or the type of the old decl is an error_mark_node, then that implies that we have already issued an error (earlier) for some bogus type specification, and in that case, it is rather pointless to harass the user with yet more error message about the same declaration, so just pretend the types match here. */ if (TREE_TYPE (newdecl) == error_mark_node || TREE_TYPE (olddecl) == error_mark_node) types_match = 1; We indeed have TREE_TYPE (olddecl) == error_mark_node in the testcase above, but apparently just setting types_match = 1 is not enough. Is it possible to get rid of olddecl altogether and replace it with newdecl? -- Summary: [3.4/4.0/4.1/4.2 regression] Declaring a variable too late yields bogus error message Product: gcc Version: 4.2.0 Status: UNCONFIRMED Keywords: diagnostic, monitored Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: reichelt at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26269