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

WIP: Use =delete instead of static_assert(always_false)

Commit
0cac51fbbf2496231b03721d95e4b05d18e36b29
Author
Martin Hořeňovský ·
Parents
11a96e186af8

Files · Download .tar.gz

Changes

 src/catch2/internal/catch_decomposer.hpp | 83 ++++++++++++--------------------
 1 file changed, 30 insertions(+), 53 deletions(-)

diff --git a/src/catch2/internal/catch_decomposer.hpp b/src/catch2/internal/catch_decomposer.hpp
index ff628482..c395630c 100644
--- a/src/catch2/internal/catch_decomposer.hpp
+++ b/src/catch2/internal/catch_decomposer.hpp
@@ -126,6 +126,12 @@
 #    endif
 #endif
 
+#    if defined( __cpp_deleted_function_with_reason )
+#    define CATCH_INTERNAL_DELETE( x ) delete (x)
+#else
+#    define CATCH_INTERNAL_DELETE( x ) delete
+#endif
+
 namespace Catch {
 
     namespace Detail {
@@ -160,9 +166,6 @@ namespace Catch {
     struct capture_by_value<std::partial_ordering> : std::true_type {};
 #endif
 
-    template <typename T>
-    struct always_false : std::false_type {};
-
     class ITransientExpression {
         bool m_isBinaryExpression;
         bool m_result;
@@ -211,61 +214,38 @@ namespace Catch {
             m_rhs( rhs )
         {}
 
+
         template<typename T>
-        auto operator && ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
-            static_assert(always_false<T>::value,
-            "chained comparisons are not supported inside assertions, "
-            "wrap the expression inside parentheses, or decompose it");
-        }
+        auto operator&&( T ) const -> BinaryExpr<LhsT, RhsT const&> const =
+            CATCH_INTERNAL_DELETE( "chained comparisons are not supported" );
 
         template<typename T>
-        auto operator || ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
-            static_assert(always_false<T>::value,
-            "chained comparisons are not supported inside assertions, "
-            "wrap the expression inside parentheses, or decompose it");
-        }
+        auto operator||( T ) const -> BinaryExpr<LhsT, RhsT const&> const =
+            CATCH_INTERNAL_DELETE( "chained comparisons are not supported" );
 
         template<typename T>
-        auto operator == ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
-            static_assert(always_false<T>::value,
-            "chained comparisons are not supported inside assertions, "
-            "wrap the expression inside parentheses, or decompose it");
-        }
+        auto operator==( T ) const -> BinaryExpr<LhsT, RhsT const&> const =
+            CATCH_INTERNAL_DELETE( "chained comparisons are not supported" );
 
         template<typename T>
-        auto operator != ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
-            static_assert(always_false<T>::value,
-            "chained comparisons are not supported inside assertions, "
-            "wrap the expression inside parentheses, or decompose it");
-        }
+        auto operator!=( T ) const -> BinaryExpr<LhsT, RhsT const&> const =
+            CATCH_INTERNAL_DELETE( "chained comparisons are not supported" );
 
         template<typename T>
-        auto operator > ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
-            static_assert(always_false<T>::value,
-            "chained comparisons are not supported inside assertions, "
-            "wrap the expression inside parentheses, or decompose it");
-        }
+        auto operator>( T ) const -> BinaryExpr<LhsT, RhsT const&> const =
+            CATCH_INTERNAL_DELETE( "chained comparisons are not supported" );
 
         template<typename T>
-        auto operator < ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
-            static_assert(always_false<T>::value,
-            "chained comparisons are not supported inside assertions, "
-            "wrap the expression inside parentheses, or decompose it");
-        }
+        auto operator<( T ) const -> BinaryExpr<LhsT, RhsT const&> const =
+            CATCH_INTERNAL_DELETE( "chained comparisons are not supported" );
 
         template<typename T>
-        auto operator >= ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
-            static_assert(always_false<T>::value,
-            "chained comparisons are not supported inside assertions, "
-            "wrap the expression inside parentheses, or decompose it");
-        }
+        auto operator>=( T ) const -> BinaryExpr<LhsT, RhsT const&> const =
+            CATCH_INTERNAL_DELETE( "chained comparisons are not supported" );
 
         template<typename T>
-        auto operator <= ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
-            static_assert(always_false<T>::value,
-            "chained comparisons are not supported inside assertions, "
-            "wrap the expression inside parentheses, or decompose it");
-        }
+        auto operator<=( T ) const -> BinaryExpr<LhsT, RhsT const&> const =
+            CATCH_INTERNAL_DELETE( "chained comparisons are not supported" );
     };
 
     template<typename LhsT>
@@ -419,19 +399,16 @@ namespace Catch {
 
     #undef CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR
 
+
         template<typename RhsT>
-        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");
-        }
+        friend auto operator&&( ExprLhs&&, RhsT&& )
+            -> BinaryExpr<LhsT, RhsT const&> = CATCH_INTERNAL_DELETE(
+                "'&&' is not supported inside assertions" );
 
         template<typename RhsT>
-        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");
-        }
+        friend auto operator||( ExprLhs&&, RhsT&& )
+            -> BinaryExpr<LhsT, RhsT const&> = CATCH_INTERNAL_DELETE(
+                "'||' is not supported inside assertions" );
 
         constexpr auto makeUnaryExpr() const -> UnaryExpr<LhsT> {
             return UnaryExpr<LhsT>{ m_lhs };