Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Template class explicit instantiation ordering

9 views
Skip to first unread message

Karen Rei Pease

unread,
Jul 6, 2007, 5:21:04 PM7/6/07
to bug...@ftp.gnu.org
Ran into this behavior incompatibility across g++ versions today, and
simplified it down to this.

- Karen

---- test.cpp ----

/*
Issue: GCC 4.1.1 and 4.1.2 precompile f3() but do not generate assembly
for it, nor does it end up with f3() as a symbol in the object file.
That is, to say, any syntax error in f3() will throw an error for each
instantiation of it, but nm never shows f3(). GCC 3.4.5 works as
expected.

To note, f2() always gets compiled as expected. In short, GCC 4.1.1 and
GCC 4.1.2 require that explicit instantiation of classes come after the
template function declaration. I briefly searched through the standard
looking for a requirement that states that this must be the case, but
didn't find one (I could have missed it, though).

Which is proper behavior? GCC 3.4.5's seems more logical and
convenient, but if there's something in the standard that caused the
change, I'm curious as to what.
*/


template<class T> class MyClass // Class declaration
{
void f1() {};
void f2();
void f3();
};

template<class T> void MyClass<T>::f2() { } // Function call

template class MyClass<int>; // Explicitly instantiate the class

template<class T> void MyClass<T>::f3() { } // Function call


/*

g++ (GCC) 4.1.2 20070626 (Red Hat 4.1.2-13)

> g++ test.cpp -c -o test.o
> nm --demangle test.o
00000000 W MyClass<int>::f1()
00000000 W MyClass<int>::f2()
U __gxx_personality_v0

********

g++ (GCC) 4.1.1 20060828 (Red Hat 4.1.1-20)

> g++ test.cpp -c -o test.o
> nm --demangle test.o
00000000 W MyClass<int>::f1()
00000000 W MyClass<int>::f2()
U __gxx_personality_v0

********

g++ (GCC) 3.4.5 20051201 (Red Hat 3.4.5-2)

> g++ test.cpp -c -o test.o
> nm --demangle test.o
00000000 W MyClass<int>::f1()
00000000 W MyClass<int>::f2()
00000000 W MyClass<int>::f3()

*/


0 new messages