@@ -176,12 +176,14 @@ public:
176176
177177 // Assignment [any.assign]
178178 any& operator=(const any& _That) {
179- _Assign(_That);
179+ any _Tmp = _That;
180+ _Reset_and_move_from(_Tmp);
180181 return *this;
181182 }
182183
183184 any& operator=(any&& _That) noexcept {
184- _Assign(_STD move(_That));
185+ any _Tmp = _STD move(_That);
186+ _Reset_and_move_from(_Tmp);
185187 return *this;
186188 }
187189
@@ -190,7 +192,8 @@ public:
190192 int> = 0>
191193 any& operator=(_ValueType&& _Value) {
192194 // replace contained value with an object of type decay_t<_ValueType> initialized from _Value
193- _Assign(_STD forward<_ValueType>(_Value));
195+ any _Tmp = _STD forward<_ValueType>(_Value);
196+ _Reset_and_move_from(_Tmp);
194197 return *this;
195198 }
196199
@@ -230,11 +233,9 @@ public:
230233 }
231234
232235 void swap(any& _That) noexcept {
233- any _Old = _STD move(*this);
234- reset();
235- _Move_from(_That);
236- _That.reset();
237- _That._Move_from(_Old);
236+ any _Tmp = _STD move(*this);
237+ _Reset_and_move_from(_That);
238+ _That._Reset_and_move_from(_Tmp);
238239 }
239240
240241 // Observers [any.observers]
@@ -288,6 +289,7 @@ private:
288289 }
289290
290291 void _Move_from(any& _That) noexcept {
292+ _STL_INTERNAL_CHECK(_Storage._TypeData == 0); // !has_value()
291293 _Storage._TypeData = _That._Storage._TypeData;
292294 switch (_Rep()) {
293295 case _Any_representation::_Small:
@@ -306,13 +308,14 @@ private:
306308 }
307309 }
308310
309- void _Assign (any _That) noexcept { // intentionally pass by value
311+ void _Reset_and_move_from (any& _That) noexcept {
310312 reset();
311313 _Move_from(_That);
312314 }
313315
314316 template <class _Decayed, class... _Types>
315317 _Decayed& _Emplace(_Types&&... _Args) { // emplace construct _Decayed
318+ _STL_INTERNAL_CHECK(_Storage._TypeData == 0); // !has_value()
316319 if constexpr (_Any_is_trivial<_Decayed>) {
317320 // using the _Trivial representation
318321 auto& _Obj = reinterpret_cast<_Decayed&>(_Storage._TrivialData);
0 commit comments