From patchwork Tue Mar 11 16:07:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 329151 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 2204B2C00C2 for ; Wed, 12 Mar 2014 03:08:26 +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=ExcwLhKkEt8wa2b9+ i6c7CaDlago365q31Av9fpafpNXc54deqrYQ2PeXz80VoeScxw4NQnSLWUd5wa7G 7hpvcpPhrlTrBNc4neqUsijAzEfd7VLngmsFpGXQY3y95U2pTIfVYuMjXmrSAGiB vw1B7IO3Oz/8AsudOxmOKV0+ts= 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=UGAayZJZJgfiozsj4s0SRSS KB+I=; b=yEfULgZ0oMYiRAzEWKqarsUMpv2NX+jzeym54PbQRVBoto/eYXBxV+t qcLB7Bx7z6HBw7EQUmkVf8SkxgVJkY1qeO6M//2UUZCZErc2HFzOlswW9QSqh7J9 09Wmvml0WYoV/zYjY+o1CaDmGy/Pt2XmkouCKLj7L02O4aCgM0lY= Received: (qmail 17420 invoked by alias); 11 Mar 2014 16:08:12 -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 17312 invoked by uid 89); 11 Mar 2014 16:08:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, FSL_NEW_HELO_USER, SPF_PASS, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: userp1040.oracle.com Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Tue, 11 Mar 2014 16:08:05 +0000 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s2BG82An020989 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 11 Mar 2014 16:08:03 GMT Received: from aserz7022.oracle.com (aserz7022.oracle.com [141.146.126.231]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s2BG81rj000913 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 11 Mar 2014 16:08:02 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s2BG81eW000880; Tue, 11 Mar 2014 16:08:01 GMT Received: from [192.168.1.4] (/79.36.196.146) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 11 Mar 2014 09:08:01 -0700 Message-ID: <531F34B5.3010001@oracle.com> Date: Tue, 11 Mar 2014 17:07:17 +0100 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: Jason Merrill , "gcc-patches@gcc.gnu.org" Subject: Re: [C++ Patch/RFC] PR 60389 References: <53160037.502@oracle.com> <531A03B7.4070907@redhat.com> <531EFBAE.6070009@oracle.com> <531F0B5F.4060705@redhat.com> In-Reply-To: <531F0B5F.4060705@redhat.com> X-IsSubscribed: yes Hi, On 03/11/2014 02:10 PM, Jason Merrill wrote: > On 03/11/2014 08:03 AM, Paolo Carlini wrote: >> + if (DECL_INHERITED_CTOR_BASE (fun) >> + && TREE_CODE (fun) == TEMPLATE_DECL) >> + { >> + ret = false; >> + if (complain) >> + error ("inherited constructors inherit % from " >> + "the designated base"); >> + } > > To correct my wording, the B constructor is the inheriting > constructor, the inherited constructor is in A. > > Let's look up the inherited constructor here and print it to be > helpful. Probably the easiest way to find it will be to add a new > entry point to locate_fn_flags so we call it with > > (DECL_INHERITED_CTOR_BASE (fun), DECL_NAME (fun), > FUNCTION_FIRST_USER_PARMTYPE (fun), LOOKUP_NORMAL|LOOKUP_SPECULATIVE, > complain) > > Then we can say "inherited constructor %qD is not constexpr". I see. The below tries to implement the above (note: complete_ctor_identifier; push_deferring_access_checks, otherwise for a similar testcase inheriting from class A we produce duplicate diagnostic about accessibility). Tested x86_64-linux. Thanks, Paolo. PS: I think we should also be more careful about inform vs error, but probably not at this Stage... Index: cp/cp-tree.h =================================================================== --- cp/cp-tree.h (revision 208474) +++ cp/cp-tree.h (working copy) @@ -5476,6 +5476,7 @@ extern tree get_copy_ctor (tree, tsubst_flags_t) extern tree get_copy_assign (tree); extern tree get_default_ctor (tree); extern tree get_dtor (tree, tsubst_flags_t); +extern tree get_inherited_ctor (tree); extern tree locate_ctor (tree); extern tree implicitly_declare_fn (special_function_kind, tree, bool, tree, tree); Index: cp/method.c =================================================================== --- cp/method.c (revision 208474) +++ cp/method.c (working copy) @@ -971,6 +971,25 @@ get_copy_assign (tree type) return fn; } +/* Locate the inherited constructor of constructor CTOR. */ + +tree +get_inherited_ctor (tree ctor) +{ + gcc_assert (DECL_INHERITED_CTOR_BASE (ctor)); + + push_deferring_access_checks (dk_no_check); + tree fn = locate_fn_flags (DECL_INHERITED_CTOR_BASE (ctor), + complete_ctor_identifier, + FUNCTION_FIRST_USER_PARMTYPE (ctor), + LOOKUP_NORMAL|LOOKUP_SPECULATIVE, + tf_none); + pop_deferring_access_checks (); + if (fn == error_mark_node) + return NULL_TREE; + return fn; +} + /* Subroutine of synthesized_method_walk. Update SPEC_P, TRIVIAL_P and DELETED_P or give an error message MSG with argument ARG. */ Index: cp/semantics.c =================================================================== --- cp/semantics.c (revision 208474) +++ cp/semantics.c (working copy) @@ -7438,19 +7438,31 @@ retrieve_constexpr_fundef (tree fun) static bool is_valid_constexpr_fn (tree fun, bool complain) { - tree parm = FUNCTION_FIRST_USER_PARM (fun); bool ret = true; - for (; parm != NULL; parm = TREE_CHAIN (parm)) - if (!literal_type_p (TREE_TYPE (parm))) - { - ret = false; - if (complain) + + if (DECL_INHERITED_CTOR_BASE (fun) + && TREE_CODE (fun) == TEMPLATE_DECL) + { + ret = false; + if (complain) + error ("inherited constructor %qD is not constexpr", + get_inherited_ctor (fun)); + } + else + { + for (tree parm = FUNCTION_FIRST_USER_PARM (fun); + parm != NULL_TREE; parm = TREE_CHAIN (parm)) + if (!literal_type_p (TREE_TYPE (parm))) { - error ("invalid type for parameter %d of constexpr " - "function %q+#D", DECL_PARM_INDEX (parm), fun); - explain_non_literal_class (TREE_TYPE (parm)); + ret = false; + if (complain) + { + error ("invalid type for parameter %d of constexpr " + "function %q+#D", DECL_PARM_INDEX (parm), fun); + explain_non_literal_class (TREE_TYPE (parm)); + } } - } + } if (!DECL_CONSTRUCTOR_P (fun)) { Index: testsuite/g++.dg/cpp0x/inh-ctor19.C =================================================================== --- testsuite/g++.dg/cpp0x/inh-ctor19.C (revision 0) +++ testsuite/g++.dg/cpp0x/inh-ctor19.C (working copy) @@ -0,0 +1,14 @@ +// PR c++/60389 +// { dg-do compile { target c++11 } } + +struct A +{ + template A(T...) {} +}; + +struct B : A +{ + using A::A; // { dg-error "inherited" } +}; + +constexpr B b; // { dg-error "literal" }