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.129.124]) by sourceware.org (Postfix) with ESMTPS id 0D4F63858D35 for ; Wed, 28 Jun 2023 17:54:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0D4F63858D35 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=1687974893; 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=jlRbgyIMsynJ+5wzuduhMyXGfxjP47WEF1ugowmUh0A=; b=J8d+iscNJF+PuL5y1nzjvoWGWeszljV5qzJXT7OwX35r9DT5Cn5K+RognNtLCgrgK2mFsF lfobdbOYzAgTH427QwgDM/K2dULT+J+f8S3sg/HO4ikVvefxYzzeRZymmeU27bVwrwHse2 q0yFkxp4DsREjWAZbBv/b/u+GJGuHOQ= Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-609-U4a9kyMCPYiYKGIK_beHKA-1; Wed, 28 Jun 2023 13:54:51 -0400 X-MC-Unique: U4a9kyMCPYiYKGIK_beHKA-1 Received: by mail-lj1-f199.google.com with SMTP id 38308e7fff4ca-2b6a679df26so612661fa.2 for ; Wed, 28 Jun 2023 10:54:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687974890; x=1690566890; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jlRbgyIMsynJ+5wzuduhMyXGfxjP47WEF1ugowmUh0A=; b=PfDUYaiHWF9GjGYMOwdr99kb3+2ahHCKQGWS51ewKWml5juopwztdBKhV3/Z1ocHSs P8uQciIf4i4er2tlf2XxTZ25zBZz7hLtSvlJIM4/8+I73zdJ+99OgkOsntbf45It+zch rK0oPrvXw03xNwVAr6BTXIUsSW416vhxr7VZUQhtiLZN2kKIEYqb0E+09liNHDcriFIW kwnweIRnl6pIJEps5qN5rtuTH05i9qQ6IEkZ5wndKyMjMGReWNzrIUVPI8wfKDgCT1yo G37Etr4mSysQaXm6d1tp6mozRrEljACdJ6Foau7zEbARIZQ40wjJLRyH2Cr7UZcAurg2 rFXw== X-Gm-Message-State: AC+VfDzs7QLY4jDEF/ag6elWI7bXm+NMnC7CvXqyAa7UdcUecKeUeSI+ mRCHpfH582XqVa7jlG5S2VX/Qo4CllLM9apTpIcy6UYGcd7muu0oZKVwzswXhkoiuiGC0RPVgPF ygBjkx4ev5SzAmhvK5RPeMQKFeJ8OXMbpkw== X-Received: by 2002:a2e:9053:0:b0:2b6:b456:7243 with SMTP id n19-20020a2e9053000000b002b6b4567243mr3918663ljg.13.1687974889653; Wed, 28 Jun 2023 10:54:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7CO8LFaHwEBlym622u9TA8TGu2FmUMBedu9n4gjYw8j8IClvJm2HesFJdIQARVfA+9aUOxUAHI6QQjfo8s+O0= X-Received: by 2002:a2e:9053:0:b0:2b6:b456:7243 with SMTP id n19-20020a2e9053000000b002b6b4567243mr3918651ljg.13.1687974889266; Wed, 28 Jun 2023 10:54:49 -0700 (PDT) MIME-Version: 1.0 References: <4c77b9a3-48cb-93c7-1489-38155c637926@idea> In-Reply-To: From: Patrick Palka Date: Wed, 28 Jun 2023 13:54:38 -0400 Message-ID: Subject: Re: [PATCH] c++: Fix ICE with parameter pack of decltype(auto) [PR103497] To: Nathaniel Shead Cc: gcc-patches@gcc.gnu.org, jason@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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,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 Sat, Jun 24, 2023 at 9:24=E2=80=AFAM 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 th= e > > 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 th= e > > commit. I could be wrong but AFAIK the hook only performs this when th= e > > 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 !=3D CPP_S= COPE) > > > { > > > type =3D 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) =3D=3D 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 =3D 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/p= r103497.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 .de= cltype.auto..|no parameter packs" } > > > > I noticed for > > > > void foo(decltype(auto) arg); > > > > we already issue an identical error from grokdeclarator. Perhaps we co= uld > > instead extend the error handling there to detect decltype(auto)... as = well, > > rather than adding new error handling in cp_parser_simple_type_specifie= r? > > Ah thanks, I didn't notice this; this simplifies the change a fair bit. > How about this patch instead? LGTM! Though I can't approve the patch myself. > > 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 =3D type_uses_auto (type); > + if (!auto_node && parameter_pack_p) > + auto_node =3D type_uses_auto (PACK_EXPANSION_PATTERN (type)); > + > if (auto_node && !(cxx_dialect >=3D cxx17 && template_parm_flag)) > { > if (cxx_dialect >=3D cxx14) > diff --git a/gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C b/gcc/test= suite/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 param= eter with .decltype.auto.." } > + > +int main() { > + foo(); > +} > -- > 2.41.0 >