diff --git a/hilti/runtime/include/types/reference.h b/hilti/runtime/include/types/reference.h index 461119ce8..6d17fafbe 100644 --- a/hilti/runtime/include/types/reference.h +++ b/hilti/runtime/include/types/reference.h @@ -261,13 +261,13 @@ class ValueReference { */ ValueReference& operator=(ValueReference&& other) noexcept { if ( &other != this ) { - // We can't move the actual value as other references may be - // referring to it. - *_get() = *other._get(); - - // Some implementations for `std::variant` do not have a `noexpect` - // move assignment operator. + // Not all types wrapped in a `ValueReference` might have a + // `noexcept` (move) assignment operator. try { + // We can't move the actual value as other references may be + // referring to it. + *_get() = *other._get(); + other._ptr = nullptr; } catch ( ... ) { cannot_be_reached();