[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / support / tracked_value.h
blob01b8c840d19bb99119ee18dfca72e237d94ee480
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 #ifndef SUPPORT_TRACKED_VALUE_H
9 #define SUPPORT_TRACKED_VALUE_H
11 #include <cassert>
13 #include "test_macros.h"
15 struct TrackedValue {
16 enum State { CONSTRUCTED, MOVED_FROM, DESTROYED };
17 State state;
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;
32 #endif
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");
38 state = t.state;
39 return *this;
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");
47 state = t.state;
48 t.state = State::MOVED_FROM;
49 return *this;
51 #endif
53 ~TrackedValue() {
54 assert(state != State::DESTROYED && "double-destroying an object");
55 state = State::DESTROYED;
59 #endif // SUPPORT_TRACKED_VALUE_H