https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104834
Bug ID: 104834 Summary: visibility=hidden ignored for template instantiations for certain dependent types Product: gcc Version: 11.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: alex.wabik at gmail dot com Target Milestone: --- Created attachment 52579 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52579&action=edit Testcase Public visibility templates generate instances with public visiblity if a template parameter is an enum or class enum declared in the translation unit which uses -fvisibility=hidden, or even explicitly marked with hidden visibility attribute. This behaviour does not reproduce on clang, which will only instantiate public template if the enum has attribute visibility=default, otherwise the instantiated template has hidden visibility. The std::thread's constructor instantiates the std::thread::_State_impl type, which generates functions with default visibility if std::thread is constructed with a lambda defined in the hidden-visiblity class. This behaviour also does not reproduce on clang. I have also seen similar problems with std::function's template constructor, and with future base instantiations when using std::async, but I was not able to produce a minimal testcase; The testcase I attach demonstrates the problem for enums and std::thread only. The workaround for the enum problem and the lambda problem is to define these types in the anonymous namespace. Attaching the test code. Inspecting the compiled object reveals the following default visibility symbols, which I believe should be hidden: std::thread::_State_impl<std::thread::_Invoker<std::tuple<ThreadTest::ThreadTest()::{lambda()#1}> > >::~_State_impl() where the whole ThreadTest class has hidden visibility. aaa::Wrapper<ThisIsEnum>::get() where the ThisIsEnum type is an enum with hidden visibility.