[libcxx] r231674 - Add TrackedValue to test/support. Thanks to Louis Dionne
Eric Fiselier
eric at efcs.ca
Mon Mar 9 11:02:16 PDT 2015
Author: ericwf
Date: Mon Mar 9 13:02:16 2015
New Revision: 231674
URL: http://llvm.org/viewvc/llvm-project?rev=231674&view=rev
Log:
Add TrackedValue to test/support. Thanks to Louis Dionne
Added:
libcxx/trunk/test/support/tracked_value.h
Added: libcxx/trunk/test/support/tracked_value.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/tracked_value.h?rev=231674&view=auto
==============================================================================
--- libcxx/trunk/test/support/tracked_value.h (added)
+++ libcxx/trunk/test/support/tracked_value.h Mon Mar 9 13:02:16 2015
@@ -0,0 +1,50 @@
+#ifndef SUPPORT_TRACKED_VALUE_H
+#define SUPPORT_TRACKED_VALUE_H
+
+#include <cassert>
+
+struct TrackedValue {
+ enum State { CONSTRUCTED, MOVED_FROM, DESTROYED };
+ State state;
+
+ TrackedValue() : state(State::CONSTRUCTED) {}
+
+ TrackedValue(TrackedValue const& t) : state(State::CONSTRUCTED) {
+ assert(t.state != State::MOVED_FROM && "copying a moved-from object");
+ assert(t.state != State::DESTROYED && "copying a destroyed object");
+ }
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ TrackedValue(TrackedValue&& t) : state(State::CONSTRUCTED) {
+ assert(t.state != State::MOVED_FROM && "double moving from an object");
+ assert(t.state != State::DESTROYED && "moving from a destroyed object");
+ t.state = State::MOVED_FROM;
+ }
+#endif
+
+ TrackedValue& operator=(TrackedValue const& t) {
+ assert(state != State::DESTROYED && "copy assigning into destroyed object");
+ assert(t.state != State::MOVED_FROM && "copying a moved-from object");
+ assert(t.state != State::DESTROYED && "copying a destroyed object");
+ state = t.state;
+ return *this;
+ }
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ TrackedValue& operator=(TrackedValue&& t) {
+ assert(state != State::DESTROYED && "move assigning into destroyed object");
+ assert(t.state != State::MOVED_FROM && "double moving from an object");
+ assert(t.state != State::DESTROYED && "moving from a destroyed object");
+ state = t.state;
+ t.state = State::MOVED_FROM;
+ return *this;
+ }
+#endif
+
+ ~TrackedValue() {
+ assert(state != State::DESTROYED && "double-destroying an object");
+ state = State::DESTROYED;
+ }
+};
+
+#endif // SUPPORT_TRACKED_VALUE_H
More information about the cfe-commits
mailing list