From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 8EC5F3858D35 for ; Thu, 29 Jun 2023 17:43:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8EC5F3858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688060592; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P+fhbmq+cAfWhVi1IRfKIfQqNkD6+QYhFFu8NHtUbdA=; b=CKzOXVtA2BQZO4YPygLbijQ5k7qurTCKQmDOpQomPW6WOem9MME9Tld07Ah6sIIYDiNwlm RUkru2mwn1qopEiooTfnllyF/MrTQTTwqvB09yHPBstTPjmcsSwCc0SEw52GfUa0QclYd+ ZkXg/pZoNHkCsl02pjAspj7WLFgeQnU= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-56-18H2LPM4OlOz7h9DmYqxIQ-1; Thu, 29 Jun 2023 13:43:10 -0400 X-MC-Unique: 18H2LPM4OlOz7h9DmYqxIQ-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-76594ad37fcso107714985a.2 for ; Thu, 29 Jun 2023 10:43:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688060590; x=1690652590; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=P+fhbmq+cAfWhVi1IRfKIfQqNkD6+QYhFFu8NHtUbdA=; b=L4vxN168nSibjVELeHJAnNiQOa9Ihk+IfRUSknfdzHTtsshm5G890TYfj4QKsDLKY6 Em9DYmLXY9Tl9tZws6j/flDiK5xBQO1XhViW4zMyRnMwIikMLVP5+3c7siQBVQ0FkmUm fx5RIUl3iWqLzJF7zyRw1uS+Fh4UOtuFQwMu8rhknZY2+WFA5PflRFZgnpR2MCmnkrBF iG82dtDvDwzmhlAa/Ee88kJIc10jg9N0HdkMsehwZtq294H266xgNNly8gTQd3FCw27W UeQiQ37I0wBPXdUbl9I2jCKYeMvAesm//D4yzZsw3gjXBkIspIv3xqy2qyipfTO0PxU6 sQvQ== X-Gm-Message-State: AC+VfDx3LZ9VVQEHsbXbuRMNnZ2gcO+odNdkVTDC+KtFyBtz1LOUA2Xb uNcv1c6sa1gI2iY3QmnvkoovNacEH+MOogZSOWlM6EKBa/R1EXW2K3JIUvKXEIrvYPjmHsnfu+F d1pUUXz+Dh3BleWl1MQ== X-Received: by 2002:a05:620a:3f49:b0:767:34e8:ec2d with SMTP id ty9-20020a05620a3f4900b0076734e8ec2dmr27255qkn.20.1688060589908; Thu, 29 Jun 2023 10:43:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5esd+4t3N/KbgWyBzI/BzcxRki45UDOrDxGiV3bFZYZCFuj55BQRF7U7Gd0LD1X7ZSNSOZDg== X-Received: by 2002:a05:620a:3f49:b0:767:34e8:ec2d with SMTP id ty9-20020a05620a3f4900b0076734e8ec2dmr27247qkn.20.1688060589590; Thu, 29 Jun 2023 10:43:09 -0700 (PDT) Received: from [192.168.1.108] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id pc27-20020a05620a841b00b0075772c756e0sm1734718qkn.101.2023.06.29.10.43.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 29 Jun 2023 10:43:08 -0700 (PDT) Message-ID: <5d7ada85-ccaa-bc07-b625-20fdc5dc924c@redhat.com> Date: Thu, 29 Jun 2023 13:43:07 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH] c++: Fix ICE with parameter pack of decltype(auto) [PR103497] To: Nathaniel Shead , Patrick Palka Cc: gcc-patches@gcc.gnu.org References: <4c77b9a3-48cb-93c7-1489-38155c637926@idea> From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 6/24/23 09:24, Nathaniel Shead wrote: > On Fri, Jun 23, 2023 at 11:59:51AM -0400, Patrick Palka wrote: >> Hi, >> >> On Sat, 22 Apr 2023, Nathaniel Shead via Gcc-patches wrote: >> >>> Bootstrapped and tested on x86_64-pc-linux-gnu. >>> >>> -- 8< -- >>> >>> This patch raises an error early when the decltype(auto) specifier is >>> used as a parameter of a function. This prevents any issues with an >>> unexpected tree type later on when performing the call. >> >> Thanks very much for the patch! Some minor comments below. >> >>> >>> PR 103497 >> >> We should include the bug component name when referring to the PR in the >> commit message (i.e. PR c++/103497) so that upon pushing the patch the >> post-commit hook automatically adds a comment to the PR reffering to the >> commit. I could be wrong but AFAIK the hook only performs this when the >> component name is included. > > Thanks for the review! Fixed. > >>> >>> gcc/cp/ChangeLog: >>> >>> * parser.cc (cp_parser_simple_type_specifier): Add check for >>> decltype(auto) as function parameter. >>> >>> gcc/testsuite/ChangeLog: >>> >>> * g++.dg/pr103497.C: New test. >>> >>> Signed-off-by: Nathaniel Shead >>> --- >>> gcc/cp/parser.cc | 10 ++++++++++ >>> gcc/testsuite/g++.dg/pr103497.C | 7 +++++++ >>> 2 files changed, 17 insertions(+) >>> create mode 100644 gcc/testsuite/g++.dg/pr103497.C >>> >>> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc >>> index e5f032f2330..1415e07e152 100644 >>> --- a/gcc/cp/parser.cc >>> +++ b/gcc/cp/parser.cc >>> @@ -19884,6 +19884,16 @@ cp_parser_simple_type_specifier (cp_parser* parser, >>> && cp_lexer_peek_nth_token (parser->lexer, 2)->type != CPP_SCOPE) >>> { >>> type = saved_checks_value (token->u.tree_check_value); >>> + /* Within a function parameter declaration, decltype(auto) is always an >>> + error. */ >>> + if (parser->auto_is_implicit_function_template_parm_p >>> + && TREE_CODE (type) == TEMPLATE_TYPE_PARM >> >> We could check is_auto (type) here instead, to avoid any confusion with >> checking AUTO_IS_DECLTYPE for a non-auto TEMPLATE_TYPE_PARM. >> >>> + && AUTO_IS_DECLTYPE (type)) >>> + { >>> + error_at (token->location, >>> + "cannot declare a parameter with %"); >>> + type = error_mark_node; >>> + } >>> if (decl_specs) >>> { >>> cp_parser_set_decl_spec_type (decl_specs, type, >>> diff --git a/gcc/testsuite/g++.dg/pr103497.C b/gcc/testsuite/g++.dg/pr103497.C >>> new file mode 100644 >>> index 00000000000..bcd421c2907 >>> --- /dev/null >>> +++ b/gcc/testsuite/g++.dg/pr103497.C >>> @@ -0,0 +1,7 @@ >>> +// { dg-do compile { target c++14 } } >>> + >>> +void foo(decltype(auto)... args); // { dg-error "parameter with .decltype.auto..|no parameter packs" } >> >> I noticed for >> >> void foo(decltype(auto) arg); >> >> we already issue an identical error from grokdeclarator. Perhaps we could >> instead extend the error handling there to detect decltype(auto)... as well, >> rather than adding new error handling in cp_parser_simple_type_specifier? > > Ah thanks, I didn't notice this; this simplifies the change a fair bit. > How about this patch instead? > > Regtested on x86_64-pc-linux-gnu. > > -- 8< -- > > This patch ensures that checks for usages of 'auto' in function > parameters also consider parameter packs, since 'type_uses_auto' does > not seem to consider this case. > > PR c++/103497 > > gcc/cp/ChangeLog: > > * decl.cc (grokdeclarator): Check for decltype(auto) in > parameter pack. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp1y/decltype-auto-103497.C: New test. > > Signed-off-by: Nathaniel Shead > --- > gcc/cp/decl.cc | 3 +++ > gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C | 8 ++++++++ > 2 files changed, 11 insertions(+) > create mode 100644 gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C > > diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc > index 60f107d50c4..aaf691fce68 100644 > --- a/gcc/cp/decl.cc > +++ b/gcc/cp/decl.cc > @@ -14044,6 +14044,9 @@ grokdeclarator (const cp_declarator *declarator, > error ("cannot use %<::%> in parameter declaration"); > > tree auto_node = type_uses_auto (type); > + if (!auto_node && parameter_pack_p) > + auto_node = type_uses_auto (PACK_EXPANSION_PATTERN (type)); Hmm, I wonder if type_uses_auto should look into PACK_EXPANSION_PATTERN itself. Would that break anything? > + > if (auto_node && !(cxx_dialect >= cxx17 && template_parm_flag)) > { > if (cxx_dialect >= cxx14) > diff --git a/gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C b/gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C > new file mode 100644 > index 00000000000..cedd661710c > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C > @@ -0,0 +1,8 @@ > +// PR c++/103497 > +// { dg-do compile { target c++14 } } > + > +void foo(decltype(auto)... args); // { dg-error "cannot declare a parameter with .decltype.auto.." } > + > +int main() { > + foo(); > +}