From: Jason Merrill Date: Mon, 2 Jun 2025 12:36:22 +0000 (-0400) Subject: c++: __has_trivial_destructor regression X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a42538f9693a6608bb733860adec75a691f1940;p=thirdparty%2Fgcc.git c++: __has_trivial_destructor regression We don't want the new call to get_dtor to cause function instantiation. PR c++/107600 gcc/cp/ChangeLog: * semantics.cc (trait_expr_value) [CPTK_HAS_TRIVIAL_DESTRUCTOR]: Add cp_unevaluated. gcc/testsuite/ChangeLog: * g++.dg/ext/has_trivial_destructor-3.C: New test. --- diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 6551ca91928..7bc346b0f29 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -13419,6 +13419,7 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) if (CLASS_TYPE_P (type1) && type_build_dtor_call (type1)) { deferring_access_check_sentinel dacs (dk_no_check); + cp_unevaluated un; tree fn = get_dtor (type1, tf_none); if (!fn && !seen_error ()) warning (0, "checking %qs for type %qT with a destructor that " diff --git a/gcc/testsuite/g++.dg/ext/has_trivial_destructor-3.C b/gcc/testsuite/g++.dg/ext/has_trivial_destructor-3.C new file mode 100644 index 00000000000..a179be52e93 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/has_trivial_destructor-3.C @@ -0,0 +1,21 @@ +// { dg-do compile { target c++11 } } + +struct X; + +template +struct default_delete +{ + void operator()(T*) { static_assert(sizeof(T), "type is not incomplete"); } +}; + +template> +struct unique_ptr +{ + ~unique_ptr() { del(ptr); } + + T* ptr; + D del; +}; + + +constexpr bool b = __has_trivial_destructor(unique_ptr);