[clang] [Clang] Fix replaceability/relocatability computation (PR #145655)
Corentin Jabot via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 25 02:12:28 PDT 2025
https://github.com/cor3ntin created https://github.com/llvm/llvm-project/pull/145655
for eligible classes with user provided constructor or `operator=`
Fixes #144232
>From 543ee0c3cb6bf8c3e0d2b66ae145fadba6bd75b2 Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinjabot at gmail.com>
Date: Wed, 25 Jun 2025 11:08:39 +0200
Subject: [PATCH] [Clang] Fix replaceability/relocatability computation
for eligible classes with user provided constructor or `operator=`
Fixes #144232
---
clang/lib/Sema/SemaTypeTraits.cpp | 4 +--
.../SemaCXX/cxx2c-trivially-relocatable.cpp | 36 +++++++++++++++++++
2 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Sema/SemaTypeTraits.cpp b/clang/lib/Sema/SemaTypeTraits.cpp
index 4dbb2450857e0..354816a8e0805 100644
--- a/clang/lib/Sema/SemaTypeTraits.cpp
+++ b/clang/lib/Sema/SemaTypeTraits.cpp
@@ -121,7 +121,7 @@ static bool hasSuitableConstructorForRelocation(Sema &SemaRef,
CXXMethodDecl *Decl =
LookupSpecialMemberFromXValue(SemaRef, D, /*Assign=*/false);
- return Decl && Decl->isUserProvided() == AllowUserDefined &&
+ return Decl && (AllowUserDefined || !Decl->isUserProvided()) &&
!Decl->isDeleted();
}
@@ -137,7 +137,7 @@ static bool hasSuitableMoveAssignmentOperatorForRelocation(
if (!Decl)
return false;
- return Decl && Decl->isUserProvided() == AllowUserDefined &&
+ return Decl && (AllowUserDefined || !Decl->isUserProvided()) &&
!Decl->isDeleted();
}
diff --git a/clang/test/SemaCXX/cxx2c-trivially-relocatable.cpp b/clang/test/SemaCXX/cxx2c-trivially-relocatable.cpp
index 7152a5937d9b7..6f4003f525930 100644
--- a/clang/test/SemaCXX/cxx2c-trivially-relocatable.cpp
+++ b/clang/test/SemaCXX/cxx2c-trivially-relocatable.cpp
@@ -410,3 +410,39 @@ C& C::operator=(const C&) = default;
static_assert (!__builtin_is_cpp_trivially_relocatable(C));
static_assert (!__builtin_is_replaceable(C));
}
+
+namespace GH144232 {
+
+struct E trivially_relocatable_if_eligible replaceable_if_eligible {
+ E (E &&);
+ E &operator= (E &&) = default;
+};
+
+struct F trivially_relocatable_if_eligible replaceable_if_eligible {
+ F (F &&) = default;
+ F &operator= (F &&);
+};
+
+struct G trivially_relocatable_if_eligible replaceable_if_eligible { G (G const &) = default; };
+
+struct I trivially_relocatable_if_eligible replaceable_if_eligible { I &operator= (const I &) = default; };
+
+struct J trivially_relocatable_if_eligible replaceable_if_eligible { J (J const &); };
+struct K trivially_relocatable_if_eligible replaceable_if_eligible { K (K const &); };
+
+
+
+static_assert (__builtin_is_replaceable (E));
+static_assert (__builtin_is_cpp_trivially_relocatable(E));
+static_assert (__builtin_is_replaceable (F));
+static_assert (__builtin_is_cpp_trivially_relocatable(F));
+static_assert (__builtin_is_replaceable (G));
+static_assert (__builtin_is_cpp_trivially_relocatable(G));
+static_assert (__builtin_is_replaceable (I));
+static_assert (__builtin_is_cpp_trivially_relocatable(I));
+static_assert (__builtin_is_replaceable (J));
+static_assert (__builtin_is_cpp_trivially_relocatable(J));
+static_assert (__builtin_is_replaceable (K));
+static_assert (__builtin_is_cpp_trivially_relocatable(K));
+
+}
More information about the cfe-commits
mailing list