From: Jason Merrill Date: Mon, 2 Jun 2025 18:58:42 +0000 (-0400) Subject: c++: more __is_destructible fixes [PR107600] X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d287bff14885598c75c1cb16b08e0ba4ba05bce;p=thirdparty%2Fgcc.git c++: more __is_destructible fixes [PR107600] 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. --- diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc index bb6790f13cd..67a80a387ba 100644 --- a/gcc/cp/method.cc +++ b/gcc/cp/method.cc @@ -2332,13 +2332,22 @@ constructible_expr (tree to, tree from) return expr; } -/* Return declval().~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() is well-formed when treated as an + unevaluated operand ([expr.context]), where U is remove_all_extents_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)) { diff --git a/gcc/testsuite/g++.dg/ext/is_destructible2.C b/gcc/testsuite/g++.dg/ext/is_destructible2.C index 7f15fc78684..2edf440ef44 100644 --- a/gcc/testsuite/g++.dg/ext/is_destructible2.C +++ b/gcc/testsuite/g++.dg/ext/is_destructible2.C @@ -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]) );