Clang ignores visibility attribute of a template method of a template class · Issue #103477 · llvm/llvm-project (original) (raw)

For the following source clang generates the symbol _ZN1tIcE3barILi1EEEvv with the DEFAULT visibility:

template struct t { template static attribute((visibility("hidden"))) void bar() {} };

void test() { t::bar<1>(); }

> clang -c test.cpp -target x86_64 -o test.o
> readelf -sW test.o
...
     5: 0000000000000000     6 FUNC    WEAK   DEFAULT     5 _ZN1tIcE3barILi1EEEvv

gcc for the same case generates a HIDDEN symbol: https://godbolt.org/z/9z7soKfoa

The problem may be similar to #31462, but there are no explicit instantiations with different visibility attributes here. Applying D153835 or D154774 fixes this issue, but these revisions seem to be abandoned. #72092 does not resolve it.