public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104834] New: visibility=hidden ignored for template instantiations for certain dependent types
@ 2022-03-08  8:07 alex.wabik at gmail dot com
  2022-03-08  8:12 ` [Bug c++/104834] " alex.wabik at gmail dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: alex.wabik at gmail dot com @ 2022-03-08  8:07 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-03-08  8:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-08  8:07 [Bug c++/104834] New: visibility=hidden ignored for template instantiations for certain dependent types alex.wabik at gmail dot com
2022-03-08  8:12 ` [Bug c++/104834] " alex.wabik at gmail dot com
2022-03-08  8:26 ` pinskia at gcc dot gnu.org
2022-03-08  8:27 ` rguenth at gcc dot gnu.org
2022-03-08  8:27 ` rguenth at gcc dot gnu.org
2022-03-08  8:28 ` pinskia at gcc dot gnu.org
2022-03-08  8:35 ` alex.wabik at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).