1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
8 #ifndef SUPPORT_TRACKED_VALUE_H
9 #define SUPPORT_TRACKED_VALUE_H
13 #include "test_macros.h"
16 enum State
{ CONSTRUCTED
, MOVED_FROM
, DESTROYED
};
19 TrackedValue() : state(State::CONSTRUCTED
) {}
21 TrackedValue(TrackedValue
const& t
) : state(State::CONSTRUCTED
) {
22 assert(t
.state
!= State::MOVED_FROM
&& "copying a moved-from object");
23 assert(t
.state
!= State::DESTROYED
&& "copying a destroyed object");
26 #if TEST_STD_VER >= 11
27 TrackedValue(TrackedValue
&& t
) : state(State::CONSTRUCTED
) {
28 assert(t
.state
!= State::MOVED_FROM
&& "double moving from an object");
29 assert(t
.state
!= State::DESTROYED
&& "moving from a destroyed object");
30 t
.state
= State::MOVED_FROM
;
34 TrackedValue
& operator=(TrackedValue
const& t
) {
35 assert(state
!= State::DESTROYED
&& "copy assigning into destroyed object");
36 assert(t
.state
!= State::MOVED_FROM
&& "copying a moved-from object");
37 assert(t
.state
!= State::DESTROYED
&& "copying a destroyed object");
42 #if TEST_STD_VER >= 11
43 TrackedValue
& operator=(TrackedValue
&& t
) {
44 assert(state
!= State::DESTROYED
&& "move assigning into destroyed object");
45 assert(t
.state
!= State::MOVED_FROM
&& "double moving from an object");
46 assert(t
.state
!= State::DESTROYED
&& "moving from a destroyed object");
48 t
.state
= State::MOVED_FROM
;
54 assert(state
!= State::DESTROYED
&& "double-destroying an object");
55 state
= State::DESTROYED
;
59 #endif // SUPPORT_TRACKED_VALUE_H