From patchwork Fri Feb 16 22:06:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 85912 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 75A91385770E for ; Fri, 16 Feb 2024 22:06: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.133.124]) by sourceware.org (Postfix) with ESMTPS id 5C9D5385782D for ; Fri, 16 Feb 2024 22:06:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5C9D5385782D 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 5C9D5385782D 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=1708121180; cv=none; b=pnH6vQzKDeE53qH8eWC+qiGZL3dkBjn1qcF1997mHATrBdaR5l+/th59Wf+bh4In7Ue4ZJjtVSi+2A5+CfmyjeiTJhcD/EpZ/r3SWcXSOXI6GVk35qK1CgV6ofGFN2DZkPW/+C09Ef3U4RvphYwCJeUP7NaKny3hQwCf2AC5n/E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708121180; c=relaxed/simple; bh=V0hNC+R4G23qGw0ty1JN1Z/ZhYShBayi+iVFeEbZ/Vg=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=ezJI6PdaUn7GyFGI6grnAWzAkJZEzuqoeKGEyWMsXEdswyvyabeF6WX4IaTfPeMA+X3kj9NkdkipXslCliAz3A0ZQ1LjlSJJcU/gwyUfPsLMnvSPMI7toIxMCdRJigvVK9wrhVvgqIIX1ewzWZGd3ztr3UOVFchLjHm3Pq6djzk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708121176; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=lCc8bOHLIkwAsfM1qZCWvp7X2vtR+WhicQCyuwd5PT8=; b=i9ZvWfTA+MWhJFG/rlFYCi1Y+g3RYyG6MukZRAJr+HES3jpeToqRjoS4vKE58AwIeCH1Mq PfJvSFTiU8Bau3BWGtBOv4SG5zW3kB242abKsg71S9J/zI+Wa7gg8CRsNQAdFKxQgilRDD PXcNYhNyEiUlRQTEa8Zuac7RPyxXdec= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-574-p1PYaKdkOwO9ZzxVmhHlyQ-1; Fri, 16 Feb 2024 17:06:14 -0500 X-MC-Unique: p1PYaKdkOwO9ZzxVmhHlyQ-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-68c51abe499so40246506d6.2 for ; Fri, 16 Feb 2024 14:06:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708121174; x=1708725974; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lCc8bOHLIkwAsfM1qZCWvp7X2vtR+WhicQCyuwd5PT8=; b=Ede2jSK4Z98KbQHrTwSegX8Qx99/EqSiKjkRLsl9isabXGex5J5HurhGRimHI8jXvB Qm1S0Z9MUg5wwvIL69frflGT14ylayZH0cnRTziS8aUakEzoO3WWtO6I12ZDHkYxm5cK ZIHKXOtG/DkttXnvBjgv9mADzgZEjWSIexY2uzANxOoyH4mbusyi/2njjgvjb5U8aU/X 1xd20jC+b0h9AGmO4k3DXWfC2GQBVR5+m46SZyYb/B66s9A6hrw1ENxwNP+DYgejS1aF 05UcnlOp7dV5y196Drh5TcQReoQI7IF90u/tk08ju0u+4RTQAKiOqBMboAf1UcZJZSIb yE8w== X-Forwarded-Encrypted: i=1; AJvYcCVqt8Xv10C56ipYQiAZTnIXV6uSLP+zKj67UxJb3WTzDDrX3KJ6SeBtPd0zbm9pbzaiolMkPIRb8jSm8ikzfLPbLrFk3xALog== X-Gm-Message-State: AOJu0YxKoJ4YgFgSY1XRdcNEAq9tfRHKpqKukgPlhRYre+PwSSZhJOxJ tf7RW0ri50btH+FVnPUA7q4NhNWp161N5jrQcZoetzO0wVJqq37Y7wAAtDZJrwEcTNsruMDSM6S C8o8lBDCETa/nHBmnwgKYWBzb1cgs4Mhi/+RAb9yQJbZECfB13sjhNrY= X-Received: by 2002:ad4:5c6d:0:b0:68f:2af8:7466 with SMTP id i13-20020ad45c6d000000b0068f2af87466mr5218844qvh.36.1708121174356; Fri, 16 Feb 2024 14:06:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IGmE1YIr+SItGXtfKI4pXijACBxl1BK96y/M99ZjatOXRGTNNOw5902UCCnXMKk3zlUkVeNog== X-Received: by 2002:ad4:5c6d:0:b0:68f:2af8:7466 with SMTP id i13-20020ad45c6d000000b0068f2af87466mr5218834qvh.36.1708121174083; Fri, 16 Feb 2024 14:06:14 -0800 (PST) Received: from redhat.com (2603-7000-9500-34a5-0000-0000-0000-1db4.res6.spectrum.com. [2603:7000:9500:34a5::1db4]) by smtp.gmail.com with ESMTPSA id z13-20020a0ce98d000000b0068f31fd157asm328053qvn.33.2024.02.16.14.06.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 14:06:13 -0800 (PST) Date: Fri, 16 Feb 2024 17:06:12 -0500 From: Marek Polacek To: Patrick Palka Cc: Jason Merrill , GCC Patches Subject: [PATCH v3] c++: wrong looser excep spec for dep noexcept [PR113158] Message-ID: References: <20240215221742.646761-1-polacek@redhat.com> <6db4134a-3a48-4ed4-bbbf-914a4ea66f3d@redhat.com> <8dd4c839-0bf7-77e2-e2f9-3e60f391a6fb@idea> MIME-Version: 1.0 In-Reply-To: <8dd4c839-0bf7-77e2-e2f9-3e60f391a6fb@idea> User-Agent: Mutt/2.2.12 (2023-09-09) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-11.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_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, 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 On Fri, Feb 16, 2024 at 04:39:47PM -0500, Patrick Palka wrote: > On Fri, 16 Feb 2024, Marek Polacek wrote: > > + /* We also have to defer checking when we're in a template and couldn't > > + instantiate & evaluate the noexcept to true/false. */ > > + if (processing_template_decl) > > + if ((base_throw > > + && (base_throw != noexcept_true_spec > > + || base_throw != noexcept_false_spec)) > > Shouldn't these innermost || be &&? D'oh, yes, what a dumb mistake. But that shows that we could also just always return true in a template ;). Fixed. dg.exp passed so far. -- >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 & evaluated to false/true. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/noexcept83.C: New test. --- gcc/cp/search.cc | 11 ++++++++ gcc/testsuite/g++.dg/cpp0x/noexcept83.C | 37 +++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept83.C base-commit: cd503b0616462445381a8232fb753239d319af76 diff --git a/gcc/cp/search.cc b/gcc/cp/search.cc index c948839dc53..827f48e8604 100644 --- a/gcc/cp/search.cc +++ b/gcc/cp/search.cc @@ -1975,6 +1975,17 @@ 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 & evaluate the noexcept to true/false. */ + if (processing_template_decl) + if ((base_throw + && base_throw != noexcept_true_spec + && base_throw != noexcept_false_spec) + || (over_throw + && over_throw != noexcept_true_spec + && over_throw != noexcept_false_spec)) + 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; +}