Bug 9311

Summary: [3.3 regression] ICE on illegal code using templates and inheritance
Product: gcc Reporter: neil.ferguson
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: gcc-bugs
Priority: P3 Keywords: ice-on-invalid-code
Version: 3.2.1   
Target Milestone: 3.3.1   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2003-06-02 09:09:06
Attachments: failure.cxx

Description neil.ferguson 2003-01-14 08:46:01 UTC
The attached (very small) source file causes an ICE when 
compiled. It defines two class templates, A and B, then 
tries to define class C as an inner class of B, inheriting 
from A. However, the definition of B does not include a 
declaration of C. 

Deleting the inheritance from A allows the compiler to 
correctly output this error: 

failure.cxx:17: invalid definition of qualified type `B<T>::C'
failure.cxx:17: `struct B<T>::<anonymous>' does not declare a template type

Uncommenting the declaration of C in B produces legal 
code, which the compiler compiles without trouble.

Release:
gcc version 3.2.1

Environment:
g++ -v:

Reading specs from /users/nf50041/lib/gcc-lib/sparc-sun-solaris2.8/3.2.1/specs
Configured with: ../gcc-3.2.1-original/configure --prefix=/users/nf50041 --with-gnu-as --with-gnu-ld --enable-languages=c,c++
Thread model: posix
gcc version 3.2.1

Also using binutils-2.13.1; uname -a gives: 

SunOS waverley 5.8 Generic_108528-13 sun4u sparc SUNW,Ultra-5_10

and the architecture is (Ultra) sparc32.

How-To-Repeat:
Run: 

g++ -c failure.cxx

and you should get: 

failure.cxx:17: internal error: Segmentation Fault
Comment 1 neil.ferguson 2003-01-14 08:46:01 UTC
Fix:
None known (write legal code :-)
Comment 2 Wolfgang Bangerth 2003-01-14 08:53:30 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirmed. The code ICEs with 3.0, 3.2 and 3.3. It produced
    a useful error with 2.95, and with present 3.4.
    
    Here's the code, for simpler cut-n-pasting:
    -----------------------
    template<typename T> class A {};
    
    template<typename T> class B {}; 
    
    template<typename T>
    class B<T>::C : public A<T> {}; 
    -----------------------
    
    W.
Comment 3 Mark Mitchell 2003-06-24 16:02:27 UTC

*** This bug has been marked as a duplicate of 5754 ***