fix clang-tidy

This commit is contained in:
Sebastian Messmer 2018-12-25 19:50:53 +01:00
parent 621b000394
commit a86ac8241d
2 changed files with 36 additions and 36 deletions

View File

@ -27,18 +27,18 @@ namespace cpputils {
either(const either<Left, Right> &rhs) noexcept(noexcept(std::declval<either<Left, Right>>()._construct_left(rhs._left)) && noexcept(std::declval<either<Left, Right>>()._construct_right(rhs._right)))
: _side(rhs._side) {
if(_side == Side::left) {
_construct_left(rhs._left);
_construct_left(rhs._left); // NOLINT(cppcoreguidelines-pro-type-union-access)
} else {
_construct_right(rhs._right);
_construct_right(rhs._right); // NOLINT(cppcoreguidelines-pro-type-union-access)
}
}
either(either<Left, Right> &&rhs) /* TODO noexcept(noexcept(_construct_left(std::move(rhs._left))) && noexcept(_construct_right(std::move(rhs._right)))) */
: _side(rhs._side) {
if(_side == Side::left) {
_construct_left(std::move(rhs._left));
_construct_left(std::move(rhs._left)); // NOLINT(cppcoreguidelines-pro-type-union-access)
} else {
_construct_right(std::move(rhs._right));
_construct_right(std::move(rhs._right)); // NOLINT(cppcoreguidelines-pro-type-union-access)
}
}
@ -51,9 +51,9 @@ namespace cpputils {
_destruct();
_side = rhs._side;
if (_side == Side::left) {
_construct_left(rhs._left);
_construct_left(rhs._left); // NOLINT(cppcoreguidelines-pro-type-union-access)
} else {
_construct_right(rhs._right);
_construct_right(rhs._right); // NOLINT(cppcoreguidelines-pro-type-union-access)
}
return *this;
}
@ -62,9 +62,9 @@ namespace cpputils {
_destruct();
_side = rhs._side;
if (_side == Side::left) {
_construct_left(std::move(rhs._left));
_construct_left(std::move(rhs._left)); // NOLINT(cppcoreguidelines-pro-type-union-access)
} else {
_construct_right(std::move(rhs._right));
_construct_right(std::move(rhs._right)); // NOLINT(cppcoreguidelines-pro-type-union-access)
}
return *this;
}
@ -83,7 +83,7 @@ namespace cpputils {
if (!is_left()) {
throw std::logic_error("Tried to get left side of an either which is right.");
}
return _left;
return _left; // NOLINT(cppcoreguidelines-pro-type-union-access)
}
Left &left() & {
return const_cast<Left&>(const_cast<const either<Left, Right>*>(this)->left());
@ -96,7 +96,7 @@ namespace cpputils {
if (!is_right()) {
throw std::logic_error("Tried to get right side of an either which is left.");
}
return _right;
return _right; // NOLINT(cppcoreguidelines-pro-type-union-access)
}
Right &right() & {
return const_cast<Right&>(const_cast<const either<Left, Right>*>(this)->right());
@ -107,14 +107,14 @@ namespace cpputils {
boost::optional<const Left&> left_opt() const& noexcept {
if (_side == Side::left) {
return _left;
return _left; // NOLINT(cppcoreguidelines-pro-type-union-access)
} else {
return boost::none;
}
}
boost::optional<Left&> left_opt() & noexcept {
if (_side == Side::left) {
return _left;
return _left; // NOLINT(cppcoreguidelines-pro-type-union-access)
} else {
return boost::none;
}
@ -123,14 +123,14 @@ namespace cpputils {
boost::optional<const Right&> right_opt() const& noexcept {
if (_side == Side::right) {
return _right;
return _right; // NOLINT(cppcoreguidelines-pro-type-union-access)
} else {
return boost::none;
}
}
boost::optional<Right&> right_opt() & noexcept {
if (_side == Side::right) {
return _right;
return _right; // NOLINT(cppcoreguidelines-pro-type-union-access)
} else {
return boost::none;
}
@ -148,17 +148,17 @@ namespace cpputils {
template<typename... Args>
void _construct_left(Args&&... args) noexcept(noexcept(new Left(std::forward<Args>(args)...))) {
new(&_left)Left(std::forward<Args>(args)...);
new(&_left)Left(std::forward<Args>(args)...); // NOLINT(cppcoreguidelines-pro-type-union-access)
}
template<typename... Args>
void _construct_right(Args&&... args) noexcept(noexcept(new Right(std::forward<Args>(args)...))) {
new(&_right)Right(std::forward<Args>(args)...);
new(&_right)Right(std::forward<Args>(args)...); // NOLINT(cppcoreguidelines-pro-type-union-access)
}
void _destruct() noexcept {
if (_side == Side::left) {
_left.~Left();
_left.~Left(); // NOLINT(cppcoreguidelines-pro-type-union-access)
} else {
_right.~Right();
_right.~Right(); // NOLINT(cppcoreguidelines-pro-type-union-access)
}
}

View File

@ -345,7 +345,7 @@ TEST(EitherTest, givenLeftMoveConstructedFromValue_thenOldIsCorrect) {
[] (const auto& test) {
MovableOnly a(3);
either<MovableOnly, int> b(std::move(a));
test(a);
test(a); // NOLINT(bugprone-use-after-move)
}
},
EXPECT_IS<MovableOnly>(MovableOnly(0)) // 0 is moved-from value
@ -369,7 +369,7 @@ TEST(EitherTest, givenRightMoveConstructedFromValue_thenOldIsCorrect) {
[] (const auto& test) {
MovableOnly a(3);
either<int, MovableOnly> b(std::move(a));
test(a);
test(a); // NOLINT(bugprone-use-after-move)
}
},
EXPECT_IS<MovableOnly>(MovableOnly(0)) // 0 is moved-from value
@ -472,12 +472,12 @@ TEST(EitherTest, givenLeftMoveAssignedFromValue_thenOldIsCorrect) {
MovableOnly a(3);
either<MovableOnly, string> b("2");
b = std::move(a);
test(a);
test(a); // NOLINT(bugprone-use-after-move)
}, [] (const auto& test) {
MovableOnly a(3);
either<MovableOnly, string> b(MovableOnly(0));
b = std::move(a);
test(a);
test(a); // NOLINT(bugprone-use-after-move)
}
},
EXPECT_IS<MovableOnly>(MovableOnly(0))
@ -508,12 +508,12 @@ TEST(EitherTest, givenRightMoveAssignedFromValue_thenOldIsCorrect) {
MovableOnly a(3);
either<string, MovableOnly> b("2");
b = std::move(a);
test(a);
test(a); // NOLINT(bugprone-use-after-move)
}, [] (const auto& test) {
MovableOnly a(3);
either<string, MovableOnly> b(MovableOnly(2));
b = std::move(a);
test(a);
test(a); // NOLINT(bugprone-use-after-move)
}
},
EXPECT_IS<MovableOnly>(MovableOnly(0)) // 0 is moved-from value
@ -635,7 +635,7 @@ TEST(EitherTest, givenLeftMoveConstructed_thenOldIsCorrect) {
[] (const auto& test) {
either<MovableOnly, int> a(MovableOnly(3));
either<MovableOnly, int> b(std::move(a));
test(a);
test(a); // NOLINT(bugprone-use-after-move)
}
},
EXPECT_IS_LEFT<MovableOnly, int>(MovableOnly(0)) // 0 is moved-from value
@ -659,7 +659,7 @@ TEST(EitherTest, givenLeftMoveConstructed_withSameType_thenOldIsCorrect) {
[] (const auto& test) {
either<MovableOnly, MovableOnly> a = make_left<MovableOnly, MovableOnly>(MovableOnly(3));
either<MovableOnly, MovableOnly> b(std::move(a));
test(a);
test(a); // NOLINT(bugprone-use-after-move)
}
},
EXPECT_IS_LEFT<MovableOnly, MovableOnly>(MovableOnly(0)) // 0 is moved-from value
@ -683,7 +683,7 @@ TEST(EitherTest, givenRightMoveConstructed_thenOldIsCorrect) {
[] (const auto& test) {
either<int, MovableOnly> a(MovableOnly(3));
either<int, MovableOnly> b(std::move(a));
test(a);
test(a); // NOLINT(bugprone-use-after-move)
}
},
EXPECT_IS_RIGHT<int, MovableOnly>(MovableOnly(0)) // 0 is moved-from value
@ -707,7 +707,7 @@ TEST(EitherTest, givenRightMoveConstructed_withSameType_thenOldIsCorrect) {
[] (const auto& test) {
either<MovableOnly, MovableOnly> a = make_right<MovableOnly, MovableOnly>(MovableOnly(3));
either<MovableOnly, MovableOnly> b(std::move(a));
test(a);
test(a); // NOLINT(bugprone-use-after-move)
}
},
EXPECT_IS_RIGHT<MovableOnly, MovableOnly>(MovableOnly(0)) // 0 is moved-from value
@ -882,12 +882,12 @@ TEST(EitherTest, givenLeftMoveAssigned_thenOldIsCorrect) {
either<MovableOnly, string> a(MovableOnly(3));
either<MovableOnly, string> b(2);
b = std::move(a);
test(a);
test(a); // NOLINT(bugprone-use-after-move)
}, [] (const auto& test) {
either<MovableOnly, string> a(MovableOnly(3));
either<MovableOnly, string> b(MovableOnly(2));
b = std::move(a);
test(a);
test(a); // NOLINT(bugprone-use-after-move)
}
},
EXPECT_IS_LEFT<MovableOnly, string>(MovableOnly(0)) // 0 is moved-from value
@ -918,12 +918,12 @@ TEST(EitherTest, givenLeftMoveAssigned_withSameType_thenOldIsCorrect) {
either<MovableOnly, MovableOnly> a = make_left<MovableOnly, MovableOnly>(3);
either<MovableOnly, MovableOnly> b = make_right<MovableOnly, MovableOnly>(2);
b = std::move(a);
test(a);
test(a); // NOLINT(bugprone-use-after-move)
}, [] (const auto& test) {
either<MovableOnly, MovableOnly> a = make_left<MovableOnly, MovableOnly>(3);
either<MovableOnly, MovableOnly> b = make_left<MovableOnly, MovableOnly>(2);
b = std::move(a);
test(a);
test(a); // NOLINT(bugprone-use-after-move)
}
},
EXPECT_IS_LEFT<MovableOnly, MovableOnly>(MovableOnly(0)) // 0 is moved-from value
@ -954,12 +954,12 @@ TEST(EitherTest, givenRightMoveAssigned_thenOldIsCorrect) {
either<string, MovableOnly> a(MovableOnly(3));
either<string, MovableOnly> b("2");
b = std::move(a);
test(a);
test(a); // NOLINT(bugprone-use-after-move)
}, [] (const auto& test) {
either<string, MovableOnly> a(MovableOnly(3));
either<string, MovableOnly> b(MovableOnly(2));
b = std::move(a);
test(a);
test(a); // NOLINT(bugprone-use-after-move)
}
},
EXPECT_IS_RIGHT<string, MovableOnly>(MovableOnly(0)) // 0 is moved-from value
@ -990,12 +990,12 @@ TEST(EitherTest, givenRightMoveAssigned_withSameType_thenOldIsCorrect) {
either<MovableOnly, MovableOnly> a = make_right<MovableOnly, MovableOnly>(3);
either<MovableOnly, MovableOnly> b = make_left<MovableOnly, MovableOnly>(2);
b = std::move(a);
test(a);
test(a); // NOLINT(bugprone-use-after-move)
}, [] (const auto& test) {
either<MovableOnly, MovableOnly> a = make_right<MovableOnly, MovableOnly>(3);
either<MovableOnly, MovableOnly> b = make_right<MovableOnly, MovableOnly>(2);
b = std::move(a);
test(a);
test(a); // NOLINT(bugprone-use-after-move)
}
},
EXPECT_IS_RIGHT<MovableOnly, MovableOnly>(MovableOnly(0)) // 0 is moved-from value