The program below fails to link with g++ 4.0 on Solaris 9 (I didn't try Linux).
It appears that symbols defined after the explicit instantiation directive
aren't emitted even when referenced. This works fine with prior versions of gcc.

$ cat u.cpp && g++ u.cpp
template <class T> struct S { T foo (); T bar (); };
template <class T> T S<T>::foo () { return bar (); }
template struct S<int>;
template <class T> T S<T>::bar () { return T (); }

int main () { return S<int>().foo (); }
Undefined                       first referenced
 symbol                             in file
S<int>::bar()                       /var/tmp//cc4BNMlG.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status

-- 
           Summary: explicit instantiation fails to emit symbols defined
                    later
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: critical
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sebor at roguewave dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: sparc-sun-solaris2.9
  GCC host triplet: sparc-sun-solaris2.9
GCC target triplet: sparc-sun-solaris2.9


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22263

Reply via email to