Bug 14361 - [3.4/4.0 Regression] Accepting invalid code with weird default parameter trailer.
Summary: [3.4/4.0 Regression] Accepting invalid code with weird default parameter trai...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: 3.4.0
Assignee: Mark Mitchell
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2004-03-01 09:38 UTC by MattyT
Modified: 2004-10-30 21:11 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.3.1
Known to fail: 3.4.0 4.0.0
Last reconfirmed: 2004-03-01 09:55:36


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description MattyT 2004-03-01 09:38:44 UTC
The code:

class A {
   A ( int n=0 int n );
};

compiles in G++-3.4, but shouldn't, as I understand it.
Comment 1 Andrew Pinski 2004-03-01 09:55:35 UTC
Confirmed a regression from 3.3.1, also note it is even worse than that.
this is accepted:
struct A {
   A ( int n=0 ,int n1 );
};

And this is too:
struct A {
   A ( int n=0 i );
};

Looks the parser is ignorning anything after the default argument until the ')' token.
Comment 2 GCC Commits 2004-03-02 02:00:14 UTC
Subject: Bug 14361

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	mmitchel@gcc.gnu.org	2004-03-02 02:00:06

Modified files:
	gcc/cp         : ChangeLog decl.c parser.c pt.c 
	gcc/testsuite  : ChangeLog 
	gcc/testsuite/g++.old-deja/g++.ns: koenig5.C 
Added files:
	gcc/testsuite/g++.dg/parse: defarg7.C 
	gcc/testsuite/g++.dg/template: friend26.C 

Log message:
	PR c++/14360
	* parser.c (cp_parser_postfix_expression): Do not perform Koenig
	lookup if ordinary name-lookup finds a non-function.
	* pt.c (tsubst_copy_and_build): Likewise.
	
	PR c++/14361
	* parser.c (cp_parser_late_parsing_default_args): Check that there
	are no extra tokens after the end of the default-argument
	expression.
	
	Backport 2004-02-12  Mark Mitchell  <mark@codesourcery.com>
	* decl.c (redeclaration_error_message): Correct handling of
	templates.
	* pt.c (tsubst_friend_declaration): Adjust code to determine
	whether or not a friend template is a definition.
	(tsubst_decl): Clear DECL_INITIAL for new FUNCTION_DECLs.

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.65&r2=1.3892.2.66
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.1174.2.10&r2=1.1174.2.11
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.17&r2=1.157.2.18
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.15&r2=1.816.2.16
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.115&r2=1.3389.2.116
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/parse/defarg7.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/friend26.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++.old-deja/g++.ns/koenig5.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3&r2=1.3.16.1

Comment 3 GCC Commits 2004-03-02 02:06:26 UTC
Subject: Bug 14361

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2004-03-02 02:06:18

Modified files:
	gcc/cp         : ChangeLog parser.c pt.c 
	gcc/testsuite  : ChangeLog 
	gcc/testsuite/g++.old-deja/g++.ns: koenig5.C 
Added files:
	gcc/testsuite/g++.dg/parse: defarg7.C 
	gcc/testsuite/g++.dg/template: friend26.C 

Log message:
	PR c++/14360
	* parser.c (cp_parser_postfix_expression): Do not perform Koenig
	lookup if ordinary name-lookup finds a non-function.
	* pt.c (tsubst_copy_and_build): Likewise.
	
	PR c++/14361
	* parser.c (cp_parser_late_parsing_default_args): Check that there
	are no extra tokens after the end of the default-argument
	expression.
	
	PR c++/14360
	* g++.old-deja/g++.ns/koenig5.C: Remove some error markers.
	
	PR c++/14361
	* g++.dg/parse/defarg7.C: New test.
	
	PR c++/14359
	* g++.dg/template/friend26.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3981&r2=1.3982
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&r1=1.178&r2=1.179
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.834&r2=1.835
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3560&r2=1.3561
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/parse/defarg7.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/friend26.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.ns/koenig5.C.diff?cvsroot=gcc&r1=1.3&r2=1.4

Comment 4 Mark Mitchell 2004-03-02 02:06:57 UTC
Fixed in GCC 3.4 and GCC 3.5.
Comment 5 Mark Mitchell 2004-03-02 02:07:47 UTC
Fixed in GCC 3.4 and GCC 3.5.