/*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
#include <folly/Expected.h>
-#include <folly/Portability.h>
+#include <folly/portability/GTest.h>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <glog/logging.h>
-#include <gtest/gtest.h>
using std::unique_ptr;
using std::shared_ptr;
static_assert(
std::is_default_constructible<Expected<NoDefault, int>>::value, "");
Expected<NoDefault, int> x{in_place, 42, 42};
- EXPECT_TRUE(x);
+ EXPECT_TRUE(bool(x));
x.emplace(4, 5);
EXPECT_TRUE(bool(x));
x = makeUnexpected(42);
- EXPECT_FALSE(x);
+ EXPECT_FALSE(bool(x));
EXPECT_EQ(42, x.error());
}
TEST(Expected, String) {
Expected<std::string, int> maybeString;
- EXPECT_FALSE(maybeString);
+ EXPECT_FALSE(bool(maybeString));
EXPECT_EQ(0, maybeString.error());
maybeString = "hello";
EXPECT_TRUE(bool(maybeString));
EXPECT_EQ(**exIntPtr, 3);
}
-#if __CLANG_PREREQ(3, 6)
+#if __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wself-move"
#endif
ASSERT_TRUE(b.hasValue() && b.value() == "23333333");
}
-#if __CLANG_PREREQ(3, 6)
+#if __clang__
#pragma clang diagnostic pop
#endif
(std::is_nothrow_move_assignable<Expected<ThrowingBadness, E>>::value));
}
+struct NoSelfAssign {
+ NoSelfAssign() = default;
+ NoSelfAssign(NoSelfAssign&&) = default;
+ NoSelfAssign(const NoSelfAssign&) = default;
+ NoSelfAssign& operator=(NoSelfAssign&& that) {
+ EXPECT_NE(this, &that);
+ return *this;
+ }
+ NoSelfAssign& operator=(const NoSelfAssign& that) {
+ EXPECT_NE(this, &that);
+ return *this;
+ }
+};
+
+#ifdef __GNUC__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wpragmas"
+#pragma GCC diagnostic ignored "-Wself-move"
+#endif
+
+TEST(Expected, NoSelfAssign) {
+ folly::Expected<NoSelfAssign, int> e {NoSelfAssign{}};
+ e = e; // @nolint
+ e = std::move(e); // @nolint
+}
+
+#ifdef __GNUC__
+#pragma GCC diagnostic pop
+#endif
+
struct NoDestructor {};
struct WithDestructor {