Static assertion for && and || expressions
diff --git a/include/internal/catch_expression_lhs.hpp b/include/internal/catch_expression_lhs.hpp
index 21cc593..f21c4ee 100644
--- a/include/internal/catch_expression_lhs.hpp
+++ b/include/internal/catch_expression_lhs.hpp
@@ -13,8 +13,6 @@
namespace Catch {
-struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
-
// Wraps the LHS of an expression and captures the operator and RHS (if any) - wrapping them all
// in an ExpressionResultBuilder object
template<typename T>
@@ -76,6 +74,8 @@
template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - ( RhsT const& );
template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator / ( RhsT const& );
template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator * ( RhsT const& );
+ template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( RhsT const& );
+ template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( RhsT const& );
private:
template<Internal::Operator Op, typename RhsT>
diff --git a/include/internal/catch_expressionresult_builder.h b/include/internal/catch_expressionresult_builder.h
index 5bf4137..1385588 100644
--- a/include/internal/catch_expressionresult_builder.h
+++ b/include/internal/catch_expressionresult_builder.h
@@ -16,6 +16,8 @@
namespace Catch {
+struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
+
// Wraps the (stringised versions of) the lhs, operator and rhs of an expression - as well as
// the result of evaluating it. This is used to build an AssertionResult object
class ExpressionResultBuilder {
@@ -43,6 +45,9 @@
AssertionResult buildResult( AssertionInfo const& info ) const;
+ template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( RhsT const& );
+ template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( RhsT const& );
+
private:
AssertionResultData m_data;
struct ExprComponents {
diff --git a/projects/SelfTest/TrickyTests.cpp b/projects/SelfTest/TrickyTests.cpp
index ec07f1f..9738670 100644
--- a/projects/SelfTest/TrickyTests.cpp
+++ b/projects/SelfTest/TrickyTests.cpp
@@ -33,9 +33,7 @@
{
std::pair<int, int> aNicePair( 1, 2 );
- // !TBD: would be nice if this could compile without the extra parentheses
- REQUIRE( (std::pair<int, int>( 1, 2 )) == aNicePair );
-
+ REQUIRE( (std::pair<int, int>( 1, 2 )) == aNicePair );
}
///////////////////////////////////////////////////////////////////////////////
@@ -45,13 +43,8 @@
"Where the is more to the expression after the RHS"
)
{
- /*
- int a = 1;
- int b = 2;
-
- // This only captures part of the expression, but issues a warning about the rest
- REQUIRE( a == 2 || b == 2 );
- */
+// int a = 1, b = 2;
+// REQUIRE( a == 2 || b == 2 );
WARN( "Uncomment the code in this test to check that it gives a sensible compiler error" );
}
///////////////////////////////////////////////////////////////////////////////