Revert "Fix old GCC + types with ambiguous constructor from 0"

This reverts commit 291c502f66.

The issue is that it breaks under C++20 for some reason.
This commit is contained in:
Martin Hořeňovský 2022-11-22 15:23:03 +01:00
parent 291c502f66
commit a20200be7e
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
2 changed files with 51 additions and 78 deletions

View File

@ -13,7 +13,6 @@
#include <catch2/internal/catch_meta.hpp> #include <catch2/internal/catch_meta.hpp>
#include <catch2/internal/catch_compare_traits.hpp> #include <catch2/internal/catch_compare_traits.hpp>
#include <catch2/internal/catch_test_failure_exception.hpp> #include <catch2/internal/catch_test_failure_exception.hpp>
#include <catch2/internal/catch_logical_traits.hpp>
#include <type_traits> #include <type_traits>
#include <iosfwd> #include <iosfwd>
@ -169,19 +168,18 @@ namespace Catch {
template < \ template < \
typename RhsT, \ typename RhsT, \
std::enable_if_t< \ std::enable_if_t< \
Detail::conjunction<Detail::is_##id##_comparable<LhsT, RhsT>, \ Detail::is_##id##_comparable<LhsT, RhsT>::value && \
Detail::negation<std::is_arithmetic< \ !std::is_arithmetic<std::remove_reference_t<RhsT>>::value, \
std::remove_reference_t<RhsT>>>>::value, \
int> = 0> \ int> = 0> \
friend auto operator op( ExprLhs&& lhs, RhsT&& rhs ) \ friend auto operator op( ExprLhs&& lhs, RhsT&& rhs ) \
->BinaryExpr<LhsT, RhsT const&> { \ ->BinaryExpr<LhsT, RhsT const&> { \
return { \ return { \
static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op##_sr, rhs }; \ static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op##_sr, rhs }; \
} \ } \
template <typename RhsT, \ template < \
std::enable_if_t<Detail::conjunction< \ typename RhsT, \
Detail::is_##id##_comparable<LhsT, RhsT>, \ std::enable_if_t<Detail::is_##id##_comparable<LhsT, RhsT>::value && \
std::is_arithmetic<RhsT>>::value, \ std::is_arithmetic<RhsT>::value, \
int> = 0> \ int> = 0> \
friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \ friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
->BinaryExpr<LhsT, RhsT> { \ ->BinaryExpr<LhsT, RhsT> { \
@ -190,33 +188,35 @@ namespace Catch {
} \ } \
template < \ template < \
typename RhsT, \ typename RhsT, \
std::enable_if_t< \ std::enable_if_t<!Detail::is_##id##_comparable<LhsT, RhsT>::value && \
Detail::conjunction< \ Detail::is_eq_0_comparable<LhsT>:: \
Detail::negation<Detail::is_##id##_comparable<LhsT, RhsT>>, \ value && /* We allow long because we want \
Detail::is_eq_0_comparable<LhsT>, \ `ptr op NULL to be accepted */ \
Detail::disjunction<std::is_same<RhsT, int>, \ ( std::is_same<RhsT, int>::value || \
/* On some platforms `NULL` is a long */ \ std::is_same<RhsT, long>::value ), \
std::is_same<RhsT, long>>>::value, \
int> = 0> \ int> = 0> \
friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \ friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
->BinaryExpr<LhsT, RhsT> { \ ->BinaryExpr<LhsT, RhsT> { \
if ( rhs != 0 ) { throw_test_failure_exception(); } \ if ( rhs != 0 ) { \
throw_test_failure_exception(); \
} \
return { \ return { \
static_cast<bool>( lhs.m_lhs op 0 ), lhs.m_lhs, #op##_sr, rhs }; \ static_cast<bool>( lhs.m_lhs op 0 ), lhs.m_lhs, #op##_sr, rhs }; \
} \ } \
template < \ template < \
typename RhsT, \ typename RhsT, \
std::enable_if_t< \ std::enable_if_t<!Detail::is_##id##_comparable<LhsT, RhsT>::value && \
Detail::conjunction< \ Detail::is_eq_0_comparable<RhsT>:: \
Detail::negation<Detail::is_##id##_comparable<LhsT, RhsT>>, \ value && /* We allow long because we want \
Detail::is_eq_0_comparable<RhsT>, \ `ptr op NULL` to be accepted */ \
Detail::disjunction<std::is_same<LhsT, int>, \ ( std::is_same<LhsT, int>::value || \
/* On some platforms `NULL` is a long */ \ std::is_same<LhsT, long>::value ), \
std::is_same<LhsT, long>>>::value, \
int> = 0> \ int> = 0> \
friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \ friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
->BinaryExpr<LhsT, RhsT> { \ ->BinaryExpr<LhsT, RhsT> { \
if ( lhs.m_lhs != 0 ) { throw_test_failure_exception(); } \ if ( lhs.m_lhs != 0 ) { \
throw_test_failure_exception(); \
} \
return { static_cast<bool>( 0 op rhs ), lhs.m_lhs, #op##_sr, rhs }; \ return { static_cast<bool>( 0 op rhs ), lhs.m_lhs, #op##_sr, rhs }; \
} }
CATCH_INTERNAL_DEFINE_EXPRESSION_EQUALITY_OPERATOR( eq, == ) CATCH_INTERNAL_DEFINE_EXPRESSION_EQUALITY_OPERATOR( eq, == )
@ -228,19 +228,18 @@ namespace Catch {
template < \ template < \
typename RhsT, \ typename RhsT, \
std::enable_if_t< \ std::enable_if_t< \
Detail::conjunction<Detail::is_##id##_comparable<LhsT, RhsT>, \ Detail::is_##id##_comparable<LhsT, RhsT>::value && \
Detail::negation<std::is_arithmetic< \ !std::is_arithmetic<std::remove_reference_t<RhsT>>::value, \
std::remove_reference_t<RhsT>>>>::value, \
int> = 0> \ int> = 0> \
friend auto operator op( ExprLhs&& lhs, RhsT&& rhs ) \ friend auto operator op( ExprLhs&& lhs, RhsT&& rhs ) \
->BinaryExpr<LhsT, RhsT const&> { \ ->BinaryExpr<LhsT, RhsT const&> { \
return { \ return { \
static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op##_sr, rhs }; \ static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op##_sr, rhs }; \
} \ } \
template <typename RhsT, \ template < \
std::enable_if_t<Detail::conjunction< \ typename RhsT, \
Detail::is_##id##_comparable<LhsT, RhsT>, \ std::enable_if_t<Detail::is_##id##_comparable<LhsT, RhsT>::value && \
std::is_arithmetic<RhsT>>::value, \ std::is_arithmetic<RhsT>::value, \
int> = 0> \ int> = 0> \
friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \ friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
->BinaryExpr<LhsT, RhsT> { \ ->BinaryExpr<LhsT, RhsT> { \
@ -249,29 +248,29 @@ namespace Catch {
} \ } \
template < \ template < \
typename RhsT, \ typename RhsT, \
std::enable_if_t< \ std::enable_if_t<!Detail::is_##id##_comparable<LhsT, RhsT>::value && \
Detail::conjunction< \ Detail::is_##id##_0_comparable<LhsT>::value && \
Detail::negation<Detail::is_##id##_comparable<LhsT, RhsT>>, \ std::is_same<RhsT, int>::value, \
Detail::is_##id##_0_comparable<LhsT>, \
std::is_same<RhsT, int>>::value, \
int> = 0> \ int> = 0> \
friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \ friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
->BinaryExpr<LhsT, RhsT> { \ ->BinaryExpr<LhsT, RhsT> { \
if ( rhs != 0 ) { throw_test_failure_exception(); } \ if ( rhs != 0 ) { \
throw_test_failure_exception(); \
} \
return { \ return { \
static_cast<bool>( lhs.m_lhs op 0 ), lhs.m_lhs, #op##_sr, rhs }; \ static_cast<bool>( lhs.m_lhs op 0 ), lhs.m_lhs, #op##_sr, rhs }; \
} \ } \
template < \ template < \
typename RhsT, \ typename RhsT, \
std::enable_if_t< \ std::enable_if_t<!Detail::is_##id##_comparable<LhsT, RhsT>::value && \
Detail::conjunction< \ Detail::is_##id##_0_comparable<RhsT>::value && \
Detail::negation<Detail::is_##id##_comparable<LhsT, RhsT>>, \ std::is_same<LhsT, int>::value, \
Detail::is_##id##_0_comparable<RhsT>, \
std::is_same<LhsT, int>>::value, \
int> = 0> \ int> = 0> \
friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \ friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
->BinaryExpr<LhsT, RhsT> { \ ->BinaryExpr<LhsT, RhsT> { \
if ( lhs.m_lhs != 0 ) { throw_test_failure_exception(); } \ if ( lhs.m_lhs != 0 ) { \
throw_test_failure_exception(); \
} \
return { static_cast<bool>( 0 op rhs ), lhs.m_lhs, #op##_sr, rhs }; \ return { static_cast<bool>( 0 op rhs ), lhs.m_lhs, #op##_sr, rhs }; \
} }

View File

@ -329,29 +329,3 @@ TEST_CASE( "#2555 - types that can only be compared with 0 literal (not int/long
REQUIRE( TypeWithLit0Comparisons{} != 0 ); REQUIRE( TypeWithLit0Comparisons{} != 0 );
REQUIRE_FALSE( 0 != TypeWithLit0Comparisons{} ); REQUIRE_FALSE( 0 != TypeWithLit0Comparisons{} );
} }
namespace {
struct MultipleImplicitConstructors {
MultipleImplicitConstructors( double ) {}
MultipleImplicitConstructors( int64_t ) {}
bool operator==( MultipleImplicitConstructors ) const { return true; }
bool operator!=( MultipleImplicitConstructors ) const { return true; }
bool operator<( MultipleImplicitConstructors ) const { return true; }
bool operator<=( MultipleImplicitConstructors ) const { return true; }
bool operator>( MultipleImplicitConstructors ) const { return true; }
bool operator>=( MultipleImplicitConstructors ) const { return true; }
};
}
TEST_CASE("#2571 - tests compile types that have multiple implicit constructors from lit 0",
"[compilation][approvals]") {
MultipleImplicitConstructors mic1( 0.0 );
MultipleImplicitConstructors mic2( 0.0 );
REQUIRE( mic1 == mic2 );
REQUIRE( mic1 != mic2 );
REQUIRE( mic1 < mic2 );
REQUIRE( mic1 <= mic2 );
REQUIRE( mic1 > mic2 );
REQUIRE( mic1 >= mic2 );
}