This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/17323] New: ICE on invalid code if static member array initialized with size computed as division by zero


The following tiny piece of C++ code causes an ICE:

---------------------- ice.cxx --------------------------------------
template <class T>
class A {
	static const int x = 1024/sizeof(T);	
	static char i[x];
};

class B : public A<B> { };
-------------------------------------------------------------------

Output after "gcc -c ice.cxx" is:
ice.cxx: In instantiation of `A<B>':
ice.cxx:8:   instantiated from here
ice.cxx:4: error: invalid application of `sizeof' to incomplete type `B' 
ice.cxx:4: warning: division by zero in `1024 / 0'
gcc: Internal error: Segmentation fault (program cc1plus)
Please submit a full bug report.


BTW: I would be very interested to hear if there's a legal (compile-time)
equivalent to the code above - so far I've found only clumsy work-arounds that
need run-time tests.

-- 
           Summary: ICE on invalid code if static member array initialized
                    with size computed as division by zero
           Product: gcc
           Version: 3.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: niemayer at isg dot de
                CC: gcc-bugs at gcc dot gnu dot org


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]