gcc 4.3.1 fails to diagnose the following ill-formed program: template <class T> struct S { T foo (); }; template <class T> T S<T>::foo () { return T (); }
template struct S<int>; extern template struct S<int>; int main () { return S<int>().foo (); } See the discussion thread below for more detail: John H. Spicer wrote: > > On Dec 30, 2008, at 2:10 PM, Martin Sebor wrote: > >> To: C++ core language mailing list >> Message c++std-core-13732 >> >> The discussion on the subject of extern template and vtables >> reminded me of the case below that still passes with at least >> one recent compiler and fails with another and which I'm still >> not sure is intended to be well-formed or not. I'm hoping this >> is a good time to revisit it and get the issue settled. > > 14.7.2p10 says: > > If an entity is the subject of both an explicit instantiation > declaration and an explicit instantiation definition > in the same translation unit, the definition shall follow the declaration. > > > This makes your example ill-formed. > > John Spicer > Edison Design Group > >> >> >> Thanks! >> Martin >> >> Martin Sebor wrote: >>> To: C++ core language mailing list >>> Message c++std-core-11080 >>> The following piece of code compiles successfully with 2 compilers >>> and fails with 2 others. I can't tell from N1448 whether it was >>> intended to be well-formed or (if so) what the expected behavior >>> should be. Could someone clarify? >>> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1448.pdf >>> Thanks in advance! >>> Martin >>> template <class T> struct S { T foo (); }; >>> template <class T> T S<T>::foo () { return T (); }; >>> template struct S<int>; >>> extern template struct S<int>; >>> int main () { return S<int>().foo (); } -- Summary: extern template declaration accepted after explicit instantiation Product: gcc Version: 4.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: sebor at roguewave dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38677