From patchwork Tue Mar 5 20:56:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 86841 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4BE8738582AA for ; Tue, 5 Mar 2024 20:56:45 +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.133.124]) by sourceware.org (Postfix) with ESMTPS id DD01D3858C98 for ; Tue, 5 Mar 2024 20:56:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DD01D3858C98 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 DD01D3858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709672179; cv=none; b=iTkK0s6r8C9V6uEarehtXYO+jx+JMZ9ZYFEQBlU/4iXylbVmVsIwhnwboVoz4r2SY8kIf3KVCgSiaqNOF2cuNu493G7qjYyVHkmqOMG7PGelBrPQ+fYW3ftalc2OZt3xI+GPR4hd/+JEgHMUWtzYUwtO0cKTckhOtZNp8GfEZKI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709672179; c=relaxed/simple; bh=5hHv2xLBmYgOLZbfzfAgdi01tZnB0U6J2v1tS+L7NEU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=J4vrAbHDelA3QVFUSqcKyfkEN1vH6R7Ndpv8Hki6R63WTGqMjAOivztSi78V4SwIFTAdQBOiH+9Zyj2xIqtEiviGrK2Yz6BCa52LB7wF0NnwFw0EiYNu1GvWj6RzSdFt5dwK72Kh2VNIekL0xR0PqYgx5oRMB6XfXH4uKdFTkJI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709672176; 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=lTo/3gl4GqaQsRxKEjTEocKiMXuK9dzf9fXcOJWaBpQ=; b=JBa9ftVBoS/iRojU05jIz2uzJVArIxgdyWoo18SDdgl7bYa1HzBNUvFNk8SiZmwyCGYNRG xEGpYHsN+yEOkLDCsSG1kNsaAqKiMgpUuEFBcjSwGTkRbnkixLP7umly2+6EZjDdHLr63x YG8s7D0B4KQXWA65lEtcf4hrRz9lv8g= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-688-yNIz5bcGPceJkB-4G1GQ8A-1; Tue, 05 Mar 2024 15:56:13 -0500 X-MC-Unique: yNIz5bcGPceJkB-4G1GQ8A-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 E317E185A786 for ; Tue, 5 Mar 2024 20:56:12 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.33.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCD09C04120; Tue, 5 Mar 2024 20:56:12 +0000 (UTC) From: Marek Polacek To: GCC Patches , Jason Merrill Subject: [PATCH] c++: ICE with noexcept and local specialization [PR114114] Date: Tue, 5 Mar 2024 15:56:05 -0500 Message-ID: <20240305205605.447458-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=-12.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_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+patchwork=sourceware.org@gcc.gnu.org Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? -- >8 -- Here we ICE because we call register_local_specialization while local_specializations is null, so local_specializations->put (); crashes on null this. It's null since maybe_instantiate_noexcept calls push_to_top_level which creates a new scope. Normally, I would have guessed that we need a new local_specialization_stack. But here we're dealing with an operand of a noexcept, which is an unevaluated operand, and those aren't registered in the hash map. maybe_instantiate_noexcept wasn't signalling that it's substituting an unevaluated operand though. PR c++/114114 gcc/cp/ChangeLog: * pt.cc (maybe_instantiate_noexcept): Save/restore cp_unevaluated_operand, c_inhibit_evaluation_warnings, and cp_noexcept_operand around the tsubst_expr call. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/noexcept84.C: New test. --- gcc/cp/pt.cc | 6 +++++ gcc/testsuite/g++.dg/cpp0x/noexcept84.C | 32 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept84.C base-commit: 8776468d9e57ace5f832c1368243a6dbce9984d5 diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index c4bc54a8fdb..11f7d33c766 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -26869,10 +26869,16 @@ maybe_instantiate_noexcept (tree fn, tsubst_flags_t complain) if (orig_fn) ++processing_template_decl; + ++cp_unevaluated_operand; + ++c_inhibit_evaluation_warnings; + ++cp_noexcept_operand; /* Do deferred instantiation of the noexcept-specifier. */ noex = tsubst_expr (DEFERRED_NOEXCEPT_PATTERN (noex), DEFERRED_NOEXCEPT_ARGS (noex), tf_warning_or_error, fn); + --cp_unevaluated_operand; + --c_inhibit_evaluation_warnings; + --cp_noexcept_operand; /* Build up the noexcept-specification. */ spec = build_noexcept_spec (noex, tf_warning_or_error); diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept84.C b/gcc/testsuite/g++.dg/cpp0x/noexcept84.C new file mode 100644 index 00000000000..06f33264f77 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept84.C @@ -0,0 +1,32 @@ +// PR c++/114114 +// { dg-do compile { target c++11 } } + +template +constexpr void +test () +{ + constexpr bool is_yes = B; + struct S { + constexpr S() noexcept(is_yes) { } + }; + S s; +} + +constexpr bool foo() { return true; } + +template +constexpr void +test2 () +{ + constexpr T (*pfn)() = &foo; + struct S { + constexpr S() noexcept(pfn()) { } + }; + S s; +} + +int main() +{ + test(); + test2(); +}