Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorAlCash072020-12-19 15:36:19 -0800
committerMartin Hořeňovský2021-06-08 23:36:06 +0200
commitc77ba5314a82b468f9591b7ec7e90ada67a7c664 (patch)
tree534aadbc889602721da2c80dd26e7e179f99e642 /src
parent65c9a1d31a338f28ef93cd61c475efc40f6cc42e (diff)
downloadcatch3-c77ba5314a82b468f9591b7ec7e90ada67a7c664.tar.gz
Fix decomposing in presence of universal ADL-found operators
Closes #2121
Diffstat (limited to 'src')
-rw-r--r--src/catch2/internal/catch_decomposer.hpp89
1 files changed, 38 insertions, 51 deletions
diff --git a/src/catch2/internal/catch_decomposer.hpp b/src/catch2/internal/catch_decomposer.hpp
index 9af5c19f..a747c34c 100644
--- a/src/catch2/internal/catch_decomposer.hpp
+++ b/src/catch2/internal/catch_decomposer.hpp
@@ -183,60 +183,53 @@ namespace Catch {
public:
explicit ExprLhs( LhsT lhs ) : m_lhs( lhs ) {}
- template<typename RhsT>
- auto operator == ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
- return { compareEqual( m_lhs, rhs ), m_lhs, "=="_sr, rhs };
+ template<typename RhsT, std::enable_if_t<!std::is_arithmetic<std::remove_reference_t<RhsT>>::value, int> = 0>
+ friend auto operator == ( ExprLhs && lhs, RhsT && rhs ) -> BinaryExpr<LhsT, RhsT const&> {
+ return { compareEqual( lhs.m_lhs, rhs ), lhs.m_lhs, "=="_sr, rhs };
}
- auto operator == ( bool rhs ) -> BinaryExpr<LhsT, bool> const {
- return { m_lhs == rhs, m_lhs, "=="_sr, rhs };
+ template<typename RhsT, std::enable_if_t<std::is_arithmetic<RhsT>::value, int> = 0>
+ friend auto operator == ( ExprLhs && lhs, RhsT rhs ) -> BinaryExpr<LhsT, RhsT> {
+ return { compareEqual( lhs.m_lhs, rhs ), lhs.m_lhs, "=="_sr, rhs };
}
- template<typename RhsT>
- auto operator != ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
- return { compareNotEqual( m_lhs, rhs ), m_lhs, "!="_sr, rhs };
+ template<typename RhsT, std::enable_if_t<!std::is_arithmetic<std::remove_reference_t<RhsT>>::value, int> = 0>
+ friend auto operator != ( ExprLhs && lhs, RhsT && rhs ) -> BinaryExpr<LhsT, RhsT const&> {
+ return { compareNotEqual( lhs.m_lhs, rhs ), lhs.m_lhs, "!="_sr, rhs };
}
- auto operator != ( bool rhs ) -> BinaryExpr<LhsT, bool> const {
- return { m_lhs != rhs, m_lhs, "!="_sr, rhs };
+ template<typename RhsT, std::enable_if_t<std::is_arithmetic<RhsT>::value, int> = 0>
+ friend auto operator != ( ExprLhs && lhs, RhsT rhs ) -> BinaryExpr<LhsT, RhsT> {
+ return { compareNotEqual( lhs.m_lhs, rhs ), lhs.m_lhs, "!="_sr, rhs };
}
- template<typename RhsT>
- auto operator > ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
- return { static_cast<bool>(m_lhs > rhs), m_lhs, ">"_sr, rhs };
- }
- template<typename RhsT>
- auto operator < ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
- return { static_cast<bool>(m_lhs < rhs), m_lhs, "<"_sr, rhs };
- }
- template<typename RhsT>
- auto operator >= ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
- return { static_cast<bool>(m_lhs >= rhs), m_lhs, ">="_sr, rhs };
- }
- template<typename RhsT>
- auto operator <= ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
- return { static_cast<bool>(m_lhs <= rhs), m_lhs, "<="_sr, rhs };
- }
- template <typename RhsT>
- auto operator | (RhsT const& rhs) -> BinaryExpr<LhsT, RhsT const&> const {
- return { static_cast<bool>(m_lhs | rhs), m_lhs, "|"_sr, rhs };
- }
- template <typename RhsT>
- auto operator & (RhsT const& rhs) -> BinaryExpr<LhsT, RhsT const&> const {
- return { static_cast<bool>(m_lhs & rhs), m_lhs, "&"_sr, rhs };
- }
- template <typename RhsT>
- auto operator ^ (RhsT const& rhs) -> BinaryExpr<LhsT, RhsT const&> const {
- return { static_cast<bool>(m_lhs ^ rhs), m_lhs, "^"_sr, rhs };
+ #define CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR(op) \
+ template<typename RhsT, std::enable_if_t<!std::is_arithmetic<std::remove_reference_t<RhsT>>::value, int> = 0> \
+ friend auto operator op ( ExprLhs && lhs, RhsT && rhs ) -> BinaryExpr<LhsT, RhsT const&> { \
+ return { static_cast<bool>(lhs.m_lhs op rhs), lhs.m_lhs, #op##_sr, rhs }; \
+ } \
+ template<typename RhsT, std::enable_if_t<std::is_arithmetic<RhsT>::value, int> = 0> \
+ friend auto operator op ( ExprLhs && lhs, RhsT rhs ) -> BinaryExpr<LhsT, RhsT> { \
+ return { static_cast<bool>(lhs.m_lhs op rhs), lhs.m_lhs, #op##_sr, rhs }; \
}
+ CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR(<)
+ CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR(>)
+ CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR(<=)
+ CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR(>=)
+ CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR(|)
+ CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR(&)
+ CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR(^)
+
+ #undef CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR
+
template<typename RhsT>
- auto operator && ( RhsT const& ) -> BinaryExpr<LhsT, RhsT const&> const {
+ friend auto operator && ( ExprLhs &&, RhsT && ) -> BinaryExpr<LhsT, RhsT const&> {
static_assert(always_false<RhsT>::value,
"operator&& is not supported inside assertions, "
"wrap the expression inside parentheses, or decompose it");
}
template<typename RhsT>
- auto operator || ( RhsT const& ) -> BinaryExpr<LhsT, RhsT const&> const {
+ friend auto operator || ( ExprLhs &&, RhsT && ) -> BinaryExpr<LhsT, RhsT const&> {
static_assert(always_false<RhsT>::value,
"operator|| is not supported inside assertions, "
"wrap the expression inside parentheses, or decompose it");
@@ -247,21 +240,15 @@ namespace Catch {
}
};
- void handleExpression( ITransientExpression const& expr );
-
- template<typename T>
- void handleExpression( ExprLhs<T> const& expr ) {
- handleExpression( expr.makeUnaryExpr() );
- }
-
struct Decomposer {
- template<typename T>
- auto operator <= ( T const& lhs ) -> ExprLhs<T const&> {
- return ExprLhs<T const&>{ lhs };
+ template<typename T, std::enable_if_t<!std::is_arithmetic<std::remove_reference_t<T>>::value, int> = 0>
+ friend auto operator <= ( Decomposer &&, T && lhs ) -> ExprLhs<T const&> {
+ return ExprLhs<const T&>{ lhs };
}
- auto operator <=( bool value ) -> ExprLhs<bool> {
- return ExprLhs<bool>{ value };
+ template<typename T, std::enable_if_t<std::is_arithmetic<T>::value, int> = 0>
+ friend auto operator <= ( Decomposer &&, T value ) -> ExprLhs<T> {
+ return ExprLhs<T>{ value };
}
};