]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Fix diagnostics for __is_destructable
authorNathaniel Shead <nathanieloshead@gmail.com>
Thu, 23 Oct 2025 06:10:04 +0000 (17:10 +1100)
committerNathaniel Shead <nathanieloshead@gmail.com>
Sat, 22 Nov 2025 23:45:11 +0000 (10:45 +1100)
We'd missed providing a diagnostic when checking a non-scalar non-class
type, such as a function type.

gcc/cp/ChangeLog:

* method.cc (destructible_expr): Add explanation when type is
neither class nor scalar.

gcc/testsuite/ChangeLog:

* g++.dg/ext/is_destructible3.C: Add test for function type.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/method.cc
gcc/testsuite/g++.dg/ext/is_destructible3.C

index ef8370fac5b3d61d3fd4231bf5ee97e8362cbe43..bc721a5d7e3f8995aefdea1a08702b0176585187 100644 (file)
@@ -2410,7 +2410,11 @@ destructible_expr (tree to, bool explain)
   else if (scalarish_type_p (to))
     return void_node;
   else
-    return error_mark_node;
+    {
+      if (explain)
+       error_at (location_of (to), "%qT is not a class or scalar type", to);
+      return error_mark_node;
+    }
 }
 
 /* Returns a tree iff TO is assignable (if CODE is MODIFY_EXPR) or
index a8501d637ab7aefeade1fd8a59346480dd4d0126..5d3c92954daa29e7b234b77b07e93a16b0eb5349 100644 (file)
@@ -9,6 +9,10 @@ static_assert(is_destructible<void>::value, "");  // { dg-error "assert" }
 // { dg-message "'void' is not destructible, because" "" { target *-*-* } .-1 }
 // { dg-error "'void' is incomplete" "" { target *-*-* } .-2 }
 
+static_assert(is_destructible<void() volatile>::value, "");  // { dg-error "assert" }
+// { dg-message "'void\\(\\) volatile' is not destructible, because" "" { target *-*-* } .-1 }
+// { dg-error "not a class or scalar type" "" { target *-*-* } .-2 }
+
 struct A {
   ~A() = delete;  // { dg-message "declared here" }
 };