I get a segmentation fault compiling the attached testcase with gcc 4.1. 4.0 and 4.2 seem to work. 4.1.2 20060901 (Debian 4.1.1-13) also worked but 4.1.2 20061007 (Debian 4.1.1-16) fails, at least on x86_64. (sid)1142:tbm@em64t: ~] g++-4.1 -c cinepaint-plugin_main.cpp cinepaint-plugin_main.cpp: In constructor ‘Camera<Unsign, Real>::Camera(Br_ImageVec&, std::vector<TNT::Array2D<Rgb<Unsign> >, std::allocator<TNT::Array2D<Rgb<Unsign> > > >&, unsigned int, ProgressInfo*)’: cinepaint-plugin_main.cpp:76: internal compiler error: Segmentation fault Please submit a full bug report, with preprocessed source if appropriate. See <URL:http://gcc.gnu.org/bugs.html> for instructions.
Created attachment 12413 [details] testcase
Ignore my comment about x86_64. I also see this on mips.
I think this is a sizeof issue: sizeof (Rgb < XYindex >)
(gdb) where #0 0x000000000045a5ce in cxx_sizeof_or_alignof_type (type=0x2b29cf3e6b00, op=214, complain=1 '\001') at /home/tbm/scratch/gcc-4.1/gcc/cp/typeck.c:1251 #1 0x000000000044a947 in cp_parser_unary_expression (parser=0x2b29cf261460, address_p=0 '\0', cast_p=0 '\0') at /home/tbm/scratch/gcc-4.1/gcc/cp/parser.c:4850 #2 0x000000000044ae15 in cp_parser_assignment_expression (parser=0x2b29cf261460, cast_p=Variable "cast_p" is not available. ) at /home/tbm/scratch/gcc-4.1/gcc/cp/parser.c:5579 #3 0x000000000044ba72 in cp_parser_parenthesized_expression_list (parser=0x2b29cf261460, is_attribute_list=240 '▒', cast_p=0 '\0', non_constant_p=0x0) at /home/tbm/scratch/gcc-4.1/gcc/cp/parser.c:4659 #4 0x000000000044a324 in cp_parser_unary_expression (parser=0x2b29cf261460, address_p=0 '\0', cast_p=1 '\001') at /home/tbm/scratch/gcc-4.1/gcc/cp/parser.c:4204 #5 0x000000000044ac41 in cp_parser_cast_expression (parser=0x2b29cf261460, address_p=0 '\0', cast_p=0 '\0') at /home/tbm/scratch/gcc-4.1/gcc/cp/parser.c:5455 ...
Reduced testcase: template < class T > struct Rgb; template < int>int Camera1 () { sizeof (Rgb < int>); }
The code in comment # 5 is invalid but even if we make it valid like below, it still ICEs: template < class T > struct Rgb{}; template < int>int Camera1 () { sizeof (Rgb < int>); }
Works in 4.0.4 20061011.
I think this was caused by PR 29226.
Also ICEs with 4.2.0 20061012 but did not with 4.2.0 20061002 (which I think was built before PR 29226 came in).
The problem is that we have not layouted out the type yet, if we had with something like: template < class T > struct Rgb{}; Rgb<int> t; template < int>int Camera1 () { sizeof (Rgb < int>); } We don't crash. Something like this fixes the ICE but I don't know if we should not call dependent_type_p twice or not, I have not checked if does causes an ICE for the testcase of PR 29226 or not: Index: ../../gcc/cp/typeck.c =================================================================== --- ../../gcc/cp/typeck.c (revision 117656) +++ ../../gcc/cp/typeck.c (working copy) @@ -1256,6 +1256,9 @@ cxx_sizeof_or_alignof_type (tree type, e value = size_one_node; } + if (!dependent_type_p (type)) + type = complete_type (type); + if (dependent_type_p (type) /* VLA types will have a non-constant size. In the body of an uninstantiated template, we don't need to try to compute the @@ -1271,7 +1274,7 @@ cxx_sizeof_or_alignof_type (tree type, e return value; } - return c_sizeof_or_alignof_type (complete_type (type), + return c_sizeof_or_alignof_type (type, op == SIZEOF_EXPR, complain); }
Subject: Bug 29435 Author: mmitchel Date: Mon Oct 16 23:06:35 2006 New Revision: 117799 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117799 Log: PR c++/29435 * typeck.c (cxx_sizeof_or_alignof_type): Complete non-dependent types when their sizes are required. Refine test for VLAs. PR c++/29435 * g++.dg/template/sizeof11.C: New test. Added: trunk/gcc/testsuite/g++.dg/template/sizeof11.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/typeck.c trunk/gcc/testsuite/ChangeLog
Fixed in 4.2.0.
Subject: Bug 29435 Author: mmitchel Date: Tue Oct 17 01:56:23 2006 New Revision: 117813 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117813 Log: PR c++/29435 * typeck.c (cxx_sizeof_or_alignof_type): Complete non-dependent types when their sizes are required. Refine test for VLAs. PR c++/29435 * g++.dg/template/sizeof11.C: New test. Added: branches/gcc-4_1-branch/gcc/testsuite/g++.dg/template/sizeof11.C Modified: branches/gcc-4_1-branch/gcc/cp/ChangeLog branches/gcc-4_1-branch/gcc/cp/typeck.c branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
Fixed in 4.1.2.
*** Bug 29698 has been marked as a duplicate of this bug. ***
*** Bug 30042 has been marked as a duplicate of this bug. ***