From patchwork Mon Jan 15 22:14:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 188344 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp1970960dyc; Mon, 15 Jan 2024 14:15:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IH8HI5FDI34LQAX9gBwfrSB0Co/RyedpbvwwcKIeMWtVz32738AcoaAPgxbs1BX77Aly+ym X-Received: by 2002:a05:622a:1353:b0:429:fe73:f352 with SMTP id w19-20020a05622a135300b00429fe73f352mr851356qtk.134.1705356945269; Mon, 15 Jan 2024 14:15:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705356945; cv=pass; d=google.com; s=arc-20160816; b=S77d+qLwVoiYwnD0jutX71JA6M5j7xtTwvx8qrMX07APVzQVGN1OSWyR/mf1wIrRHd qZxDoc9wh5ZbXHDY/ldcuijidUsUeva6niD6U5+RqXKpcvtnZGczmApN2L/U+NrL2QR8 6O9tf57JFYMuInJwdXByru7rgmdBwR5j/D+XAZxqqlemnCi7GLzFIGwArCHTu110ukfx mVGf+ND769SzhCjhRrHqXauKzxPzN3/l8gKIUGUnJt3A0GZltqPwxhUYJ8WFOHoZXACD 23LvoDMGg/Q1hnM1Yr8RxusmUWUySHkskNMtoautn7TUPDOfJKdbh6iWFFRb8Zo3CdT+ Expw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=XknUo7//07i4X9c2B/I04zHUYo8EODdAjM4BkE9V/7U=; fh=2BFo3VQCimnyWTJsWe6sNdepvNrW+J/2ctoM6N7MZ0Y=; b=P4RdLwupkuGVog1fPiH3evquiDNgjYNZ4LDt2JZvmDwf/HExGaksKzWex5lIHwzGd0 0QCWkQkyU7GaFtLVjJYs7nlOusjKt6+WcCYBYjrAG21cApc/BEtRrpNtATmuD5WoI2M8 zIfF8BndDnwA+YFyDnz/ZaumwU7Kcg25kX/vnm2XMHgeh9qtBDF6xtV6TaexraAqdrrp hdTyRl+LXv998OB7vVN9pR17e/VEUe1AJP4ASEbungs82pM0e0e/9pkrO9B+g7/SatPC mcDIas2xveP9o03mbIF5Fm9CuZl6C1mzwtz6Xb5j5OmmOMCR0nkNfPW1zclslbG5lw92 lz6w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=H44K30vv; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id 21-20020ac85755000000b00429f4b4ec9bsi1917035qtx.66.2024.01.15.14.15.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 14:15:45 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=H44K30vv; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F3E7A385782B for ; Mon, 15 Jan 2024 22:15:44 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 DE73C3858C2C for ; Mon, 15 Jan 2024 22:14:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DE73C3858C2C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DE73C3858C2C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705356898; cv=none; b=rANyYxkG2TjBnZMW0hGlo+8JY+v6RETB96bRwxAa2Y0Mwuo23FrUc+sbQjq1sHe3YGl//bVtP+EG11GkHba2so9X+6aahE9vFdY5hg0PhIL1ke4eiAG2pDyrWYJ4mdBX4sKKYht0sO5tEr80nNCyA94OQhFkvVlJ79zNIN3zLjg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705356898; c=relaxed/simple; bh=uC9YWLgXUKZ8oNTlnHR0Ku8xg+Jc4+Huc/6taA3nmr0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=jQs8k0PNfVGwm8Z3tnHPgmX+5FgcMpX39Qn8xtMypRAEm8m474tXZG1HYHjSgmU9imqivPF2bysBCT86OqS096PUcedXQvsN7oebs0O7tFKphk8co476NISus58is7RAE3lskF/U8BqGm5Qt/Uup71rOwWs1owy85h/DRbshG+0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705356896; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=XknUo7//07i4X9c2B/I04zHUYo8EODdAjM4BkE9V/7U=; b=H44K30vvJGEhUJcMq1QPGG3vUa1tEvwGqAc5rAUkodIHjFL6c8xaoontpucyjeJ9xHHxCN h8HB/YUXWweI8u66DKuK7dcGDmuQAwhYUeTts5uTFGnT1o6mBsOJe7ZXdeCxRQyMd3Ijgz JP7yoJtEZidKFSfD2aXc66wxBsbz+Oo= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-547-0VTksnGZNEikPtNDDxzFqQ-1; Mon, 15 Jan 2024 17:14:55 -0500 X-MC-Unique: 0VTksnGZNEikPtNDDxzFqQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B61B13811F37 for ; Mon, 15 Jan 2024 22:14:54 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.17.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 92399C15968; Mon, 15 Jan 2024 22:14:54 +0000 (UTC) From: Marek Polacek To: GCC Patches , Jason Merrill Subject: [PATCH] c++: ICE with auto in template arg [PR110065] Date: Mon, 15 Jan 2024 17:14:48 -0500 Message-ID: <20240115221448.498382-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.1 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_H4, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788196364379249484 X-GMAIL-MSGID: 1788196364379249484 Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? -- >8 -- Here we started crashing with r14-1659 because that removed the auto checking in cp_parser_template_type_arg which seemed like dead code. But the attached test shows that the code can still be reached because cp_parser_type_id_1 checks auto only when auto_is_implicit_function_template_parm_p is on. Then I noticed that we're still crashing in C++20, and that ICE started with r12-4772. So I changed the reemerged check to use flag_concepts_ts rather than flag_concepts on the basis that check_auto_in_tmpl_args also checks flag_concepts_ts. PR c++/110065 gcc/cp/ChangeLog: * parser.cc (cp_parser_template_type_arg): Add auto checking. gcc/testsuite/ChangeLog: * g++.dg/concepts/auto8.C: New test. * g++.dg/concepts/auto8a.C: New test. --- gcc/cp/parser.cc | 12 ++++++++++-- gcc/testsuite/g++.dg/concepts/auto8.C | 17 +++++++++++++++++ gcc/testsuite/g++.dg/concepts/auto8a.C | 18 ++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/concepts/auto8.C create mode 100644 gcc/testsuite/g++.dg/concepts/auto8a.C base-commit: 731444b3c39e3dc3dd8778f430a38742861dcca1 diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 8ab98cc0c23..e92309b8960 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -25063,12 +25063,20 @@ cp_parser_type_id (cp_parser *parser, cp_parser_flags flags, static tree cp_parser_template_type_arg (cp_parser *parser) { - tree r; const char *saved_message = parser->type_definition_forbidden_message; parser->type_definition_forbidden_message = G_("types may not be defined in template arguments"); - r = cp_parser_type_id_1 (parser, CP_PARSER_FLAGS_NONE, true, false, NULL); + tree r = cp_parser_type_id_1 (parser, CP_PARSER_FLAGS_NONE, + /*is_template_arg=*/true, + /*is_trailing_return=*/false, nullptr); parser->type_definition_forbidden_message = saved_message; + /* cp_parser_type_id_1 checks for auto, but only for + ->auto_is_implicit_function_template_parm_p. */ + if (cxx_dialect >= cxx14 && !flag_concepts_ts && type_uses_auto (r)) + { + error ("invalid use of % in template argument"); + r = error_mark_node; + } return r; } diff --git a/gcc/testsuite/g++.dg/concepts/auto8.C b/gcc/testsuite/g++.dg/concepts/auto8.C new file mode 100644 index 00000000000..f9d98b2ec0f --- /dev/null +++ b/gcc/testsuite/g++.dg/concepts/auto8.C @@ -0,0 +1,17 @@ +// PR c++/110065 +// { dg-do compile { target c++17 } } + +template +inline constexpr bool t = false; + +int +f () +{ + return t auto&>; // { dg-error "template argument" } +} + +void +g () +{ + t auto&>; // { dg-error "template argument" } +} diff --git a/gcc/testsuite/g++.dg/concepts/auto8a.C b/gcc/testsuite/g++.dg/concepts/auto8a.C new file mode 100644 index 00000000000..fc60dc871c2 --- /dev/null +++ b/gcc/testsuite/g++.dg/concepts/auto8a.C @@ -0,0 +1,18 @@ +// PR c++/110065 +// { dg-do compile { target c++17 } } +// { dg-additional-options -fconcepts-ts } + +template +inline constexpr bool t = false; + +int +f () +{ + return t auto&>; // { dg-error "template argument" } +} + +void +g () +{ + t auto&>; // { dg-error "template argument" } +}