bug in egcs-1.1.2 compiling C++ code on linux/x86 - nested classes in template class partial specialization

John Pedretti pedretti@roguewave.com
Tue Jul 27 12:21:00 GMT 1999


Compilation of the following (legal C++) code results in a bogus error
message (included below). The problem arises in the declaration of a
partially specialized template class which contains a nested class with a
constructor. It doesn't look like this is documented as a "well-known bug"
so I thought you might want to know about it. 

BTW, is there any chance that this bug is fixed in gcc-2.95?

Cheers, John

===========================
John A. Pedretti, Rogue Wave Software, Inc.   
(303) 545-3150     pedretti@roguewave.com  
===========================
******************* source file (foo.cpp) *******************************
template <class T1, class T2>// template class foo
template <class T1, class T2>
class foo {
};

// partial specialization of class foo
template <class T2>
class foo<int, T2>
{ 
      // nested class bar
    class bar { 
public: 
          // constructor
       bar() {}
    };
};   

int main () {
      // instantiation of partially specialized foo 
    foo<int, float> f;
    return 0;
}

************ preprocessed source (foo.ii) **************
# 1 "foo.cpp"
template <class T1, class T2>
class foo {
};

template <class T2>
class foo<int, T2>
{
    class bar { 
    public:
        bar() { }
    };
    bar b;
};   


int main () {
    foo<int, float> f2;
    return 0;
}

************ command line ****************

$ g++ foo.cpp

************ output **************


Reading specs from
/build/pedretti/egcs/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
 /build/pedretti/egcs/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.66/cpp
-lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus
-D__GNUC_MINOR__=91 -D__ELF__ -Dunix -Di386 -D__i386__ -Dlinux -D__ELF__
-D__unix__ -D__i386__ -D__i386__ -D__linux__ -D__unix -D__i386 -D__linux
-Asystem(posix) -D__EXCEPTIONS -Asystem(unix) -Acpu(i386) -Amachine(i386)
-Di386 -D__i386 -D__i386__ -Di686 -Dpentiumpro -D__i686 -D__i686__
-D__pentiumpro -D__pentiumpro__ foo.cpp foo.ii
GNU CPP version egcs-2.91.66 19990314 (egcs-1.1.2 release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /build/pedretti/egcs/include/g++
 /build/pedretti/egcs/i686-pc-linux-gnu/include
 /build/pedretti/egcs/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.66/include
 /usr/include
End of search list.
 /build/pedretti/egcs/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.66/cc1plus
foo.ii -quiet -dumpbase foo.cc -version -o foo.s
GNU C++ version egcs-2.91.66 19990314 (egcs-1.1.2 release)
(i686-pc-linux-gnu) compiled by GNU C version egcs-2.91.66 19990314
(egcs-1.1.2 release).
foo.cpp: In instantiation of `foo<int,float>::bar::bar<int>()':
foo.cpp:16:   instantiated from here
foo.cpp:10: new declaration `foo<int,int>::bar::bar<>()'
foo.cpp:10: ambiguates old declaration `foo<int,float>::bar::bar<int>()'





More information about the Gcc-bugs mailing list