]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: more __is_destructible fixes [PR107600]
authorJason Merrill <jason@redhat.com>
Mon, 2 Jun 2025 18:58:42 +0000 (14:58 -0400)
committerJason Merrill <jason@redhat.com>
Mon, 2 Jun 2025 19:44:42 +0000 (15:44 -0400)
PR c++/107600

gcc/cp/ChangeLog:

* method.cc (destructible_expr): Fix refs and arrays of unknown
bound.

gcc/testsuite/ChangeLog:

* g++.dg/ext/is_destructible2.C: Add more cases.

gcc/cp/method.cc
gcc/testsuite/g++.dg/ext/is_destructible2.C

index bb6790f13cdb50deec5a7bd5d4dde3b2ea85c492..67a80a387ba71a55f7ed21eaec646fd0c0ec4051 100644 (file)
@@ -2332,13 +2332,22 @@ constructible_expr (tree to, tree from)
   return expr;
 }
 
-/* Return declval<T>().~T() treated as an unevaluated operand.  */
+/* Valid if "Either T is a reference type, or T is a complete object type for
+   which the expression declval<U&>().~U() is well-formed when treated as an
+   unevaluated operand ([expr.context]), where U is remove_all_extents_t<T>."
+
+   For a class U, return the destructor call; otherwise return void_node if
+   valid or error_mark_node if not.  */
 
 static tree
 destructible_expr (tree to)
 {
   cp_unevaluated cp_uneval_guard;
   int flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR;
+  if (TYPE_REF_P (to))
+    return void_node;
+  if (!COMPLETE_TYPE_P (complete_type (to)))
+    return error_mark_node;
   to = strip_array_types (to);
   if (CLASS_TYPE_P (to))
     {
index 7f15fc7868484ee6ff8a06279c691fc81c7d0585..2edf440ef44b37f97013f7950857535056f978c7 100644 (file)
@@ -13,3 +13,12 @@ static_assert( __is_assignable(A, A) );
 static_assert( not __is_destructible(int()) );
 static_assert( not __is_nothrow_destructible(int()) );
 static_assert( not __is_trivially_destructible(int()) );
+static_assert( __is_destructible(int&) );
+static_assert( __is_destructible(int&&) );
+static_assert( __is_destructible(int(&)[1]) );
+static_assert( __is_destructible(const int(&)[1]) );
+static_assert( __is_destructible(void(&)()) );
+static_assert( not __is_destructible(int[]) );
+static_assert( not __is_destructible(const int[]) );
+static_assert( not __is_destructible(int[][1]) );
+static_assert( not __is_destructible(const int[][1]) );