From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25469 invoked by alias); 13 Feb 2006 22:56:30 -0000 Received: (qmail 25453 invoked by uid 48); 13 Feb 2006 22:56:27 -0000 Date: Mon, 13 Feb 2006 22:56:00 -0000 Subject: [Bug c++/26269] New: [3.4/4.0/4.1/4.2 regression] Declaring a variable too late yields bogus error message X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "reichelt at gcc dot gnu dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2006-02/txt/msg01424.txt.bz2 List-Id: 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: '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 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