From patchwork Thu Mar 21 03:09:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 229542 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 736962C00C0 for ; Thu, 21 Mar 2013 14:10:04 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; q=dns; s=default; b=fIpnNIG1zd7NQrrYT x1W0Re6fOQ7sXTC6hMGyVJe84tW+g9cb5VTKRbR+HC7DzgXG1deThpu4boCsWeyF /wS8Vb6vIzbpb374e11pCVp2/s58MFqU2Wi1MhP6qmR/S05u8aEnOOhbuGDlh2On gxW11+mNT4eo+wqA67UqIaQ9OQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; s=default; bh=xiRLM+6CSh87/GZdkC/D2GN 6VXM=; b=nalKJzFAm9pnpjGMKE0d4YxoYHJnBmx328+gWh6tNhsYIoSz4csSQxU KnkkCtCbSAqXHMB0a6iw91Mju6DLEoS4EaEBmlCBbl9xusDFmJRY5dQF/NBeZlH5 PAVS5a5WKnmiE6nsy2mrnPf13YJ9uJO82RzYOkoQ4ICzhsZDAWTc= Received: (qmail 24006 invoked by alias); 21 Mar 2013 03:09:58 -0000 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 Received: (qmail 23970 invoked by uid 89); 21 Mar 2013 03:09:46 -0000 X-Spam-SWARE-Status: No, score=-8.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 21 Mar 2013 03:09:43 +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 r2L39g93019252 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 20 Mar 2013 23:09:42 -0400 Received: from [10.3.113.56] (ovpn-113-56.phx2.redhat.com [10.3.113.56]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r2L39f6K013412 for ; Wed, 20 Mar 2013 23:09:42 -0400 Message-ID: <514A79F5.4060905@redhat.com> Date: Wed, 20 Mar 2013 23:09:41 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:21.0) Gecko/20100101 Thunderbird/21.0a2 MIME-Version: 1.0 To: gcc-patches List Subject: Re: C++ PATCH for c++/17232 (abstract class, array and sfinae) References: <5144CA1F.8060605@redhat.com> <5146289B.4070802@redhat.com> In-Reply-To: <5146289B.4070802@redhat.com> On 03/17/2013 04:33 PM, Jason Merrill wrote: > On 03/16/2013 03:38 PM, Jason Merrill wrote: >> In SFINAE context, we need to instantiate a class so that we can tell >> whether or not is abstract. Doing this in non-SFINAE context caused >> problems, so I've made it conditional. > > But it still causes problems, such as PR 56642. So I've reverted the > complete_type change for now. This patch fixes 56642 properly; forcing the type to be complete can cause a function decl instantiation to cause its own instantiation again, so we need to deal with that. Tested x86_64-pc-linux-gnu, applying to trunk. commit f6585cdd1828608c4052ac06b80c89ce86da120f Author: Jason Merrill Date: Mon Mar 18 00:25:34 2013 -0400 PR c++/17232 PR c++/56642 * pt.c (tsubst_decl): Check return value of register_specialization. * typeck2.c (abstract_virtuals_error_sfinae): Re-apply complete_type change. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 4274479..531d860 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -10285,7 +10285,13 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain) DECL_TEMPLATE_INFO (r) = build_template_info (gen_tmpl, argvec); SET_DECL_IMPLICIT_INSTANTIATION (r); - register_specialization (r, gen_tmpl, argvec, false, hash); + + tree new_r + = register_specialization (r, gen_tmpl, argvec, false, hash); + if (new_r != r) + /* We instantiated this while substituting into + the type earlier (template/friend54.C). */ + RETURN (new_r); /* We're not supposed to instantiate default arguments until they are called, for a template. But, for a diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 24b5593..3bac67c 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -265,6 +265,10 @@ abstract_virtuals_error_sfinae (tree decl, tree type, abstract_class_use use, return 0; type = TYPE_MAIN_VARIANT (type); + /* In SFINAE context, force instantiation. */ + if (!(complain & tf_error)) + complete_type (type); + /* If the type is incomplete, we register it within a hash table, so that we can check again once it is completed. This makes sense only for objects for which we have a declaration or at least a diff --git a/gcc/testsuite/g++.dg/template/abstract-dr337.C b/gcc/testsuite/g++.dg/template/abstract-dr337.C index 4f66c1c..6905262 100644 --- a/gcc/testsuite/g++.dg/template/abstract-dr337.C +++ b/gcc/testsuite/g++.dg/template/abstract-dr337.C @@ -6,8 +6,8 @@ class A { }; template -void g(T (*a)[1]) {} // { dg-error "abstract" "" { xfail *-*-* } } +void g(T (*a)[1]) {} // { dg-error "abstract" "" } int main() { - g >(0); // { dg-error "no matching function" "" { xfail *-*-* } } + g >(0); // { dg-error "no matching function" } } diff --git a/gcc/testsuite/g++.dg/template/friend54.C b/gcc/testsuite/g++.dg/template/friend54.C new file mode 100644 index 0000000..ead7a72 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/friend54.C @@ -0,0 +1,18 @@ +// PR c++/56642 + +template struct A; + +template +A f(T*) { return A(); } + +template +struct A +{ + friend A f(T*); +}; + +int main() +{ + int *p = 0; + f(p); +}