]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: wrong looser excep spec for dep noexcept [PR113158]
authorMarek Polacek <polacek@redhat.com>
Thu, 15 Feb 2024 22:07:43 +0000 (17:07 -0500)
committerMarek Polacek <polacek@redhat.com>
Sat, 17 Feb 2024 14:29:02 +0000 (09:29 -0500)
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
gcc/testsuite/g++.dg/cpp0x/noexcept83.C [new file with mode: 0644]

index c948839dc5337b4d564531dc19641259c5cb664c..827f48e8604f6b8f6acb0461fcc521a4602b5756 100644 (file)
@@ -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 (file)
index 0000000..47832bb
--- /dev/null
@@ -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;
+}