------- Comment #5 from reichelt at gcc dot gnu dot org  2006-02-14 17:13 
-------
Confirmed.

The ICE can be reduced to the following valid code snippet:

======================================
template<typename> struct A;

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

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

B<char> b;
======================================

bug.cc: In instantiation of 'const int B<char>::k':
bug.cc:12:   instantiated from 'B<char>'
bug.cc:15:   instantiated from here
bug.cc:11: internal compiler error: in build_c_cast, at cp/typeck.c:5231
Please submit a full bug report, [etc.]

This problem appeared with gcc 4.0.2, but does not show on the
current 4.0 branch. The ICE probably got only papered over, since
the following valid code is rejected now (it also caused an ICE
that appeared in GCC 4.0.2):

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

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

B<char> b;
======================================

bug.cc:13: error: variable-size type declared outside of any function
bug.cc:13: error: variable-size type declared outside of any function

This problem also exists on the 4.1 branch and mainline.

Last, but not least, the following valid code snippet is rejected
on the current 4.0 branch, as well as 4.1 branch and mainline:

======================================
template<typename> struct A
{
    static const int i = 1;
    static const int j = i;
    static const int k = int(j);
    int x[k];
};

A<char> a;
======================================

Mark, would you consider this a showstopper for the 4.1 release?


-- 

reichelt at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mark at codesourcery dot
                   |                            |com, reichelt at gcc dot gnu
                   |                            |dot org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |ice-on-valid-code,
                   |                            |monitored, rejects-valid
   Last reconfirmed|0000-00-00 00:00:00         |2006-02-14 17:13:05
               date|                            |
            Summary|ICE                         |[4.0/4.1/4.2 regression]
                   |                            |Trouble with static const
                   |                            |data members in template
                   |                            |classes
   Target Milestone|---                         |4.0.3


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26266

Reply via email to