[PATCH] D35388: [libc++] Give extern templates default visibility on gcc

Eric Fiselier via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 2 15:50:19 PDT 2017


EricWF requested changes to this revision.
EricWF added a comment.
This revision now requires changes to proceed.

Hmm. So the documentation is wrong, but not "fully wrong". If you simply try applying this patch and compiling with GCC you'll still encounter a bunch of instances of `warning: type attributes ignored after type is already defined [-Wattributes]`.

The warning occurs when the class template specialization named in the extern template declaration has already been defined (possibly by an implicit instantiation). Ex. https://godbolt.org/g/DLgxhe

  #define VIS(Str) __attribute__((__visibility__(Str)))
  template <class T> class VIS("hidden") T { void foo(); };
  T<int> t; // cause definition of T<int>. 
  template <> void T<float>::foo() {} // causes definition?
  extern template class VIS("default") T<void>; // OK not defined yet.
  extern template class VIS("default") T<int>: // Not OK, T<int> is already defined 

This case occurs multiple times in `<locale>` where the extern template declaration occurs after we declare an explicit specialization of a member function. It appears we need to do more to fix this than simply enable the visibility macro with GCC.
Likely either by ensuring the extern template decl occurs before anything that causes an implicit instantiation (but I'm not sure if that's allow, maybe member specializations have to occur first?), or by adding yet another macro to specially handle the `<locale>` case et al. with GCC.


https://reviews.llvm.org/D35388





More information about the cfe-commits mailing list