From patchwork Tue Mar 8 17:23:35 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 86025 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 D027AB6F12 for ; Wed, 9 Mar 2011 04:23:46 +1100 (EST) Received: (qmail 13928 invoked by alias); 8 Mar 2011 17:23:43 -0000 Received: (qmail 13916 invoked by uid 22791); 8 Mar 2011 17:23:42 -0000 X-SWARE-Spam-Status: No, hits=-6.2 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; Tue, 08 Mar 2011 17:23:38 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p28HNaNl014552 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 8 Mar 2011 12:23:36 -0500 Received: from [127.0.0.1] (ovpn-113-31.phx2.redhat.com [10.3.113.31]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p28HNZxC011088 for ; Tue, 8 Mar 2011 12:23:36 -0500 Message-ID: <4D766617.10105@redhat.com> Date: Tue, 08 Mar 2011 12:23:35 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Lightning/1.0b2 Thunderbird/3.1.7 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/45651 (ICE with explicit template instantiation and unnamed namespace) 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 The linkage handling of an explicit instantiation of an undefined template in instantiate_decl was interacting badly with the linkage magic for anonymous namespaces. Fixed thus. Tested x86_64-pc-linux-gnu, applied to trunk. commit bb206a6c192120614fa6e3c78a2ba2add6f5c3f2 Author: Jason Merrill Date: Tue Mar 8 10:54:00 2011 -0500 PR c++/45651 * pt.c (instantiate_decl): Don't clear DECL_INTERFACE_KNOWN on !TREE_PUBLIC decls. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 076224c..48f9382 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -17224,8 +17224,13 @@ instantiate_decl (tree d, int defer_ok, if (!pattern_defined && expl_inst_class_mem_p && DECL_EXPLICIT_INSTANTIATION (d)) { - DECL_NOT_REALLY_EXTERN (d) = 0; - DECL_INTERFACE_KNOWN (d) = 0; + /* Leave linkage flags alone on instantiations with anonymous + visibility. */ + if (TREE_PUBLIC (d)) + { + DECL_NOT_REALLY_EXTERN (d) = 0; + DECL_INTERFACE_KNOWN (d) = 0; + } SET_DECL_IMPLICIT_INSTANTIATION (d); } diff --git a/gcc/testsuite/g++.dg/template/anon5.C b/gcc/testsuite/g++.dg/template/anon5.C new file mode 100644 index 0000000..34599c0 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/anon5.C @@ -0,0 +1,6 @@ +// PR c++/45651 + +namespace { template struct A {}; } +template struct B { void f(A); }; +template struct B<1>; +template void B::f(A) {}