Bug 13536 - [3.4 regression] parse error when parenthesized construction-style cast contains old-style cast
Summary: [3.4 regression] parse error when parenthesized construction-style cast conta...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.0
: P2 critical
Target Milestone: 3.4.0
Assignee: Mark Mitchell
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2003-12-31 23:47 UTC by David Baron
Modified: 2004-01-17 04:22 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2004-01-01 12:29:54


Attachments
testcase (49 bytes, text/plain)
2003-12-31 23:48 UTC, David Baron
Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Baron 2003-12-31 23:47:33 UTC
The following expression:

  return (int((char*)0));

yields the following errors on the gcc mainline:

$ /usr/local/gcc-3.4-20031231/bin/g++ parse.cpp                                
                                               
parse.cpp: In function `int main()':
parse.cpp:3: error: expected `)'
parse.cpp:3: error: expected `)'
parse.cpp:3: error: expected `;'
parse.cpp:3: error: expected primary-expression before ')' token
parse.cpp:3: error: expected `;'

It worked fine on the mainline on 20031002.
Comment 1 David Baron 2003-12-31 23:48:41 UTC
Created attachment 5395 [details]
testcase
Comment 2 Andrew Pinski 2004-01-01 00:39:26 UTC
Most likely caused by: <http://gcc.gnu.org/ml/gcc-cvs/2003-12/msg00658.html>.
Comment 3 Kriang Lerdsuwanakij 2004-01-01 12:29:54 UTC
Yup, it's a regression from 3.3.
Comment 4 Steven Bosscher 2004-01-04 09:36:20 UTC
This hunk of the patch to parser.c causes the problem:  
30a31,47  
> @@ -10900,6 +10905,16 @@  
>        bool saved_default_arg_ok_p = parser->default_arg_ok_p;  
>        parser->default_arg_ok_p = false;  
>  
> +      /* After seeing a decl-specifier-seq, if the next token is not a  
> +      "(", there is no possibility that the code is a valid  
> +      expression initializer.  Therefore, if parsing tentatively,  
> +      we commit at this point.  */  
> +      if (!parser->in_template_argument_list_p  
> +       && cp_parser_parsing_tentatively (parser)  
> +       && !cp_parser_committed_to_tentative_parse (parser)  
> +       && cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_PAREN))  
> +     cp_parser_commit_to_tentative_parse (parser);  
> +      /* Parse the declarator.  */  
>        declarator = cp_parser_declarator (parser,  
>                                        CP_PARSER_DECLARATOR_EITHER,  
>                                        /*ctor_dtor_or_conv_p=*/NULL,  
  
Making this P1 since it's a regression and a rejects-valid bug.  
  
Assigned to Mark since this was his patch.  
 
Comment 5 GCC Commits 2004-01-04 22:42:30 UTC
Subject: Bug 13536

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2004-01-04 22:42:22

Modified files:
	gcc/cp         : ChangeLog call.c parser.c 
	gcc/testsuite  : ChangeLog 
	libstdc++-v3   : ChangeLog 
	libstdc++-v3/testsuite/27_io/basic_filebuf: 4.cc 
	libstdc++-v3/testsuite/27_io/basic_fstream: 4.cc 
	libstdc++-v3/testsuite/27_io/basic_ifstream: 4.cc 
	libstdc++-v3/testsuite/27_io/basic_ios: 4.cc 
	libstdc++-v3/testsuite/27_io/basic_iostream: 4.cc 
	libstdc++-v3/testsuite/27_io/basic_istream: 4.cc 
	libstdc++-v3/testsuite/27_io/basic_istringstream: 4.cc 
	libstdc++-v3/testsuite/27_io/basic_ofstream: 4.cc 
	libstdc++-v3/testsuite/27_io/basic_ostream: 4.cc 
	libstdc++-v3/testsuite/27_io/basic_ostringstream: 4.cc 
	libstdc++-v3/testsuite/27_io/basic_stringbuf: 5.cc 
	libstdc++-v3/testsuite/27_io/basic_stringstream: 4.cc 
Added files:
	gcc/testsuite/g++.dg/init: copy7.C 
	gcc/testsuite/g++.dg/parse: cast1.C 

Log message:
	PR c++/12226
	* call.c (CHECK_COPY_CONSTRUCTOR_P): New macro.
	(reference_binding): Set it when appropriate.
	(build_temp): New function, split out from ...
	(convert_like_real): ... here.  Honor CHECK_COPY_CONSTRUCTOR_P.
	(initialize_reference): Likewise.
	
	PR c++/12226
	* g++.dg/init/copy7.c: New test.
	
	PR c++/12226
	* testsuite/27_io/basic_filebuf/4.cc: Remove use of invalid copy
	constructor.
	* testsuite/27_io/basic_fstream/4.cc: Likewise.
	* testsuite/27_io/basic_ifstream/4.cc: Likewise.
	* testsuite/27_io/basic_ios/4.cc: Likewise.
	* testsuite/27_io/basic_iostream/4.cc: Likewise.
	* testsuite/27_io/basic_istream/4.cc: Likewise.
	* testsuite/27_io/basic_istingstream/4.cc: Likewise.
	* testsuite/27_io/basic_ofstream/4.cc: Likewise.
	* testsuite/27_io/basic_ostream/4.cc: Likewise.
	* testsuite/27_io/basic_ostringstream/4.cc: Likewise.
	* testsuite/27_io/basic_stringbuf/5.cc: Likewise.
	* testsuite/27_io/basic_stringstream/4.cc: Likewise.
	
	PR c++/13536
	* parser.c (cp_parser): Add in_type_id_in_expr_p.
	(cp_parser_new): Initialize it.
	(cp_parser_postfix_expression): Set it.
	(cp_parser_sizeof_operand): Likewise.
	(cp_parser_parameteR_declaration): Do not commit early to tenative
	parsers when in_type_id_in_expr_p is set.
	
	PR c++/13536
	* g++.dg/parse/cast1.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3848&r2=1.3849
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/call.c.diff?cvsroot=gcc&r1=1.447&r2=1.448
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&r1=1.143&r2=1.144
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3331&r2=1.3332
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/copy7.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/parse/cast1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&r1=1.2193&r2=1.2194
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/27_io/basic_filebuf/4.cc.diff?cvsroot=gcc&r1=1.2&r2=1.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/27_io/basic_fstream/4.cc.diff?cvsroot=gcc&r1=1.2&r2=1.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/27_io/basic_ifstream/4.cc.diff?cvsroot=gcc&r1=1.2&r2=1.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/27_io/basic_ios/4.cc.diff?cvsroot=gcc&r1=1.2&r2=1.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/27_io/basic_iostream/4.cc.diff?cvsroot=gcc&r1=1.2&r2=1.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/27_io/basic_istream/4.cc.diff?cvsroot=gcc&r1=1.2&r2=1.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/27_io/basic_istringstream/4.cc.diff?cvsroot=gcc&r1=1.2&r2=1.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/27_io/basic_ofstream/4.cc.diff?cvsroot=gcc&r1=1.2&r2=1.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/27_io/basic_ostream/4.cc.diff?cvsroot=gcc&r1=1.2&r2=1.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/27_io/basic_ostringstream/4.cc.diff?cvsroot=gcc&r1=1.2&r2=1.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/27_io/basic_stringbuf/5.cc.diff?cvsroot=gcc&r1=1.2&r2=1.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/27_io/basic_stringstream/4.cc.diff?cvsroot=gcc&r1=1.2&r2=1.3

Comment 6 Mark Mitchell 2004-01-04 22:42:52 UTC
Fixed in GCC 3.4.