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.]
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>();
#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.
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
Fixed in 4.3.0.
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
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.
Closing 4.1 branch.