title: Should visibility/export macros be applied to templates when writing a library?
body: <p>When building a C++ DLL or shared library <code>__attribute__((__visibility__("default")))</code> or <code>__declspec(dllexport)</code> is frequently attached via a macro to those concrete symbols (classes, functions, etc) that should be made available to consumers of the library, with the other symbols defaulted to have internal visibility.</p>
  
  <p>But what should be done about inline functions or templates?</p>
  
  <p>It seems that for inline functions the answer should be that no annotation is needed. If the consumer of the header defining the inline function actually inlines the function, then there is no symbol needed. If the consumer emits an out-of-line definition instead, that is still OK. The only wrinkle is that the definitions of the inline function inside the DLL and inside each consuming library may differ. So, you could get some trouble if you were expecting to reliably compare the addresses of inline functions, but that seems pretty sketchy anyway.</p>
  
  <p>Given that argument, it would seem that since templates bodies are typically entirely visible to the consuming TU, that the same logic would apply.</p>
  
  <p>I feel like there are probably some subtleties here with respect to 'extern template' and explicit instantiations.</p>
  
  <p>Does anyone have concrete guidance on how visibility attributes should adhere to inline functions and templates?</p>