https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106023

            Bug ID: 106023
           Summary: Would like to control the ELF visibility of template
                    explicit instantiations
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: thiago at kde dot org
  Target Milestone: ---

Given a template like:

template <typename T> struct __attribute__((visibility("hidden"))) S
{
    static constexpr int n = 0;
};

I would like to mark an explicit instantiation (not a specialisation!) with a
different visibility:

template struct __attribute__((visibility("default"))) S<int>;
template __attribute__((visibility("default"))) const int S<unsigned>::n;

Either solution would help me, but the first would be preferable. Both would be
best.

Clang does support both forms properly. Visual Studio supports the former only.
See https://gcc.godbolt.org/z/T7sdzTnbG and note how GCC adds ".hidden" to the
two "::n" symbols and Clang doesn't, while Clang properly refers to those
symbols using @GOTPCREL and GCC doesn't. The MVSC example uses dllimport only
to highlight the difference; it wouldn't be written like this in real code.

Please ensure "protected" visibility also works. See
https://gcc.godbolt.org/z/o3W4x5YsG

Reply via email to