bug-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Template class explicit instantiation ordering


From: Karen Rei Pease
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()

*/






reply via email to

[Prev in Thread] Current Thread [Next in Thread]