From patchwork Fri May 20 11:17:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 624455 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 3rB55J6tw6z9t43 for ; Fri, 20 May 2016 21:17:56 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=H6H3Uj2q; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=TQEY4jb/KUFdR/b0t NLUkjfct9jQ2p7r4DBoQN+14iIesKLyXLu+pofvnIRAHbN8FWcRoZ49t3ADdE8Gt ShO9EHIbLDDZMNmm2pEDP+4Ko8G4EciQBSBHDCHoQV58PModAbpCBUSGLh3fjRWq u9gzdHm7a0eTn1BwPSIscRAdfw= 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 :subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=hsgbWp3bMtLK80MoSjDGqY2 zjIU=; b=H6H3Uj2qGjPFX4w9wOQ+AVoUWWFWUC+LBvqaEs5agmmAb9xySNMaoSm 3XiBNXJZ9m6PrH2SyQdHzydwwIyw1aGb31G89nyev+BuA5syD9Yu6XbAXTvK1khZ O0kkh1ISX37yhzMBz4FQQbBVYedJOEDYni8YYYKK+/3FCQsmQFZw= Received: (qmail 117384 invoked by alias); 20 May 2016 11:17:49 -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 117367 invoked by uid 89); 20 May 2016 11:17:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=wrt X-HELO: aserp1040.oracle.com Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 20 May 2016 11:17:46 +0000 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u4KBHhwM023706 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 20 May 2016 11:17:44 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u4KBHhAv006433 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 20 May 2016 11:17:43 GMT Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u4KBHcUb025944; Fri, 20 May 2016 11:17:43 GMT Received: from [192.168.1.4] (/82.59.175.53) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 20 May 2016 04:17:37 -0700 Subject: Re: [C++ Patch/RFC] PR 70572 ("[4.9/5/6/7 Regression] ICE on code with decltype (auto) on x86_64-linux-gnu in digest_init_r") To: Jason Merrill , "gcc-patches@gcc.gnu.org" References: <573C8ED1.40608@oracle.com> <280efae8-86ed-aaef-67e9-26cbc499b632@redhat.com> <573CF71D.3080503@oracle.com> From: Paolo Carlini Message-ID: <573EF24F.2000205@oracle.com> Date: Fri, 20 May 2016 13:17:35 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 MIME-Version: 1.0 In-Reply-To: X-IsSubscribed: yes Hi, On 19/05/2016 15:58, Jason Merrill wrote: > On 05/18/2016 07:13 PM, Paolo Carlini wrote: >> + error ("cannot declare variable %q+D with function type", decl); > > I think the error message would be more helpful if it mentioned > decltype(auto), maybe > > "initializer for % has function type, did you > forget the %<()%>?", DECL_NAME (decl) > > (or some other way to print the variable type as declared rather than > as deduced). The below passes testing. There are a few minor changes wrt your suggestions (I think we want & as hint; spacing consistent with typeck2.c; DECL_NAME doesn't seem necessary). I wondered if we want to tighten the condition consistently with the wording of the error message, thus patchlet *2 below, which of course also passes testing. Thanks, Paolo. /////////////////////// Index: cp/decl.c =================================================================== --- cp/decl.c (revision 236496) +++ cp/decl.c (working copy) @@ -6609,6 +6609,14 @@ cp_finish_decl (tree decl, tree init, bool init_co adc_variable_type); if (type == error_mark_node) return; + if (TREE_CODE (type) == FUNCTION_TYPE + && TREE_CODE (TREE_TYPE (d_init)) == FUNCTION_TYPE) + { + error ("initializer for % has function type " + "(did you forget the %<&%> ?)", decl); + TREE_TYPE (decl) = error_mark_node; + return; + } cp_apply_type_quals_to_decl (cp_type_quals (type), decl); } Index: testsuite/g++.dg/cpp1y/auto-fn31.C =================================================================== --- testsuite/g++.dg/cpp1y/auto-fn31.C (revision 0) +++ testsuite/g++.dg/cpp1y/auto-fn31.C (working copy) @@ -0,0 +1,7 @@ +// PR c++/70572 +// { dg-do compile { target c++14 } } + +void foo () +{ + decltype (auto) a = foo; // { dg-error "initializer" } +} Index: cp/decl.c =================================================================== --- cp/decl.c (revision 236496) +++ cp/decl.c (working copy) @@ -6609,6 +6609,13 @@ cp_finish_decl (tree decl, tree init, bool init_co adc_variable_type); if (type == error_mark_node) return; + if (TREE_CODE (type) == FUNCTION_TYPE) + { + error ("initializer for % has function type " + "(did you forget the %<&%> ?)", decl); + TREE_TYPE (decl) = error_mark_node; + return; + } cp_apply_type_quals_to_decl (cp_type_quals (type), decl); } Index: testsuite/g++.dg/cpp1y/auto-fn31.C =================================================================== --- testsuite/g++.dg/cpp1y/auto-fn31.C (revision 0) +++ testsuite/g++.dg/cpp1y/auto-fn31.C (working copy) @@ -0,0 +1,7 @@ +// PR c++/70572 +// { dg-do compile { target c++14 } } + +void foo () +{ + decltype (auto) a = foo; // { dg-error "initializer" } +}