From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 52483 invoked by alias); 9 Sep 2019 21:00:03 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 52447 invoked by uid 89); 9 Sep 2019 21:00:03 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.3 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=HX-Languages-Length:1764 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 09 Sep 2019 21:00:01 +0000 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 08C4B83F3B for ; Mon, 9 Sep 2019 21:00:00 +0000 (UTC) Received: by mail-qt1-f198.google.com with SMTP id z20so17255793qtn.12 for ; Mon, 09 Sep 2019 14:00:00 -0700 (PDT) Received: from [192.168.1.116] (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id i4sm1751880qke.93.2019.09.09.13.59.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Sep 2019 13:59:58 -0700 (PDT) Subject: Re: C++ PATCH for c++/84374 - diagnose invalid uses of decltype(auto) To: Marek Polacek , GCC Patches References: <20190908164709.GF14737@redhat.com> From: Jason Merrill Message-ID: Date: Mon, 09 Sep 2019 21:00:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190908164709.GF14737@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2019-09/txt/msg00623.txt.bz2 On 9/8/19 11:47 AM, Marek Polacek wrote: > [dcl.type.auto.deduct]/5 "If the placeholder-type-specifier is of the > form type-constraintopt decltype(auto), T shall be the placeholder alone." > > So, only plain decltype(auto) is allowed. But we aren't diagnosing it in > function declarations, because do_auto_deduction is never called for those. > > Bootstrapped/regtested on x86_64-linux, ok for trunk? > > 2019-09-08 Marek Polacek > > PR c++/84374 - diagnose invalid uses of decltype(auto). > * decl.c (grokdeclarator): Diagnose wrong usage of decltype(auto) in > a function declaration. > > * g++.dg/cpp1y/auto-fn57.C: New test. > > diff --git gcc/cp/decl.c gcc/cp/decl.c > index 88e2c3beb2b..b1777730934 100644 > --- gcc/cp/decl.c > +++ gcc/cp/decl.c > @@ -11560,6 +11560,14 @@ grokdeclarator (const cp_declarator *declarator, > "cannot have deduced return type"); > virtualp = false; > } > + else if (is_auto (auto_node) > + && AUTO_IS_DECLTYPE (auto_node) > + && type != auto_node) > + { > + error_at (typespec_loc, "%qT as type rather than " > + "plain %", type); > + return error_mark_node; > + } > } > else if (!is_auto (type) && sfk != sfk_conversion) > { > @@ -11580,6 +11588,16 @@ grokdeclarator (const cp_declarator *declarator, > "invalid use of %"); > return error_mark_node; > } > + else if (tree a = type_uses_auto (late_return_type)) > + { > + if (AUTO_IS_DECLTYPE (a) && a != late_return_type) > + { > + error_at (typespec_loc, "%qT as type rather than " > + "plain %", > + late_return_type); > + return error_mark_node; > + } > + } Maybe check this in one place, after splice_late_return_type? Jason