From patchwork Wed Apr 7 21:58:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1463534 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=RoyxwwOf; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FFyvN5mg8z9sWC for ; Thu, 8 Apr 2021 07:58:23 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 30808393A412; Wed, 7 Apr 2021 21:58:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 30808393A412 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1617832700; bh=LfAD21Lr5xZ1CDe96vngkwM/ISyUb09wUeyn9PgrIFM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=RoyxwwOfI8TAFQND2crR7jfbI0g0erEz4a1pd6nVCj7Gza6hm91wJCZxvmfPAXFwI ANVgUIw1i9X4UzxcFAS7sksKtXta7kKkz4WzkrPVPo73zC9ubSb50eArgxjIRHN5V0 0RpAMuHvJcCZTjAtQ0/+hgCk/xeisqh+X459oZgI= 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.133.124]) by sourceware.org (Postfix) with ESMTP id 7B1E8388A03C for ; Wed, 7 Apr 2021 21:58:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7B1E8388A03C Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-98-qrMQml0xOi-W9zNHa8PICg-1; Wed, 07 Apr 2021 17:58:16 -0400 X-MC-Unique: qrMQml0xOi-W9zNHa8PICg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C1DAA8710F4 for ; Wed, 7 Apr 2021 21:58:15 +0000 (UTC) Received: from pdp-11.redhat.com (ovpn-113-222.rdu2.redhat.com [10.10.113.222]) by smtp.corp.redhat.com (Postfix) with ESMTP id 616E55D9CA; Wed, 7 Apr 2021 21:58:15 +0000 (UTC) To: GCC Patches , Jason Merrill Subject: [PATCH] c++: Fix ICE with unexpanded parameter pack [PR99844] Date: Wed, 7 Apr 2021 17:58:10 -0400 Message-Id: <20210407215810.347038-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.4 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_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Marek Polacek via Gcc-patches From: Marek Polacek Reply-To: Marek Polacek Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" In explicit17.C, we weren't detecting an unexpanded parameter pack in explicit(bool), so we crashed on a TEMPLATE_PARM_INDEX in constexpr. I noticed the same is true for noexcept(), but only since my patch to implement delayed parsing of noexcept. Previously, we would detect the unexpanded pack in push_template_decl but now the noexcept expression has not yet been parsed, so we need to do it a bit later. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? gcc/cp/ChangeLog: PR c++/99844 * decl.c (build_explicit_specifier): Call check_for_bare_parameter_packs. * except.c (build_noexcept_spec): Likewise. gcc/testsuite/ChangeLog: PR c++/99844 * g++.dg/cpp2a/explicit16.C: Use c++20. * g++.dg/cpp0x/noexcept66.C: New test. * g++.dg/cpp2a/explicit17.C: New test. --- gcc/cp/decl.c | 3 +++ gcc/cp/except.c | 2 ++ gcc/testsuite/g++.dg/cpp0x/noexcept66.C | 13 +++++++++++++ gcc/testsuite/g++.dg/cpp2a/explicit16.C | 2 +- gcc/testsuite/g++.dg/cpp2a/explicit17.C | 9 +++++++++ 5 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept66.C create mode 100644 gcc/testsuite/g++.dg/cpp2a/explicit17.C base-commit: 2f3d9104610cb2058cf091707a20c1c6eff8d470 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index edab147c78d..3294b4fa943 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -17991,6 +17991,9 @@ require_deduced_type (tree decl, tsubst_flags_t complain) tree build_explicit_specifier (tree expr, tsubst_flags_t complain) { + if (check_for_bare_parameter_packs (expr)) + return error_mark_node; + if (instantiation_dependent_expression_p (expr)) /* Wait for instantiation, tsubst_function_decl will handle it. */ return expr; diff --git a/gcc/cp/except.c b/gcc/cp/except.c index 0bbc229490e..cbafc09629b 100644 --- a/gcc/cp/except.c +++ b/gcc/cp/except.c @@ -1228,6 +1228,8 @@ type_throw_all_p (const_tree type) tree build_noexcept_spec (tree expr, tsubst_flags_t complain) { + if (check_for_bare_parameter_packs (expr)) + return error_mark_node; if (TREE_CODE (expr) != DEFERRED_NOEXCEPT && !value_dependent_expression_p (expr)) { diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept66.C b/gcc/testsuite/g++.dg/cpp0x/noexcept66.C new file mode 100644 index 00000000000..6c76d9146ad --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept66.C @@ -0,0 +1,13 @@ +// PR c++/99844 +// { dg-do compile { target c++11 } } + +template +struct S { + void fn() noexcept(B); // { dg-error "parameter packs not expanded" } +}; + +void fn () +{ + S s; + s.fn(); +} diff --git a/gcc/testsuite/g++.dg/cpp2a/explicit16.C b/gcc/testsuite/g++.dg/cpp2a/explicit16.C index 9d95b0d669e..9c20f6332e9 100644 --- a/gcc/testsuite/g++.dg/cpp2a/explicit16.C +++ b/gcc/testsuite/g++.dg/cpp2a/explicit16.C @@ -1,5 +1,5 @@ // PR c++/95066 - explicit malfunction with dependent expression. -// { dg-do compile { target c++2a } } +// { dg-do compile { target c++20 } } template struct Foo { diff --git a/gcc/testsuite/g++.dg/cpp2a/explicit17.C b/gcc/testsuite/g++.dg/cpp2a/explicit17.C new file mode 100644 index 00000000000..38a61f4a273 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/explicit17.C @@ -0,0 +1,9 @@ +// PR c++/99844 +// { dg-do compile { target c++20 } } + +template +struct S { + constexpr explicit(B) S() {} // { dg-error "parameter packs not expanded" } +}; + +constexpr S s;