--- Begin Message ---
Subject: |
Template class explicit instantiation ordering |
Date: |
Fri, 06 Jul 2007 21:21:04 +0000 |
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()
*/
--- End Message ---
--- Begin Message ---
Subject: |
confirm 0d8f39639e3ad9b17ec9e4a86fb9c0372599ce7d |
If you reply to this message, keeping the Subject: header intact,
Mailman will discard the held message. Do this if the message is
spam. If you reply to this message and include an Approved: header
with the list password in it, the message will be approved for posting
to the list. The Approved: header can also appear in the first line
of the body of the reply.
--- End Message ---