Created attachment 8196 [details] testcase +++ This bug was initially created as a clone of Bug #11250 +++ This bug is based on bug #11250, which manually marked a base class template as hidden, resulting in an undefined reference when clang expected to find the instance of the template in another .so . This bug is the same, except that it uses the -fvisibility-inlines-hidden option. In the original testcase, one could argue that the problem is in the source files and not in clang. In lib2.cc, clang is apparently smart enough to see that it is not necessary to instantiate S1< int >, because it will be done in the same place where S2::~S2() is implemented (since S2's vtable is keyed to it, as the first virtual method in S2, and S2's vtable will require vtable of S1< int >, which will also instantiate S1< int >::f()). Therefore it could be argued that it is a developer error to mark S1 as non-exported (especially since it's done so only in lib1.cc and not in lib2.cc ). However, this new testcase compiles and links fine as it is, as long as -fvisibility-inlines-hidden is not used, otherwise the same problem occurs. Now again lib1.so contains a non-exported instance of S1< int >::f(), because of the switch. Presumably when compiling with -fvisibility-inlines-hidden clang should create a non-exported instance of S1< int >::f() even in lib2.so , otherwise -fvisibility-inlines-hidden is broken or next to useless.
This has apparently gotten fixed somewhen on the way to 3.2.