Bug 31038 - [4.1 regression] ICE with C99 style compound literal vs templates vs instantiation
Summary: [4.1 regression] ICE with C99 style compound literal vs templates vs instanti...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.3.0
: P1 normal
Target Milestone: 4.2.0
Assignee: Mark Mitchell
URL:
Keywords: ice-on-valid-code, monitored
Depends on: 28255
Blocks:
  Show dependency treegraph
 
Reported: 2007-03-04 21:27 UTC by Volker Reichelt
Modified: 2008-07-04 16:03 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.2.0 4.3.0
Known to fail: 4.1.3
Last reconfirmed: 2007-03-04 22:00:04


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2007-03-04 21:27:32 UTC
The following valid code snippet triggers an ICE since GCC 4.1.0:

=============================
template<int> void foo()
{
  int i = (int) { 0 };
}

template void foo<0>();
=============================

bug.cc: In function 'void foo() [with int <anonymous> = 0]':
bug.cc:6:   instantiated from here
bug.cc:3: internal compiler error: in tsubst_copy, at cp/pt.c:8342
Please submit a full bug report, [etc.]
Comment 1 Andrew Pinski 2007-03-04 22:00:04 UTC
I can fix the testcase here by optimizing when we produce a CLEANUP_POINT_EXPR but the following testcase still fails at that point:

int f(void);
template<int> void foo()
{
  int i = (int) { f() };
}

template void foo<0>();
Comment 2 Andrew Pinski 2007-03-04 22:14:27 UTC
#8  0x0017dc54 in cp_parser_initializer_clause (parser=0x434e1dc0, non_constant_p=0xbffff039 "") at ../../gcc/cp/parser.c:12954
12954           initializer = fold_non_dependent_expr (initializer);

And fold_non_dependent_expr sets processing_template_decl to false.
Comment 3 Mark Mitchell 2007-03-12 00:26:51 UTC
Subject: Bug 31038

Author: mmitchel
Date: Mon Mar 12 00:26:39 2007
New Revision: 122829

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122829
Log:
	PR c++/30328
	* semantics.c (finish_typeof): Use unlowered_expr_type.
	
	PR c++/30328
	* g++.dg/ext/bitfield1.C: New test.

	PR c++/31038
	* parser.c (cp_parser_postfix_expression): Disallow compound
	literals in constant expressions.

	PR c++/31038
	* g++.dg/template/complit2.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/ext/bitfield1.C
    trunk/gcc/testsuite/g++.dg/template/complit2.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog

Comment 4 Mark Mitchell 2007-03-12 01:34:47 UTC
Fixed in 4.3.0.
Comment 5 Mark Mitchell 2007-03-12 01:52:57 UTC
Subject: Bug 31038

Author: mmitchel
Date: Mon Mar 12 01:52:45 2007
New Revision: 122830

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122830
Log:
	PR c++/31038
	* parser.c (cp_parser_postfix_expression): Disallow compound
	literals in constant expressions.

	PR c++/30328
	* semantics.c (finish_typeof): Use unlowered_expr_type.

	PR c++/31038
	* g++.dg/template/complit2.C: New test.

	PR c++/30328
	* g++.dg/ext/bitfield1.C: New test.

Added:
    branches/gcc-4_2-branch/gcc/testsuite/g++.dg/ext/bitfield1.C
    branches/gcc-4_2-branch/gcc/testsuite/g++.dg/template/complit2.C
Modified:
    branches/gcc-4_2-branch/gcc/cp/ChangeLog
    branches/gcc-4_2-branch/gcc/cp/parser.c
    branches/gcc-4_2-branch/gcc/cp/semantics.c
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog

Comment 6 Andrew Pinski 2008-05-28 23:54:54 UTC
What caused this regression was the change of representation of CONSTRUCTOR.  I can make this easy work with a simple patch which looks at values of the CONSTRUCTOR.
Comment 7 Joseph S. Myers 2008-07-04 16:03:21 UTC
Closing 4.1 branch.