From patchwork Fri Jun 30 07:05:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 114594 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp10157577vqr; Fri, 30 Jun 2023 00:06:20 -0700 (PDT) X-Google-Smtp-Source: APBJJlGctvdUV0hgw775qUwFOn9WOobETHqTeAP/m0ZptWjVLfgrPC2IRIYjx9igGq8opLyF+KuW X-Received: by 2002:a17:907:9844:b0:974:5e8b:fc28 with SMTP id jj4-20020a170907984400b009745e8bfc28mr1928787ejc.9.1688108780441; Fri, 30 Jun 2023 00:06:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688108780; cv=none; d=google.com; s=arc-20160816; b=mFs60Kpm0ADFUeIpKVYZQvaELMtouaNTiAIaG1OZgsP7+fr5WM57n1nxFsglv4topr YuItWPSEUbuZfDeAmqJbkMX8UMHOrPd64g8BSYPOPBzqa8arZuMQq3mkWcB0Xp/9PYfx EPUiO894atTAgv8cfRGPORBX5NUGO2fFmZSdI8qtQORbfHIDxROo+YFq7vcbYdccgtSC 1YqBSAFA75oUdGHODag/2BbGERz+uz6O3RC//ylT0jk7iBiObS009aoUwKmdVqTIWoWL KbibEeLLDvl+RClje3PNk/UqWV1JKvNdtddFX+sCBo/91Qv3TEATuy+DBzneZwS0zyTm zmaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:date:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=sq1M/S8GAvg5DQqu/2E1ry6um3VYgqHfFT3asXYtghU=; fh=TOr0z+yV0An5/R2tRqbnEJzbVqldJH7hujnmQLhQh/s=; b=X9x1M7gGBWk23NpNfyk7eewk/1ehCF1nf4s3llfepVtrM5D4/2NAC4zjjciVkkYNvk PFODOmuL1S+O+osdtMBVtTuQ7zADK4gzBmCJ2flDrZE0BLMOyv9YfDi5YK2F4r+qxmgV jzJ+E/wosfmsXTl3VL/Qt8u/7iKtXfYIUmev/HgcnCCdL5mZRTcPfE7tmJYCXPtGfxVP dhlSWsoN/1Zbty/FBiFSzlw591QLQ+GMTnqphSgGIoGXMvLUm44oUVFP21mceJYHzU/J vbpNGSm+wh57Wwh7CRjnpWkpkfWw5x5EhzT3hothvg6hOd/6VesmK5KUm4q59cA0KlqF rBTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=twcj8WT9; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id lz17-20020a170906fb1100b0098e24139529si7022219ejb.733.2023.06.30.00.06.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 00:06:20 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=twcj8WT9; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0237C3856968 for ; Fri, 30 Jun 2023 07:06:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0237C3856968 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688108779; bh=sq1M/S8GAvg5DQqu/2E1ry6um3VYgqHfFT3asXYtghU=; h=Date:To:Cc:Subject:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=twcj8WT9TMRCD3JQgoTqxSrRIrDBwsnvGQRILkaEzWY4ZVTuTiC1YIVho8jXhjgZ2 fuBz3aNfv+i+ro/BLRNPxYl3lMkTbIKYjR4lI1BHvP3sfCuI8zACJcGlyOonjGPqsh sKblKQSPRvwP2UEZHo+0+yGICjZfquvHmiTFnt/g= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id 820C03857704 for ; Fri, 30 Jun 2023 07:05:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 820C03857704 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1b7fb1a82c4so9830585ad.1 for ; Fri, 30 Jun 2023 00:05:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688108734; x=1690700734; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=sq1M/S8GAvg5DQqu/2E1ry6um3VYgqHfFT3asXYtghU=; b=ThZtLL/ME178ev6JQbpA4uZCD6tuesuceD3hxEEKhNF6zicd7lsk5gMk1oR+7G0lRJ Iwy9DgUaXyYz70u+8Qpq9JvzoB2UJRSRP296QCdB/48sDbL4cXBKfuBEaj+TBFJeoDoi ltMLgU5iAVIK2L3LNIKM3umAXpp100yLiYqupfqGGgNZFI4r8O9IiHQ0zJbT8mT7iYwc 4CVjXM5Hh3OS8CFUDiG/VWdvjHJnF8NtSWWWIEKSnb3F2OhvW/TbNPkM2OIDH8R1PRsP xsOw/aV+8JrdKWEnVMyHyamG02QzCw7ZkMwDJ0rq28KnSvBc5O74/ykxLOcuZMfmFwPs 6XIQ== X-Gm-Message-State: ABy/qLYt9r7G7oRZdx0SzMdayt8n0mOIeWvruoJWdeWZQ6FHl3amjT1U 0Kpg0WinC+15KZzy9gzk6t8= X-Received: by 2002:a17:903:1107:b0:1b8:6498:acc1 with SMTP id n7-20020a170903110700b001b86498acc1mr1293456plh.23.1688108734394; Fri, 30 Jun 2023 00:05:34 -0700 (PDT) Received: from Thaum.localdomain (59-102-120-25.tpgi.com.au. [59.102.120.25]) by smtp.gmail.com with ESMTPSA id bf3-20020a170902b90300b001b50b933febsm10057559plb.238.2023.06.30.00.05.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 00:05:34 -0700 (PDT) Date: Fri, 30 Jun 2023 17:05:24 +1000 To: Jason Merrill Cc: Patrick Palka , gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Fix ICE with parameter pack of decltype(auto) [PR103497] Message-ID: References: <4c77b9a3-48cb-93c7-1489-38155c637926@idea> <5d7ada85-ccaa-bc07-b625-20fdc5dc924c@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <5d7ada85-ccaa-bc07-b625-20fdc5dc924c@redhat.com> X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Nathaniel Shead via Gcc-patches From: Nathaniel Shead Reply-To: Nathaniel Shead Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763856637567630402?= X-GMAIL-MSGID: =?utf-8?q?1770110352434605638?= On Thu, Jun 29, 2023 at 01:43:07PM -0400, Jason Merrill wrote: > 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? I gave that a try and it seems to work fine. Regtested on x86_64-pc-linux-gnu. -- 8< -- This patch ensures 'type_uses_auto' also checks for usages of 'auto' in parameter packs. PR c++/103497 gcc/cp/ChangeLog: * pt.cc (type_uses_auto): Check inside parameter packs. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/decltype-auto-103497.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/pt.cc | 7 ++++++- gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 2345a18becc..2a3ba5ab67d 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -31083,7 +31083,12 @@ type_uses_auto (tree type) { if (type == NULL_TREE) return NULL_TREE; - else if (flag_concepts_ts) + + /* For parameter packs, check the contents of the pack. */ + if (PACK_EXPANSION_P (type)) + type = PACK_EXPANSION_PATTERN (type); + + if (flag_concepts_ts) { /* The Concepts TS allows multiple autos in one type-specifier; just return the first one we find, do_auto_deduction will collect all of 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(); +}