From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by sourceware.org (Postfix) with ESMTPS id 3C3753858C2A for ; Sat, 24 Jun 2023 13:24:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3C3753858C2A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-54f75f85a17so935201a12.0 for ; Sat, 24 Jun 2023 06:24:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687613078; x=1690205078; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=ONFwewP5lSXm14mPDSMl2WKSF8rtdAe+GAciMsvb+BA=; b=VjHGzJjmlK2wp4d5EwpAe4zRtk8eYltttkN/nhvW+7xOqHEoNNBhEcar+kj2OeKgdQ cz62TBADMqEt0fjPaSW3KyH2g58X6mYSAu6SC6ddo8UqmIEKq59DmYzzCaOCdquLxdLN eBIVx487Q510vskNNXeE78KwibBk6ToakflemT/aU63huYvE8/Zss1zlwbwjogQCqTkc LCA8NUbLFo4Sb5cpjFipNKPv9kWp5Qd60MSa4j6Eks3lDAX0LPpKb2W8R+Op1So3rUHP l+dj9Eir6xXZixvdvcSnyrEpNT9tZXSj5H0o/jzA3NzKQvfrEAlHEQNGQ056y32UungO 4lnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687613078; x=1690205078; 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=ONFwewP5lSXm14mPDSMl2WKSF8rtdAe+GAciMsvb+BA=; b=GxMf6puD9i8P38eTtmFb5uE/Jv+HjVvrc2YKZpqBaGj3g3WXOANW7oMDP347EFADjT Nh476FKqcCoQ0oX+86dYf9GFuR9CYsW5cyYUKzkRnpP4EsWjq0warwlhxtcjNA+uvynf hykOIxLyTpz38KOrj6u0zHgcHvbjPJhkYJUm2vXS4pRAs11AI+SFkCPSS1JEUnrDJ7k1 rf+zjK+RkjYcK4vHAs/y3DQgy0dba/e5NyWdc4o8lunMhVri8HGMhqw2m8K+Y29EtZNb zuJVzBlElzc3qHzvDvlY5pk3UVdgQGdxfMIzhQHw6WX4XmTmUIsxdqQ5UA+KgkFsi67a 0kUQ== X-Gm-Message-State: AC+VfDz2rwHSlzrcc/tJ8To56tOPwisgdcqZVQg+TwmUi7oU72kzKO7z PqozMts/Zs9leNILRT3Imnf2X6x+HuA= X-Google-Smtp-Source: ACHHUZ7HkC3YVoEq7kje2VL/f8Xy3318DlyoS3+Xs34hTpSPexf/GiBoURGnyYRr32UeWBq/L6Ankg== X-Received: by 2002:a17:903:278c:b0:1b5:26d4:517d with SMTP id jw12-20020a170903278c00b001b526d4517dmr677088plb.29.1687613078023; Sat, 24 Jun 2023 06:24:38 -0700 (PDT) Received: from Thaum.localdomain (59-102-120-25.tpgi.com.au. [59.102.120.25]) by smtp.gmail.com with ESMTPSA id 5-20020a170902e9c500b001b024ee5f6esm254645plk.81.2023.06.24.06.24.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Jun 2023 06:24:37 -0700 (PDT) Date: Sat, 24 Jun 2023 23:24:32 +1000 From: Nathaniel Shead To: Patrick Palka Cc: gcc-patches@gcc.gnu.org, jason@redhat.com Subject: Re: [PATCH] c++: Fix ICE with parameter pack of decltype(auto) [PR103497] Message-ID: References: <4c77b9a3-48cb-93c7-1489-38155c637926@idea> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4c77b9a3-48cb-93c7-1489-38155c637926@idea> X-Spam-Status: No, score=-11.4 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 List-Id: 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)); + 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(); +} -- 2.41.0