Bug 28301

Summary: [4.3/4.4/4.5 regression] ICE with broken specialization
Product: gcc Reporter: Volker Reichelt <reichelt>
Component: c++Assignee: Lee Millward <lmillward>
Status: RESOLVED FIXED    
Severity: normal CC: fang, gcc-bugs, hjl.tools, jason
Priority: P4 Keywords: error-recovery, ice-on-invalid-code, monitored
Version: 4.3.4   
Target Milestone: 4.3.4   
URL: http://gcc.gnu.org/ml/gcc-patches/2009-03/msg01797.html
Host: Target:
Build: Known to work: 4.2.0
Known to fail: 4.0.4 4.1.3 Last reconfirmed: 2006-09-09 13:20:00

Description Volker Reichelt 2006-07-07 14:25:46 UTC
The following invalid code snippet triggers an ICE since GCC 3.4.0:

===========================================
template<typename> struct A
{
    template<int> void foo()  // missing ;
};

template<> struct A<void>
{
    template<int> void foo();
};

void bar()
{
    A<void> a;
    a.foo<0>();
}
===========================================

bug.cc:4: error: expected initializer before '}' token
bug.cc:6: error: explicit specialization in non-namespace scope 'struct A< <template-parameter-1-1> >'
bug.cc:6: error: enclosing class templates are not explicitly specialized
bug.cc:6: error: template parameters not used in partial specialization:
bug.cc:6: error:         '<template-parameter-1-1>'
bug.cc:15: error: expected `}' at end of input
bug.cc: In member function 'void A< <template-parameter-1-1> >::bar()':
bug.cc:14: internal compiler error: in retrieve_specialization, at cp/pt.c:819
Please submit a full bug report, [etc.]
Comment 1 Andrew Pinski 2006-09-03 06:30:41 UTC
Confiremed.
Comment 2 patchapp@dberlin.org 2006-09-09 13:20:30 UTC
Subject: Bug number PR c++/28301

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-09/msg00344.html
Comment 3 Volker Reichelt 2006-10-05 19:58:30 UTC
Fixed on mainline by Lee's patch for PR27667.
Comment 4 Gabriel Dos Reis 2007-02-03 17:57:05 UTC
Won't fix in GCC-4.0.x.  Adjusting milestone.
Comment 5 Joseph S. Myers 2008-07-04 15:40:20 UTC
Closing 4.1 branch.
Comment 6 Volker Reichelt 2009-03-28 21:40:50 UTC
The bug reappeared on the trunk and the 4.3 branch.
This was caused by

2009-03-18  H.J. Lu  <hongjiu.lu@intel.com>

	PR c++/39425
	* parser.c (cp_parser_explicit_specialization): Don't skip the
	rest of the specialization when begin_specialization returns
	false.
Comment 7 H.J. Lu 2009-03-28 21:56:35 UTC
Even if a bug is fixed by another patch for a different bug,
the testcase should be added to gcc.
Comment 8 H.J. Lu 2009-03-31 17:37:35 UTC
A patch is posted at

http://gcc.gnu.org/ml/gcc-patches/2009-03/msg01797.html
Comment 9 hjl@gcc.gnu.org 2009-04-10 18:56:22 UTC
Subject: Bug 28301

Author: hjl
Date: Fri Apr 10 18:56:07 2009
New Revision: 145936

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145936
Log:
gcc/cp/

2009-04-10  Jason Merrill  <jason@redhat.com>

	PR c++/28301
	* parser.c (cp_parser_skip_to_end_of_block_or_statement): Return
	if we see a close brace without an open brace.

gcc/testsuite/

2009-04-10  H.J. Lu  <hongjiu.lu@intel.com>

	PR c++/28301
	* g++.dg/cpp0x/enum2.C: Updated.
	* g++.dg/debug/pr22514.C: Likewise.
	* g++.dg/parse/enum2.C: Likewise.
	* g++.dg/parse/enum3.C: Likewise.
	* g++.dg/template/crash79.C: Likewise.
	* g++.old-deja/g++.jason/cond.C: Likewise.

	* g++.dg/template/pr28301.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/template/pr28301.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/cpp0x/enum2.C
    trunk/gcc/testsuite/g++.dg/debug/pr22514.C
    trunk/gcc/testsuite/g++.dg/parse/enum2.C
    trunk/gcc/testsuite/g++.dg/parse/enum3.C
    trunk/gcc/testsuite/g++.dg/template/crash79.C
    trunk/gcc/testsuite/g++.old-deja/g++.jason/cond.C

Comment 10 hjl@gcc.gnu.org 2009-04-10 19:01:32 UTC
Subject: Bug 28301

Author: hjl
Date: Fri Apr 10 19:01:16 2009
New Revision: 145938

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145938
Log:
gcc/cp/

2009-04-10  H.J. Lu  <hongjiu.lu@intel.com>

	Backport from mainline:
	2009-04-10  Jason Merrill  <jason@redhat.com>

	PR c++/28301
	* parser.c (cp_parser_skip_to_end_of_block_or_statement): Return
	if we see a close brace without an open brace.

gcc/testsuite/

2009-04-10  H.J. Lu  <hongjiu.lu@intel.com>

	Backport from mainline:
	2009-04-10  H.J. Lu  <hongjiu.lu@intel.com>

	PR c++/28301
	* g++.dg/cpp0x/enum2.C: Updated.
	* g++.dg/debug/pr22514.C: Likewise.
	* g++.dg/parse/enum2.C: Likewise.
	* g++.dg/parse/enum3.C: Likewise.
	* g++.dg/template/crash79.C: Likewise.
	* g++.old-deja/g++.jason/cond.C: Likewise.

	* g++.dg/template/pr28301.C: New.

Added:
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/template/pr28301.C
      - copied unchanged from r145937, trunk/gcc/testsuite/g++.dg/template/pr28301.C
Modified:
    branches/gcc-4_4-branch/gcc/cp/ChangeLog
    branches/gcc-4_4-branch/gcc/cp/parser.c
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/cpp0x/enum2.C
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/debug/pr22514.C
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/parse/enum2.C
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/parse/enum3.C
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/template/crash79.C
    branches/gcc-4_4-branch/gcc/testsuite/g++.old-deja/g++.jason/cond.C

Comment 11 hjl@gcc.gnu.org 2009-04-10 19:36:33 UTC
Subject: Bug 28301

Author: hjl
Date: Fri Apr 10 19:36:19 2009
New Revision: 145939

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145939
Log:
gcc/cp/

2009-04-10  H.J. Lu  <hongjiu.lu@intel.com>

	Backport from mainline:
	2009-04-10  Jason Merrill  <jason@redhat.com>

	PR c++/28301
	* parser.c (cp_parser_skip_to_end_of_block_or_statement): Return
	if we see a close brace without an open brace.

gcc/testsuite/

2009-04-10  H.J. Lu  <hongjiu.lu@intel.com>

	Backport from mainline:
	2009-04-10  H.J. Lu  <hongjiu.lu@intel.com>

	PR c++/28301
	* g++.dg/debug/pr22514.C: Updated.
	* g++.dg/parse/enum2.C: Likewise.
	* g++.dg/parse/enum3.C: Likewise.

	* g++.dg/template/pr28301.C: New.

Added:
    branches/gcc-4_3-branch/gcc/testsuite/g++.dg/template/pr28301.C
      - copied unchanged from r145938, trunk/gcc/testsuite/g++.dg/template/pr28301.C
Modified:
    branches/gcc-4_3-branch/gcc/cp/ChangeLog
    branches/gcc-4_3-branch/gcc/cp/parser.c
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_3-branch/gcc/testsuite/g++.dg/debug/pr22514.C
    branches/gcc-4_3-branch/gcc/testsuite/g++.dg/parse/enum2.C
    branches/gcc-4_3-branch/gcc/testsuite/g++.dg/parse/enum3.C

Comment 12 H.J. Lu 2009-04-10 19:37:38 UTC
Fixed.