Commit ca295dff authored by Joe Loser's avatar Joe Loser Committed by Facebook Github Bot

Simplify suppressing self-move warning (#946)

Summary:
- A couple of tests pragma push/pop to avoid `-Wself-move` warning in
  code that does a move-assignment with itself.
- Use `static_cast<T&&>` instead of `std::move` which will suppress
  the warning still without the need for pragma push/pop.
Pull Request resolved: https://github.com/facebook/folly/pull/946

Reviewed By: Orvid

Differential Revision: D10253159

Pulled By: yfeldblum

fbshipit-source-id: 9d75db95018e6115a195f246dbd93b0a5935d80d
parent 57e90efd
......@@ -517,25 +517,16 @@ TEST(Expected, MakeOptional) {
EXPECT_EQ(**exIntPtr, 3);
}
#if __CLANG_PREREQ(3, 6)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wself-move"
#endif
TEST(Expected, SelfAssignment) {
Expected<std::string, E> a = "42";
a = static_cast<decltype(a)&>(a); // suppress self-assign warning
ASSERT_TRUE(a.hasValue() && a.value() == "42");
Expected<std::string, E> b = "23333333";
b = std::move(b);
b = static_cast<decltype(b)&&>(b); // suppress self-move warning
ASSERT_TRUE(b.hasValue() && b.value() == "23333333");
}
#if __CLANG_PREREQ(3, 6)
#pragma clang diagnostic pop
#endif
class ContainsExpected {
public:
ContainsExpected() {}
......@@ -641,13 +632,12 @@ struct NoSelfAssign {
#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 = static_cast<decltype(e)&>(e); // suppress self-assign warning
e = std::move(e); // @nolint
e = static_cast<decltype(e)&&>(e); // @nolint suppress self-move warning
}
#ifdef __GNUC__
......
......@@ -606,25 +606,16 @@ TEST(Optional, MakeOptional) {
EXPECT_EQ(**optIntPtr, 3);
}
#if __CLANG_PREREQ(3, 6)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wself-move"
#endif
TEST(Optional, SelfAssignment) {
Optional<int> a = 42;
a = static_cast<decltype(a)&>(a); // suppress self-assign warning
ASSERT_TRUE(a.hasValue() && a.value() == 42);
Optional<int> b = 23333333;
b = std::move(b);
b = static_cast<decltype(b)&&>(b); // suppress self-move warning
ASSERT_TRUE(b.hasValue() && b.value() == 23333333);
}
#if __CLANG_PREREQ(3, 6)
#pragma clang diagnostic pop
#endif
namespace {
class ContainsOptional {
......
......@@ -1101,7 +1101,7 @@ TEST(small_vector, SelfMoveAssignmentForVectorOfPair) {
test.emplace_back(13, 2);
EXPECT_EQ(test.size(), 1);
EXPECT_EQ(test[0].first, 13);
test = static_cast<decltype(test)&&>(test); // trick clang -Wself-move
test = static_cast<decltype(test)&&>(test); // suppress self-move warning
EXPECT_EQ(test.size(), 1);
EXPECT_EQ(test[0].first, 13);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment