From patchwork Tue Mar 4 16:32:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 326389 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 6D11D2C00B3 for ; Wed, 5 Mar 2014 03:33:44 +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:cc:subject:content-type; q=dns; s=default; b=czKqzkgBSmSYyu+Xs0+fQFqKMxeu59sV0pucZbYxfEI vZd49abRb0oguAMXfmT2s05yVXEfEG1Lh8TLZ1oeNYo09jXb3o9qD3UaNOichbkE CkdhjoNquqRz/8SeoG4VowodzASb+hjCW5t0gTGzroO3RPkOxaSX3/d0djIqru8k = 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:cc:subject:content-type; s=default; bh=iQz6TW+u/UyV911x+VQ4Uu2pYpY=; b=WtiVhu/VLRFv+rHUh +jUFd+MViH1Z+/yTcjuBZ0DQHaiTfy7leOUtev5jgQHQ3q67BhhyBxwaG90VIX4l OMZlBGaiVmrUlZpzd2mbzuPqSure+g9N7Uc0gAxWs2Qkqd13pJwgm4spNsIPmR77 gD9LU9BzyIbzhunkih7VwCvJrY= Received: (qmail 20485 invoked by alias); 4 Mar 2014 16:33:35 -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 20470 invoked by uid 89); 4 Mar 2014 16:33:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, FSL_NEW_HELO_USER, RP_MATCHES_RCVD, SPF_PASS 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, 04 Mar 2014 16:33:34 +0000 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s24GXVO1008611 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 4 Mar 2014 16:33:32 GMT Received: from aserz7022.oracle.com (aserz7022.oracle.com [141.146.126.231]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s24GXTwv000444 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 4 Mar 2014 16:33:31 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s24GXTd6024860; Tue, 4 Mar 2014 16:33:29 GMT Received: from [192.168.1.4] (/79.17.190.245) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 04 Mar 2014 08:33:29 -0800 Message-ID: <53160037.502@oracle.com> Date: Tue, 04 Mar 2014 17:32:55 +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: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch/RFC] PR 60389 X-IsSubscribed: yes Hi, this regression is just an ICE on invalid, but I'm finding it somewhat tricky. Let's see if I can explain clearly enough what I figured out so far. The problem manifests itself when is_valid_constexpr_fn is called by explain_invalid_constexpr_fn with a TEMPLATE_DECL (the inherited template constructor) as the fun argument and FUNCTION_FIRST_USER_PARM cannot be used on it. This happens because explain_invalid_constexpr_fn (called from the second half of explain_non_literal_class) doesn't early return via: /* Only diagnose defaulted functions or instantiations. */ if (!DECL_DEFAULTED_FN (fun) && !is_instantiation_of_constexpr (fun)) return; because we internally represent inherited *template* constructors too as defaulted. Thus, the idea of handling those specially per the first draft I'm attaching. In fact, note that if we try to fix up is_valid_constexpr_fn (like in the second draft I'm attaching below), we get a final error message of the form 60389.C:13:12: note: ‘template B::B(T ...)’ is not usable as a constexpr function because: using A::A; ^ 60389.C:13:12: error: invalid type for parameter 1 of constexpr function ‘template B::B(T ...)’ which I find quite confusing, because that parameter is a TYPE_PACK_EXPANSION (for which the literal_type_p check in is_valid_constexpr_fn returns false) but in fact a B::B() is needed... Note, moreover, that if the user tries to "force" the compilation by simply declaring the A::A(T...) constructor explicitly constexpr, the compilation in fact succeeds (at least, with GCC ;) and that doesn't appear to make much sense vs the latter error message. So, what shall we do? Just patch 1 (with a comment explaining the early return)? Or Patch 2 and reconsider these issues later? Or something else? Thanks! Paolo. ///////////////////////// Index: cp/semantics.c =================================================================== --- cp/semantics.c (revision 208317) +++ cp/semantics.c (working copy) @@ -7430,7 +7430,7 @@ retrieve_constexpr_fundef (tree fun) static bool is_valid_constexpr_fn (tree fun, bool complain) { - tree parm = FUNCTION_FIRST_USER_PARM (fun); + tree parm = FUNCTION_FIRST_USER_PARM (STRIP_TEMPLATE (fun)); bool ret = true; for (; parm != NULL; parm = TREE_CHAIN (parm)) if (!literal_type_p (TREE_TYPE (parm))) 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 "invalid type" } +}; + +constexpr B b; // { dg-error "literal" } Index: cp/semantics.c =================================================================== --- cp/semantics.c (revision 208317) +++ cp/semantics.c (working copy) @@ -8002,7 +8002,9 @@ explain_invalid_constexpr_fn (tree fun) tree body; location_t save_loc; /* Only diagnose defaulted functions or instantiations. */ - if (!DECL_DEFAULTED_FN (fun) + if ((!DECL_DEFAULTED_FN (fun) + || (DECL_INHERITED_CTOR_BASE (fun) + && TREE_CODE (fun) == TEMPLATE_DECL)) && !is_instantiation_of_constexpr (fun)) return; if (diagnosed == NULL) 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; +}; + +constexpr B b; // { dg-error "literal" }