Bug 31992 - [4.1 regression] ICE initializing static variable of template class
Summary: [4.1 regression] ICE initializing static variable of template class
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.3.0
: P1 normal
Target Milestone: 4.2.1
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code, monitored
Depends on:
Blocks:
 
Reported: 2007-05-18 22:52 UTC by Volker Reichelt
Modified: 2008-07-04 16:06 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.4.0 4.2.0 4.3.0
Known to fail: 4.1.3
Last reconfirmed: 2007-07-06 01:36:26


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2007-05-18 22:52:13 UTC
The following valid code snippet triggers a segfault since GCC 4.1.2:

=============================================
template<int> struct A
{
    static const int i;
};

template<int N> const int A<N>::i( A::i );
=============================================

bug.cc:6: internal compiler error: Segmentation fault
Please submit a full bug report, [etc.]
Comment 1 Dave Brolley 2007-07-05 20:05:10 UTC
I've worked on this a bit and just realized that it's assigned to Mark Mitchell. However, here's what I've learned, in case it helps...

The segfault occurs in convert_for_initialization because the TREE_TYPE of rhs is NULL_TREE. This is because the tree is a SCOPE_REF referring to A and i. The TREE_TYPE was set to NULL_TREE because A is a dependent type. Now, it's documented in build_qualified_name in cp/tree.c that a SCOPE_REF has NULL type in the event that the expression represents a dependent type. However, since i does not depend on any of the template parameters of A, I think that A::i is not a dependent type and that the TREE_TYPE should have been set to the type of i.
Comment 2 Mark Mitchell 2007-07-06 01:24:12 UTC
Subject: Bug 31992

Author: mmitchel
Date: Fri Jul  6 01:23:54 2007
New Revision: 126399

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126399
Log:
	PR c++/32245
	* init.c (build_zero_init): Always build an initializer for
	non-static storage.
	* typeck2.c (build_functional_cast): Use build_zero_init.

	PR c++/32251
	* init.c (build_new_1): Always pass the allocation function to
	build_op_delete_call.
	* call.c (build_op_delete_call): Handle operator delete with a
	variable-argument list.  Do not issue an error when no matching
	deallocation function is available for a new operator.

	PR c++/31992
	* cp-tree.h (any_value_dependent_elements_p): Declare it.
	* decl.c (value_dependent_init_p): New function.
	(cp_finish_decl): Use it.
	* pt.c (value_dependent_expression_p): Use
	any_value_dependent_elements_p.
	* parser.c (cp_parser_primary_expression): Add comment about
	treating dependent qualified names as integral
	constant-expressions.

	PR c++/32245
	* g++.dg/init/ptrmem4.C: New test.

	PR c++/32251
	* g++.dg/init/new21.C: Likewise.

	PR c++/31992
	* g++.dg/template/static30.C: Likewise.

Added:
    trunk/gcc/testsuite/g++.dg/init/new21.C
    trunk/gcc/testsuite/g++.dg/init/ptrmem4.C
    trunk/gcc/testsuite/g++.dg/template/static30.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/decl.c
    trunk/gcc/cp/init.c
    trunk/gcc/cp/parser.c
    trunk/gcc/cp/pt.c
    trunk/gcc/cp/typeck2.c
    trunk/gcc/testsuite/ChangeLog

Comment 3 Mark Mitchell 2007-07-06 01:36:26 UTC
Fixed in 4.3.0.
Comment 4 Mark Mitchell 2007-07-07 02:02:55 UTC
Subject: Bug 31992

Author: mmitchel
Date: Sat Jul  7 02:02:37 2007
New Revision: 126433

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126433
Log:
	PR c++/32245
	* init.c (build_zero_init): Always build an initializer for
	non-static storage.
	* typeck2.c (build_functional_cast): Use build_zero_init.

	PR c++/32251
	* init.c (build_new_1): Always pass the allocation function to
	build_op_delete_call.
	* call.c (build_op_delete_call): Handle operator delete with a
	variable-argument list.  Do not issue an error when no matching
	deallocation function is available for a new operator.

	PR c++/31992
	* cp-tree.h (any_value_dependent_elements_p): Declare it.
	* decl.c (value_dependent_init_p): New function.
	(cp_finish_decl): Use it.
	* pt.c (value_dependent_expression_p): Use
	any_value_dependent_elements_p.
	* parser.c (cp_parser_primary_expression): Add comment about
	treating dependent qualified names as integral
	constant-expressions.

	PR c++/32245
	* g++.dg/init/ptrmem4.C: New test.

	PR c++/32251
	* g++.dg/init/new21.C: Likewise.

	PR c++/31992
	* g++.dg/template/static30.C: Likewise.

Added:
    branches/gcc-4_2-branch/gcc/testsuite/g++.dg/init/new21.C
    branches/gcc-4_2-branch/gcc/testsuite/g++.dg/init/ptrmem4.C
    branches/gcc-4_2-branch/gcc/testsuite/g++.dg/template/static30.C
Modified:
    branches/gcc-4_2-branch/gcc/cp/ChangeLog
    branches/gcc-4_2-branch/gcc/cp/call.c
    branches/gcc-4_2-branch/gcc/cp/cp-tree.h
    branches/gcc-4_2-branch/gcc/cp/decl.c
    branches/gcc-4_2-branch/gcc/cp/init.c
    branches/gcc-4_2-branch/gcc/cp/parser.c
    branches/gcc-4_2-branch/gcc/cp/pt.c
    branches/gcc-4_2-branch/gcc/cp/typeck2.c
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog

Comment 5 Joseph S. Myers 2008-07-04 16:06:39 UTC
Closing 4.1 branch.