Bug 106023 - Would like to control the ELF visibility of template explicit instantiations
Summary: Would like to control the ELF visibility of template explicit instantiations
Status: RESOLVED DUPLICATE of bug 77306
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 13.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: visibility
Depends on: 77306
Blocks:
  Show dependency treegraph
 
Reported: 2022-06-18 15:16 UTC by Thiago Macieira
Modified: 2022-06-19 16:04 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thiago Macieira 2022-06-18 15:16:16 UTC
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
Comment 1 Andrew Pinski 2022-06-18 20:06:23 UTC
I think this is a dup of bug 77306.
Comment 2 Thiago Macieira 2022-06-19 16:04:05 UTC
Ah, so it is. Thanks for putting up with my being lazy.

*** This bug has been marked as a duplicate of bug 77306 ***