[forwarded from http://bugs.debian.org/373909]
Rechecked with 4.1.2 20060630 and 4.2.0 The following code generates the g++ compiler error: 14: error: expected constructor, destructor, or type conversion before Outer template <typename T> class Outer { public: class Inner { }; Inner get() const; }; template <typename T> Outer<T>::Inner Outer<T>::get() const // <-- this is line 14 { return Inner(); } If the function get() is placed inside the template class Outer, no error is reported. E.g., template <typename T> class Outer { public: class Inner { }; Inner get() const { return Inner(); } }; An external definition compiles well if the class Inner is explicitly defined as a template class (even though no template parameters are required). E.g., template <typename T> class Outer { public: template <typename U> class Inner { }; Inner<T> get() const; }; template <typename T> Outer<T>::Inner<T> Outer<T>::get() const { return Inner<T>(); } Moreover, the first source, producing a compilation error with g++ was also offered to the intel C++ compiler, where it compiled flawlessly. Here is a transcript of the issued commands, illustrating the difference: [EMAIL PROTECTED]:~/programming/C++$ g++ -c -Wall demo1.cxx demo1.cxx:14: error: expected constructor, destructor, or type conversion before ?Outer? [EMAIL PROTECTED]:~/programming/C++$ icc -c -Wall demo1.cxx [EMAIL PROTECTED]:~/programming/C++$ My considerations for filing a bug report were: * g++ produces a compilation error where icc doesn't; * g++'s compilation error is only produced when the template function is defined outside of its template class; * the reported error message is rather cryptic, given the nature of the source, suggesting confusion on the part of the compiler. Of course, g++ might offer a more rigid implementation of the C++ standard at this point. However, I couldn't find a clear indication that the external function implementation violates the standard. Hence the bug report. -- Summary: template function returning nested class fails to compile when defined outside of its class Product: gcc Version: 4.1.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: debian-gcc at lists dot debian dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28317