]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: __has_trivial_destructor regression
authorJason Merrill <jason@redhat.com>
Mon, 2 Jun 2025 12:36:22 +0000 (08:36 -0400)
committerJason Merrill <jason@redhat.com>
Mon, 2 Jun 2025 15:28:23 +0000 (11:28 -0400)
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.

gcc/cp/semantics.cc
gcc/testsuite/g++.dg/ext/has_trivial_destructor-3.C [new file with mode: 0644]

index 6551ca919286cc918787349495c76b7501b1eddf..7bc346b0f294a36b5456a88f7c01890079e6ea49 100644 (file)
@@ -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 (file)
index 0000000..a179be5
--- /dev/null
@@ -0,0 +1,21 @@
+// { dg-do compile { target c++11 } }
+
+struct X;
+
+template<class T>
+struct default_delete
+{
+  void operator()(T*) { static_assert(sizeof(T), "type is not incomplete"); }
+};
+
+template<class T, class D = default_delete<T>>
+struct unique_ptr
+{
+  ~unique_ptr() { del(ptr); }
+
+  T* ptr;
+  D del;
+};
+
+
+constexpr bool b = __has_trivial_destructor(unique_ptr<X>);