public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Marek Polacek <mpolacek@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-9047] c++: wrong looser excep spec for dep noexcept [PR113158]
Date: Sat, 17 Feb 2024 14:29:38 +0000 (GMT)	[thread overview]
Message-ID: <20240217142938.563913858D39@sourceware.org> (raw)

https://gcc.gnu.org/g:876fa432ef4074053fa65b1855e7d43320515576

commit r14-9047-g876fa432ef4074053fa65b1855e7d43320515576
Author: Marek Polacek <polacek@redhat.com>
Date:   Thu Feb 15 17:07:43 2024 -0500

    c++: wrong looser excep spec for dep noexcept [PR113158]
    
    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.

Diff:
---
 gcc/cp/search.cc                        | 11 ++++++++++
 gcc/testsuite/g++.dg/cpp0x/noexcept83.C | 37 +++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)

diff --git a/gcc/cp/search.cc b/gcc/cp/search.cc
index c948839dc533..827f48e8604f 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 000000000000..47832bbb44d3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/noexcept83.C
@@ -0,0 +1,37 @@
+// PR c++/113158
+// { dg-do compile { target c++11 } }
+
+template<typename T>
+struct V {
+  static constexpr bool t = false;
+};
+struct base {
+    virtual int f() = 0;
+};
+
+template<typename T>
+struct derived : base {
+    int f() noexcept(V<T>::t) override;
+};
+
+struct base2 {
+    virtual int f() noexcept = 0;
+};
+
+template<bool B>
+struct W {
+  static constexpr bool t = B;
+};
+
+template<bool B>
+struct derived2 : base2 {
+    int f() noexcept(W<B>::t) override; // { dg-error "looser exception specification" }
+};
+
+void
+g ()
+{
+  derived<int> d1;
+  derived2<false> d2; // { dg-message "required from here" }
+  derived2<true> d3;
+}

                 reply	other threads:[~2024-02-17 14:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240217142938.563913858D39@sourceware.org \
    --to=mpolacek@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).