From patchwork Sat Apr 22 06:25:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 86553 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1534341vqo; Fri, 21 Apr 2023 23:26:13 -0700 (PDT) X-Google-Smtp-Source: AKy350bpu7/DxuCMd8hDXLa2sfE9UFgUkxu5WzmIa6c+OHB2v3RaHX+yXVJauh15mPfA1r2sZbSO X-Received: by 2002:a05:6402:120c:b0:506:a2dd:e162 with SMTP id c12-20020a056402120c00b00506a2dde162mr7072512edw.22.1682144773062; Fri, 21 Apr 2023 23:26:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682144773; cv=none; d=google.com; s=arc-20160816; b=aSCblaR7w3IMbDt7XmrC1XxqZffZ+QYkflKI4NJS979mtCev49bp9CNy94t6S89lgK pzePlaxbWz7ONAiI1HdweSGVR2zE0FNRhVE4ZeBSeOX+cG6kPtAwLjpcQ9C2psYMVLOS t0q4cIeCUTX4jq+9FPfMVtOpLfdJZj1HOrh7A7P6DiraMOAvPt9kxLs3PIDZaK+HKvgB NWM8c0K/GRlbtZkUv9P26Tsct6X9ABKU/1uBgojode6JF1WeeflLuaEsn8hvLO11Z88S JnRDObqVyZruMujB6Wvc8wxWabEcCbN4z/g7PPSr7rmlHYbbrQkg9pSFe8jWvqBM4oPi rKUg== 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 :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=/HCLF+ff3ikZqifo/nez0sQK2hSg5dA7TvBwRnyfukQ=; b=YN2E6ETieVJSmfhT/zM80jAe6URYqk/F0CW3HC9X77OFiUJom/kP6AzhBDKWSJYXUv CCf0wl+UXSEDP3GiyvRuIqN4jey5EQyGcWrI399ZMQPswANL17CAAQaREVsjATIMYOwy g1NRlcspVw95mL20Emba3tqpQPlkGEATaUlpMRuDJIHF9P+4lEctYpg6cOVAZgsg9CIP T9yi8P67PVYU9Ax6keqmlBXK264APELpC0XZMYcg4UzDcKzlwT0tMuTmGmVxjcf0oUaV f0gIje/VF753TgWVdOndqMSM7k8HJre/CkLdCbvlgW31L41EdGD3IonxZq+EqcvHLQ7c d8Ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=rN7rnXkF; 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 w21-20020a056402129500b004fd1f069ba6si3934493edv.560.2023.04.21.23.26.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Apr 2023 23:26:13 -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=rN7rnXkF; 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 E02863857713 for ; Sat, 22 Apr 2023 06:26:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E02863857713 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682144771; bh=/HCLF+ff3ikZqifo/nez0sQK2hSg5dA7TvBwRnyfukQ=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=rN7rnXkFK+Oij5A3X35UbgLRkLAvA+CTBP4E+NJPucY7r5Dp08Ch9a3jKWdYo59FS tEdPmknZ7dCEMQXCDiH3rUZ2TW55SNsPCRYb81e1wCl6Dj6DYEjgBHkBp7WDZqeo+m ihBSyWUBnh+uTKvRCYoiZi/dvb7VXEtK0W2LhBJI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by sourceware.org (Postfix) with ESMTPS id 9F6DF3858C50 for ; Sat, 22 Apr 2023 06:25:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9F6DF3858C50 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1a66b9bd7dfso31903105ad.2 for ; Fri, 21 Apr 2023 23:25:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682144726; x=1684736726; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/HCLF+ff3ikZqifo/nez0sQK2hSg5dA7TvBwRnyfukQ=; b=IDq2THZNWp5W8RuxCnuNrA3JzEhSQK2GvHfazLfciQ+L79AXq3Jj8hp5TqmOJE3LKk U6/5Ayh8HXkPmbBkiRjyy6FdLHYpOngJKjz3iobnNW+gGMR0Jo1kvuKx/SNKc3+E//Cv npTgwMYHHPNpmsC4GzONARfQs5UHd4USws3HWXCsQKZl/vTWYrBoBw/JAi/aynoYCr5J zawggj/ZHj0Kfib6H2vasYytT4O5nKQpZNo+rISfQ+XsiO1mlXfTrddg28AmG/JjyOm2 yTvXkwK4gTERwpa3LNjbjxdBTTbSAv9Aw/LpY52Qnvda+zbZ0mXOKKa1y1YZ1LrkHdaC Drbw== X-Gm-Message-State: AAQBX9f0nmBQbQ7m4H6Z0rt0+RLrvaxuO5uEvteWcEKcOFMt6OhruOQu UERLP18W7uVtNC1xWN2nNMpXLqWyDjk= X-Received: by 2002:a17:903:113:b0:1a5:167f:620f with SMTP id y19-20020a170903011300b001a5167f620fmr6344214plc.15.1682144726137; Fri, 21 Apr 2023 23:25:26 -0700 (PDT) Received: from Thaum.localdomain (125-209-144-50.tpgi.com.au. [125.209.144.50]) by smtp.gmail.com with ESMTPSA id md17-20020a17090b23d100b0024744818bc5sm5365383pjb.9.2023.04.21.23.25.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Apr 2023 23:25:25 -0700 (PDT) Date: Sat, 22 Apr 2023 16:25:13 +1000 To: gcc-patches@gcc.gnu.org Cc: Nathaniel Shead Subject: [PATCH] c++: Fix ICE with parameter pack of decltype(auto) [PR103497] Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-11.8 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?1763856637567630402?= 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. PR 103497 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 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 + && 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" } + +int main() { + foo(); +}