diff options
| author | Martin Hořeňovský | 2026-04-27 20:50:51 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2026-04-27 20:50:51 +0200 |
| commit | 0cac51fbbf2496231b03721d95e4b05d18e36b29 (patch) | |
| tree | 72e4c63d723490e0f766966e4ad5f98545259ec9 | |
| parent | 11a96e186af8b2779d93e550217e9c95d3f89371 (diff) | |
| download | catch3-devel-use-delete-instead-of-static-assert-false.tar.gz | |
WIP: Use =delete instead of static_assert(always_false)devel-use-delete-instead-of-static-assert-false
| -rw-r--r-- | src/catch2/internal/catch_decomposer.hpp | 83 |
1 files 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 }; |