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 0172E386D635 for ; Thu, 15 Feb 2024 22:17:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0172E386D635 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 0172E386D635 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=1708035469; cv=none; b=NyPZjvdJ2ejgMzvZ3nieo4grBfMxZ+6myIayy87XLH7KjkCaGJQIwdgyY0vsHgw2QVrl79YbF9xX//ebBTdZL3mn/TiS371N6c64s8fRdg3Sil0gSg3nmW4xOBDNG0vZkLVAojdLix0sNb8sjp2c38YiGbKqYm2ACIef73ItP94= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708035469; c=relaxed/simple; bh=pLccWa/6vOXAfAs/PGaSy8ke24FBGFEvsQWY2wkjQT0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Qo8B9INXyqDOw6Dr37xZtGjDeRy9eIYpmtdjnUUAiRBoTdo5M9fXSDcG2Y1HrTHsnUaWS/Q15Uo2eHd7HO+Y+TIywWBUgB3fzyBr1OZzqWr4B5rUQtJ+aa9mCGT1fSRKQye47lF5Dg00iw7C2zn9+FPTwLt03kFH/w1GkDBmfyk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708035465; 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=zrTK7/t0zHCM5917/I0dOK8c8TQIZCt/Gtq4PHzOMTE=; b=eV6WQbVto3DzzgFOsAgSlA9BgWmvygcDbSe9Yo1tgq/qpW4jJGOGDkkZGx6B+Fho6rlt5D Ppizt1zsxXzxH9bBrwCfeM51jWYToCpUvImprM32M257cxS8H1Bvb2YhGn7VnHHaXujbEr 4/1yhiNW5aPwqQUA/Wx+P8eQkPDWINc= 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-43-WbNBD0m2O4KPA3M4H4FRzQ-1; Thu, 15 Feb 2024 17:17:44 -0500 X-MC-Unique: WbNBD0m2O4KPA3M4H4FRzQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 DB63428B6A20 for ; Thu, 15 Feb 2024 22:17:43 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.33.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id BDEDB492BC9; Thu, 15 Feb 2024 22:17:43 +0000 (UTC) From: Marek Polacek To: Jason Merrill , GCC Patches Subject: [PATCH] c++: wrong looser excep spec for dep noexcept [PR113158] Date: Thu, 15 Feb 2024 17:17:42 -0500 Message-ID: <20240215221742.646761-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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_H2,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: Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? By the ??? below I mean that maybe_instantiate_noexcept could return a tristate, and then maybe_check_overriding_exception_spec could check if (maybe_instantiate_noexcept ().is_unknown ()) return true; and we don't have to add any new checks to maybe_check_o_e_spec. -- >8 -- Here we find ourselves in maybe_check_overriding_exception_spec in a template context where we can't instantiate a dependent noexcept. That's OK, but we have to defer the checking otherwise we give wrong errors. PR c++/113158 gcc/cp/ChangeLog: * search.cc (maybe_check_overriding_exception_spec): Defer checking when a noexcept couldn't be instantiated. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/noexcept83.C: New test. --- gcc/cp/search.cc | 7 +++++ gcc/testsuite/g++.dg/cpp0x/noexcept83.C | 37 +++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept83.C diff --git a/gcc/cp/search.cc b/gcc/cp/search.cc index c948839dc53..73d254d6b84 100644 --- a/gcc/cp/search.cc +++ b/gcc/cp/search.cc @@ -1975,6 +1975,13 @@ maybe_check_overriding_exception_spec (tree overrider, tree basefn) || UNPARSED_NOEXCEPT_SPEC_P (over_throw)) return true; + /* We also have to defer checking when we're in a template and couldn't + instantiate the noexcept yet. + ??? maybe_instantiate_noexcept already checked these. Use tristate? */ + if (type_dependent_expression_p (base_throw) + || type_dependent_expression_p (over_throw)) + return true; + if (!comp_except_specs (base_throw, over_throw, ce_derived)) { auto_diagnostic_group d; diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept83.C b/gcc/testsuite/g++.dg/cpp0x/noexcept83.C new file mode 100644 index 00000000000..47832bbb44d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept83.C @@ -0,0 +1,37 @@ +// PR c++/113158 +// { dg-do compile { target c++11 } } + +template +struct V { + static constexpr bool t = false; +}; +struct base { + virtual int f() = 0; +}; + +template +struct derived : base { + int f() noexcept(V::t) override; +}; + +struct base2 { + virtual int f() noexcept = 0; +}; + +template +struct W { + static constexpr bool t = B; +}; + +template +struct derived2 : base2 { + int f() noexcept(W::t) override; // { dg-error "looser exception specification" } +}; + +void +g () +{ + derived d1; + derived2 d2; // { dg-message "required from here" } + derived2 d3; +} base-commit: b3b3bd250f0a7c22b7d46d3522c8b94c6a35d22a prerequisite-patch-id: 3beddc8cae6ef7f28cd7eac7240d5f4dad08e5f7 -- 2.43.0