From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A427F385843A; Tue, 8 Mar 2022 08:07:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A427F385843A From: "alex.wabik at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/104834] New: visibility=hidden ignored for template instantiations for certain dependent types Date: Tue, 08 Mar 2022 08:07:45 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 11.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: alex.wabik at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Mar 2022 08:07:45 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104834 Bug ID: 104834 Summary: visibility=3Dhidden 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=3D52579&action=3Dedit 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=3Dhidden, or even explicitly marked with hidden visibility attribute. This behaviour does not reproduce on clang, which will only instantiate pub= lic template if the enum has attribute visibility=3Ddefault, otherwise the instantiated template has hidden visibility. The std::thread's constructor instantiates the std::thread::_State_impl typ= e, which generates functions with default visibility if std::thread is constru= cted with a lambda defined in the hidden-visiblity class. This behaviour also do= es 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 ab= le to produce a minimal testcase; The testcase I attach demonstrates the probl= em for enums and std::thread only. The workaround for the enum problem and the lambda problem is to define the= se types in the anonymous namespace. Attaching the test code. Inspecting the compiled object reveals the followi= ng default visibility symbols, which I believe should be hidden: std::thread::_State_impl > >::~_State_impl() where the whole ThreadTest class has hidden visibility. aaa::Wrapper::get() where the ThisIsEnum type is an enum with hidden visibility.=