From patchwork Mon Jan 23 20:19:56 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 137465 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 663881007D3 for ; Tue, 24 Jan 2012 07:20:28 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1327954828; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=ABEstjA jaRqNmxCDbaSd51qcjSA=; b=oehHLcDJF+UR9B7XW70NyDaEliCinVRQrfdvEQK BFBvrvwJL3EzoBRUhnA6QaO1dqTjg8D8nI/6IBXwhELnVw+wIH6sv4Awa3QYynMf Ijuh/fMEa7iPK1nbPpvPYub33nB8cMxRGw6bFBHYQdB2o9YMwuGtSglT2KduYnrf acj8= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=LOPtvRmtKdA2/diWCyneMxw9vNCKVCkXilUNwsItv8UTtbnq5T+TnQbipGKQv8 UQuNXr1bf+0sD980kuqxlzhzJR9H4cXOk9v96DcX9MUWa0qIm3eW+o93D/hn2TVA d6jbsyfGgwIMVcJ2AivV4eP2rpH6Eskrne14PEvrnxQeQ=; Received: (qmail 8133 invoked by alias); 23 Jan 2012 20:20:21 -0000 Received: (qmail 8112 invoked by uid 22791); 23 Jan 2012 20:20:17 -0000 X-SWARE-Spam-Status: No, hits=-6.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 23 Jan 2012 20:19:59 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q0NKJwI9001299 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 23 Jan 2012 15:19:58 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q0NKJwJv023408 for ; Mon, 23 Jan 2012 15:19:58 -0500 Received: from [0.0.0.0] (ovpn-113-137.phx2.redhat.com [10.3.113.137]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id q0NKJu2m005390 for ; Mon, 23 Jan 2012 15:19:57 -0500 Message-ID: <4F1DC0EC.6040609@redhat.com> Date: Mon, 23 Jan 2012 15:19:56 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:9.0) Gecko/20111222 Thunderbird/9.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/51930 (instantiation hidden despite visibility attribute) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org DECL_VISIBILITY_SPECIFIED is set if the decl occurs after a #pragma visibility or within a namespace with explicit visibility. In these cases, we want the visibility of template arguments to be able to further restrict the visibility of template specializations. But if the specialization itself has explicitly specified visibility, we should respect that. This patch will also mean that an attribute on the template will override argument visibility, which I could go either way on. But if this is a problem for users they can use a pragma instead. Tested x86_64-pc-linux-gnu, applying to trunk. commit e3f4b4e6d7c54ec96c77aa3e36fe9d38b7922391 Author: Jason Merrill Date: Mon Jan 23 14:31:23 2012 -0500 PR c++/51930 * decl2.c (determine_visibility): Check for visibility attribute on template specialization. diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index f51790c..bdc962a 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -2177,8 +2177,14 @@ determine_visibility (tree decl) ? TYPE_TEMPLATE_INFO (TREE_TYPE (decl)) : DECL_TEMPLATE_INFO (decl)); tree args = TI_ARGS (tinfo); + tree attribs = (TREE_CODE (decl) == TYPE_DECL + ? TYPE_ATTRIBUTES (TREE_TYPE (decl)) + : DECL_ATTRIBUTES (decl)); - if (args != error_mark_node) + if (args != error_mark_node + /* Template argument visibility outweighs #pragma or namespace + visibility, but not an explicit attribute. */ + && !lookup_attribute ("visibility", attribs)) { int depth = TMPL_ARGS_DEPTH (args); tree pattern = DECL_TEMPLATE_RESULT (TI_TEMPLATE (tinfo)); diff --git a/gcc/testsuite/g++.dg/ext/visibility/template10.C b/gcc/testsuite/g++.dg/ext/visibility/template10.C new file mode 100644 index 0000000..01108aa --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/visibility/template10.C @@ -0,0 +1,16 @@ +// PR c++/51930 +// { dg-require-visibility } +// { dg-options -fvisibility=hidden } +// { dg-final { scan-not-hidden "_Z8testfuncI3fooEvv" } } + +struct foo { }; + +template +__attribute__ ((visibility("default"))) +void testfunc(); + +template void testfunc() { } + +template +__attribute__ ((visibility("default"))) +void testfunc();