Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Static assertion for && and || expressions

Commit
5d26ca1af7eba30eb74cb08d598d99829567d911
Author
Phil Nash ·
Parents
a9b346b14dc1

Files · Download .tar.gz

Changes

 include/internal/catch_expression_lhs.hpp         |  4 ++--
 include/internal/catch_expressionresult_builder.h |  5 +++++
 projects/SelfTest/TrickyTests.cpp                 | 13 +++----------
 3 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/include/internal/catch_expression_lhs.hpp b/include/internal/catch_expression_lhs.hpp
index 21cc593a..f21c4eec 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 @@ public:
     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 5bf41379..13855888 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 @@ public:
 
     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 ec07f1fc..97386709 100644
--- a/projects/SelfTest/TrickyTests.cpp
+++ b/projects/SelfTest/TrickyTests.cpp
@@ -33,9 +33,7 @@ TEST_CASE
 {
     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 @@ TEST_CASE
     "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" );
 }
 ///////////////////////////////////////////////////////////////////////////////