Bug 27819 - [4.0 regression] ICE casting static const variables
Summary: [4.0 regression] ICE casting static const variables
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.2.0
: P1 normal
Target Milestone: 4.1.2
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code, monitored
Depends on:
Blocks:
 
Reported: 2006-05-30 12:22 UTC by Volker Reichelt
Modified: 2007-02-03 17:27 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.1.2 4.2.0
Known to fail: 4.1.1
Last reconfirmed: 2006-09-17 07:48:24


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2006-05-30 12:22:46 UTC
The following valid code snippet causes an ICE since GCC 4.0.0
(it was wrongly rejected in GCC 3.4.x):

======================================
struct A
{
    static const char i = 1;
};

template<int> struct B
{
    static const int j = A::i;
    int x[int(j)];
};

B<0> b;
======================================

bug.cc:9: internal compiler error: in build_c_cast, at cp/typeck.c:5252
Please submit a full bug report, [etc.]

This is related to PR 26266.
Comment 1 Wolfgang Bangerth 2006-05-31 02:31:57 UTC
I confirm the ICE with 4.0.x. With 4.1.x, we get a duplicate error message:

g/x> /home/bangerth/bin/gcc-4.1-pre/bin/c++ -c x.cc
x.cc:12: error: variable-size type declared outside of any function
x.cc:12: error: variable-size type declared outside of any function

I'm not completely sure whether the testcase is invalid (I suppose the cast
can not be part of a constant expression). icc accepts the code.

W.
Comment 2 Mark Mitchell 2006-06-05 02:46:51 UTC
Subject: Bug 27819

Author: mmitchel
Date: Mon Jun  5 02:46:38 2006
New Revision: 114382

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114382
Log:
	PR c++/27819
	* decl.c (cp_finish_decl): Process initializers for static data
	members with non-dependent initializers, even in templates.
	PR c++/27722
	* decl.c (maybe_deduce_size_from_array_init): If the declaration
	is erroneous, give it an erroneous type.
	(layout_var_decl): If the type is erroneous, give up.
	(check_initializer): Likewise.
	PR c++/27807
	* cp-tree.h (TYPE_OBJ_P): New macro.
	(TYPE_PTROB_P): Use it.
	(TYPE_REF_OBJ_P): Likewise.
	* semantics.c (finish_compound_literal): Do not permit compound
	literals of non-object types.
	PR c++/27806
	* typeck.c (original_type): Robustify.
	PR c++/27819
	* g++.dg/template/static25.C: New test.
	PR c++/27722
	* g++.dg/init/array21.C: New test.
	PR c++/27807
	* g++.dg/ext/complit7.C: New test.
	
	PR c++/27806
	* g++.dg/parse/ptrmem5.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/ext/complit7.C
    trunk/gcc/testsuite/g++.dg/init/array21.C
    trunk/gcc/testsuite/g++.dg/parse/ptrmem5.C
    trunk/gcc/testsuite/g++.dg/template/static25.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/decl.c
    trunk/gcc/cp/semantics.c
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/ChangeLog

Comment 3 Mark Mitchell 2006-06-05 02:52:48 UTC
Subject: Bug 27819

Author: mmitchel
Date: Mon Jun  5 02:52:37 2006
New Revision: 114383

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114383
Log:
	PR c++/27819
	* decl.c (cp_finish_decl): Process initializers for static data
	members with non-dependent initializers, even in templates.
	PR c++/27722
	* decl.c (maybe_deduce_size_from_array_init): If the declaration
	is erroneous, give it an erroneous type.
	(layout_var_decl): If the type is erroneous, give up.
	(check_initializer): Likewise.
	PR c++/27807
	* cp-tree.h (TYPE_OBJ_P): New macro.
	(TYPE_PTROB_P): Use it.
	(TYPE_REF_OBJ_P): Likewise.
	* semantics.c (finish_compound_literal): Do not permit compound
	literals of non-object types.
	PR c++/27806
	* typeck.c (original_type): Robustify.
	PR c++/27819
	* g++.dg/template/static25.C: New test.
	PR c++/27722
	* g++.dg/init/array21.C: New test.
	PR c++/27807
	* g++.dg/ext/complit7.C: New test.
	
	PR c++/27806
	* g++.dg/parse/ptrmem5.C: New test.

Added:
    branches/gcc-4_1-branch/gcc/testsuite/g++.dg/ext/complit7.C
    branches/gcc-4_1-branch/gcc/testsuite/g++.dg/init/array21.C
    branches/gcc-4_1-branch/gcc/testsuite/g++.dg/parse/ptrmem5.C
    branches/gcc-4_1-branch/gcc/testsuite/g++.dg/template/static25.C
Modified:
    branches/gcc-4_1-branch/gcc/cp/ChangeLog
    branches/gcc-4_1-branch/gcc/cp/cp-tree.h
    branches/gcc-4_1-branch/gcc/cp/decl.c
    branches/gcc-4_1-branch/gcc/cp/semantics.c
    branches/gcc-4_1-branch/gcc/cp/typeck.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog

Comment 4 Mark Mitchell 2006-06-05 02:53:06 UTC
Fixed in 4.1.2, 4.2.0.
Comment 5 Gabriel Dos Reis 2007-02-03 17:27:14 UTC
Fixed in GCC-4.1.2