Bug 15786 - [3.4/4.0 Regression] Bad error message for frequently occuring error.
Summary: [3.4/4.0 Regression] Bad error message for frequently occuring error.
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 3.4.3
Assignee: Mark Mitchell
URL:
Keywords: diagnostic
: 16151 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-06-02 21:28 UTC by Carlo Wood
Modified: 2019-08-20 04:18 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 3.4.1 4.0.0
Last reconfirmed: 2004-06-02 22:20:12


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Carlo Wood 2004-06-02 21:28:43 UTC
I've run so many times into this now that I feel that it is important to get it
fixed.

The following code snippet,

struct A {
  void foo(bar* p);
};

Gives as error message:

>g++-cvs-3.5 -c test.cc
test.cc:2: error: variable or field `foo' declared void
test.cc:2: error: expected `;' before '(' token

Only when foo is not a member function, there also appears
a MUCH more correct error message:

test.cc:1: error: variable or field `foo' declared void
test.cc:1: error: `bar' was not declared in this scope
test.cc:1: error: `p' was not declared in this scope

If possible, the `bar' was not declared in this scope should
come first - and it should definitely also be printed in
the case of the member function.

3.4.0 does the same unclear thing.

You can consider this a regression because 3.3.3 gives most
sensible output:

>g++-3.3.3 -c test.cc
test.cc:2: error: `bar' was not declared in this scope
test.cc:2: error: `p' was not declared in this scope
test.cc:2: error: invalid data member initialization
test.cc:2: error: (use `=' to initialize static data members)
test.cc:2: error: variable or field `foo' declared void
Comment 1 Andrew Pinski 2004-06-02 22:20:12 UTC
Confirmed.
Comment 2 Mark Mitchell 2004-06-04 20:18:29 UTC
This is not a showstopper.
Comment 3 Wolfgang Bangerth 2004-07-22 12:58:40 UTC
*** Bug 16151 has been marked as a duplicate of this bug. ***
Comment 4 Mark Mitchell 2004-08-29 18:51:53 UTC
Postponed until GCC 3.4.3.
Comment 5 GCC Commits 2004-10-12 01:52:28 UTC
Subject: Bug 15786

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2004-10-12 01:52:20

Modified files:
	gcc/cp         : ChangeLog parser.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/parse: error22.C 

Log message:
	PR c++/15786
	* parser.c (cp_parser_declarator): Add member_p parameter.
	(cp_parser_condition): Adjust calls to cp_parser_declarator.
	(cp_parser_explicit_instantiation): Likewise.
	(cp_parser_init_declarator): Likewise.
	(cp_parser_direct_declarator): Add member_p parameter.  Do not
	parse tentatively when parsing the parameters to a member.
	(cp_parser_type_id): Adjust calls to cp_parser_declarator.
	(cp_parser_parameter_declaration): Likewise.
	(cp_parser_member_declaration): Likewise.
	(cp_parser_exception_declaration): Likewise.
	
	PR c++/15876
	* g++.dg/parse/error22.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4426&r2=1.4427
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&r1=1.262&r2=1.263
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4438&r2=1.4439
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/parse/error22.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 6 GCC Commits 2004-10-12 03:07:19 UTC
Subject: Bug 15786

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	mmitchel@gcc.gnu.org	2004-10-12 03:07:16

Modified files:
	gcc/cp         : ChangeLog parser.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/parse: error22.C 

Log message:
	PR c++/15786
	* parser.c (cp_parser_declarator): Add member_p parameter.
	(cp_parser_condition): Adjust calls to cp_parser_declarator.
	(cp_parser_explicit_instantiation): Likewise.
	(cp_parser_init_declarator): Likewise.
	(cp_parser_direct_declarator): Add member_p parameter.  Do not
	parse tentatively when parsing the parameters to a member.
	(cp_parser_type_id): Adjust calls to cp_parser_declarator.
	(cp_parser_parameter_declaration): Likewise.
	(cp_parser_member_declaration): Likewise.
	(cp_parser_exception_declaration): Likewise.
	
	PR c++/15876
	* g++.dg/parse/error22.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3892.2.168&r2=1.3892.2.169
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.157.2.43&r2=1.157.2.44
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.284&r2=1.3389.2.285
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/parse/error22.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1

Comment 7 Mark Mitchell 2004-10-12 03:17:39 UTC
Fixed in GCC 3.4.3.