any/meta_any: safe but unspecified state after self move - close #1206

Related Work Items: #1
This commit is contained in:
Michele Caini
2025-01-13 12:13:06 +01:00
parent 6f5e9351ed
commit 32fbc8a51f
4 changed files with 51 additions and 17 deletions

View File

@@ -249,12 +249,14 @@ public:
/**
* @brief Move assignment operator.
*
* @warning
* Self-moving puts objects in a safe but unspecified state.
*
* @param other The instance to move from.
* @return This any object.
*/
basic_any &operator=(basic_any &&other) noexcept {
ENTT_ASSERT(this != &other, "Self move assignment");
reset();
if(other.mode == any_policy::embedded) {

View File

@@ -357,13 +357,15 @@ public:
/**
* @brief Move assignment operator.
*
* @warning
* Self-moving puts objects in a safe but unspecified state.
*
* @param other The instance to move from.
* @return This meta any object.
*/
meta_any &operator=(meta_any &&other) noexcept {
ENTT_ASSERT(this != &other, "Self move assignment");
release();
reset();
storage = std::move(other.storage);
ctx = other.ctx;
node = std::exchange(other.node, internal::meta_type_node{});