/*
- * 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;
(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 {
// Error case:
Expected<int, E> ex = Expected<std::unique_ptr<int>, E>{
unexpected, E::E1}.then([](std::unique_ptr<int> p) -> int {
- EXPECT_TRUE(false);
+ ADD_FAILURE();
return *p;
});
EXPECT_FALSE(bool(ex));