Bug 15766 - bad parse error recovery (2 bugs)
Summary: bad parse error recovery (2 bugs)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2004-06-01 21:19 UTC by Peter Pirkelbauer
Modified: 2016-02-26 21:54 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.3.4, 6.0
Known to fail: 3.4.0, 4.0.0
Last reconfirmed: 2009-08-04 09:34:58


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Pirkelbauer 2004-06-01 21:19:07 UTC
You can find the diagnostic output at the end of this description.
The following code (ii-file) produces misleading error messages.

>>>>>>>>>>>>>>>>>>> ii-file begin <
# 1 "bug.cc"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "bug.cc"
void confusion1(const A& a) {}
 
void confusion2()
{ for (int i = 0; ; i++;) {}
}
>>>>>>>>>>>>>>>>>>> ii-file end <

The error messages are: 
(1)
bug.cc:1: error: expected `,' or `...' before '&' token
bug.cc:1: error: ISO C++ forbids declaration of `A' with no type

(2)
bug.cc: In function `void confusion2()':
bug.cc:4: error: expected `;' before ';' token
bug.cc:4: error: expected primary-expression before ')' token
bug.cc:4: error: expected `;' before ')' token

suggested behavior:
(1) The first line "bug.cc:1: error: expected `,' or `...' before '&' token"
tells nothing about the real cause and should not be displayed.

(2) produces 3 error messages, where only the second is correct; The other two
should not be displayed.

Thanks,
Peter

*************************** diagnostics *

Reading specs from /usr/local/lib/gcc/i686-pc-linux-gnu/3.4.0/specs
Configured with: ./configure --disable-libgcj --prefix=/usr/local/ngcc :
(reconfigured) ./configure --prefix=/usr/local --enable-languages=c++
Thread model: posix
gcc version 3.4.0
 /usr/local/libexec/gcc/i686-pc-linux-gnu/3.4.0/cc1plus -E -quiet -v
-D_GNU_SOURCE bug.cc -mtune=pentiumpro -o bug.ii
ignoring nonexistent directory
"/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.0/../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/lib/gcc/i686-pc-linux-gnu/3.4.0/../../../../include/c++/3.4.0
 /usr/local/lib/gcc/i686-pc-linux-gnu/3.4.0/../../../../include/c++/3.4.0/i686-pc-linux-gnu
 /usr/local/lib/gcc/i686-pc-linux-gnu/3.4.0/../../../../include/c++/3.4.0/backward
 /usr/local/include
 /usr/local/lib/gcc/i686-pc-linux-gnu/3.4.0/include
 /usr/include
End of search list.
 /usr/local/libexec/gcc/i686-pc-linux-gnu/3.4.0/cc1plus -fpreprocessed bug.ii
-quiet -dumpbase bug.cc -mtune=pentiumpro -auxbase bug -version -o bug.s
GNU C++ version 3.4.0 (i686-pc-linux-gnu)
        compiled by GNU C version 3.2.2 20030222 (Red Hat Linux 3.2.2-5).
GGC heuristics: --param ggc-min-expand=64 --param ggc-min-heapsize=64153
Comment 1 Wolfgang Bangerth 2004-06-01 21:46:08 UTC
Confirmed. This is a regression against 3.3.4 which simply printed 
g/x> /home/bangerth/bin/gcc-3.3.4-pre/bin/c++ -c x.cc 
x.cc:1: error: parse error before `&' token 
x.cc: In function `void confusion2()': 
x.cc:4: error: parse error before `;' token 
W. 
Comment 2 GCC Commits 2004-06-07 15:52:31 UTC
Subject: Bug 15766

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	mmitchel@gcc.gnu.org	2004-06-07 15:52:23

Modified files:
	gcc            : ChangeLog c-common.c 
	gcc/cp         : ChangeLog except.c parser.c pt.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/eh: throw1.C 
	gcc/testsuite/g++.dg/expr: sizeof3.C 
	gcc/testsuite/g++.dg/template: access14.C enum1.C 

Log message:
	PR c++/15337
	* error.c (c_sizeof_or_alignof_type): Use more detailed error
	message.
	
	PR c++/15766
	* parser.c (cp_parser_iteration_statement): Fix typo in error
	message.
	
	PR c++/14777
	* pt.c (tsubst_default_argument): Do not defer access checks
	while substituting into the default argument.
	
	PR c++/15554
	* pt.c (tsubst_copy): Do not try to substitute for an enumeration
	constant in a non-dependent context.
	
	PR c++/15057
	* except.c (build_throw): Ensure that temp_expr has been
	initialized.
	
	PR c++/15337
	* g++.dg/expr/sizeof3.C: New test.
	
	PR c++/14777
	* g++.dg/template/access14.C: New test.
	
	PR c++/15554
	* g++.dg/template/enum1.C: New test.
	
	PR c++/15057
	* g++.dg/eh/throw1.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.470&r2=2.2326.2.471
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-common.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.476.4.6&r2=1.476.4.7
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.115&r2=1.3892.2.116
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/except.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.164.4.4&r2=1.164.4.5
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.31&r2=1.157.2.32
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.816.2.28&r2=1.816.2.29
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.197&r2=1.3389.2.198
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/eh/throw1.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/expr/sizeof3.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/access14.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/enum1.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1

Comment 3 GCC Commits 2004-06-07 15:54:20 UTC
Subject: Bug 15766

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2004-06-07 15:54:15

Modified files:
	gcc            : ChangeLog c-common.c 
	gcc/cp         : ChangeLog except.c parser.c pt.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/eh: throw1.C 
	gcc/testsuite/g++.dg/expr: sizeof3.C 
	gcc/testsuite/g++.dg/template: access14.C enum1.C 

Log message:
	PR c++/15337
	* error.c (c_sizeof_or_alignof_type): Use more detailed error
	message.
	
	PR c++/15766
	* parser.c (cp_parser_iteration_statement): Fix typo in error
	message.
	
	PR c++/14777
	* pt.c (tsubst_default_argument): Do not defer access checks
	while substituting into the default argument.
	
	PR c++/15554
	* pt.c (tsubst_copy): Do not try to substitute for an enumeration
	constant in a non-dependent context.
	
	PR c++/15057
	* except.c (build_throw): Ensure that temp_expr has been
	initialized.
	
	PR c++/15337
	* g++.dg/expr/sizeof3.C: New test.
	
	PR c++/14777
	* g++.dg/template/access14.C: New test.
	
	PR c++/15554
	* g++.dg/template/enum1.C: New test.
	
	PR c++/15057
	* g++.dg/eh/throw1.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.3859&r2=2.3860
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-common.c.diff?cvsroot=gcc&r1=1.509&r2=1.510
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4083&r2=1.4084
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/except.c.diff?cvsroot=gcc&r1=1.167&r2=1.168
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&r1=1.200&r2=1.201
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.859&r2=1.860
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3816&r2=1.3817
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/eh/throw1.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/expr/sizeof3.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/access14.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/enum1.C.diff?cvsroot=gcc&r1=1.1&r2=1.2

Comment 4 Mark Mitchell 2004-06-07 16:22:26 UTC
The first error message in (2) has been fixed.

The rest of these are not and will never be show-stoppers; therefore, I've
removed the target milestone.
Comment 5 Manuel López-Ibáñez 2008-08-18 17:48:05 UTC
These are two different bugs.
Comment 6 Manuel López-Ibáñez 2009-08-04 09:34:58 UTC
For the first testcase, A could well be defined without type, so "const A" would be valid. So we definitely need to emit another error before '&' but the current one is misleading. Perhaps "parse error before '&'" is a solution. The alternative is to parse tentatively everything up to a comma or closing parenthesis and then find out what went wrong. That way, perhaps we can tell that A was meant to be a type but it is not declared. I wonder what comeau, clang and other c++ compilers report here.

Comment 7 Martin Sebor 2016-02-26 21:50:46 UTC
Author: msebor
Date: Fri Feb 26 21:50:15 2016
New Revision: 233765

URL: https://gcc.gnu.org/viewcvs?rev=233765&root=gcc&view=rev
Log:
PR c++/15766 - bad parse error recovery (2 bugs)

gcc/testsuite/ChangeLog:
2016-02-26  Martin Sebor  <msebor@redhat.com>

	PR c++/15766
	* g++.old-deja/g++.other/decl5.C: Add a test case.

Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.old-deja/g++.other/decl5.C
Comment 8 Martin Sebor 2016-02-26 21:54:03 UTC
With recent trunk of 6.0 GCC prints the following diagnostics for the test program.  I've added a test for the first diagnostic to the test suite in r233765.  Resolving as fixed.

t.c:1:23: error: ‘A’ does not name a type
 void confusion1(const A& a) {}
                       ^
t.c: In function ‘void confusion1(const int&)’:
t.c:1:26: warning: unused parameter ‘a’ [-Wunused-parameter]
 void confusion1(const A& a) {}
                          ^
t.c: In function ‘void confusion2()’:
t.c:4:24: error: expected ‘)’ before ‘;’ token
 { for (int i = 0; ; i++;) {}
                        ^
t.c:4:25: error: expected primary-expression before ‘)’ token
 { for (int i = 0; ; i++;) {}
                         ^