Skip to content

Commit 5fe4215

Browse files
committed
(compatibility) enable clang compilation
- replaced fallback operator implementation based on C-style varargs with operators triggered by SFINAE inclusion/exclusion - tested with clang 18 and gcc 12 issue #41
1 parent 055eb52 commit 5fe4215

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

include/clippy/clippy-eval.hpp

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,6 +2454,19 @@ namespace json_logic
24542454
return compareSeq(deref(lv), deref(rv), std::move(pred));
24552455
}
24562456

2457+
// convenience template that only returns a type when the types mismatch
2458+
template <class U, class V, class ResultType>
2459+
struct MismatchedTypes
2460+
{
2461+
using type = ResultType;
2462+
};
2463+
2464+
template <class T, class ResultType>
2465+
struct MismatchedTypes<T,T,ResultType>
2466+
{
2467+
// using type // triggers SFINAE exclusion
2468+
};
2469+
24572470

24582471
//
24592472
// the calc operator implementations
@@ -2466,11 +2479,17 @@ namespace json_logic
24662479
{
24672480
using EqualityOperator::result_type;
24682481

2469-
result_type operator()(...) const { return false; } // type mismatch
2482+
template <class U, class V>
2483+
auto
2484+
operator()(const U&, const V&) const
2485+
-> typename MismatchedTypes<U,V,result_type>::type // type mismatch
2486+
{
2487+
return false;
2488+
}
24702489

24712490
template <class T>
2472-
result_type
2473-
operator()(const T& lhs, const T& rhs) const
2491+
auto
2492+
operator()(const T& lhs, const T& rhs) const -> result_type
24742493
{
24752494
return lhs == rhs;
24762495
}
@@ -2481,7 +2500,13 @@ namespace json_logic
24812500
{
24822501
using EqualityOperator::result_type;
24832502

2484-
result_type operator()(...) const { return true; } // type mismatch
2503+
template <class U, class V>
2504+
auto
2505+
operator()(const U&, const V&) const
2506+
-> typename MismatchedTypes<U,V,result_type>::type // type mismatch
2507+
{
2508+
return true;
2509+
}
24852510

24862511
template <class T>
24872512
result_type
@@ -2496,7 +2521,13 @@ namespace json_logic
24962521
{
24972522
using StrictEqualityOperator::result_type;
24982523

2499-
result_type operator()(...) const { return false; } // type mismatch
2524+
template <class U, class V>
2525+
auto
2526+
operator()(const U&, const V&) const
2527+
-> typename MismatchedTypes<U,V,result_type>::type // type mismatch
2528+
{
2529+
return false;
2530+
}
25002531

25012532
template <class T>
25022533
result_type
@@ -2511,7 +2542,13 @@ namespace json_logic
25112542
{
25122543
using StrictEqualityOperator::result_type;
25132544

2514-
result_type operator()(...) const { return true; } // type mismatch
2545+
template <class U, class V>
2546+
auto
2547+
operator()(const U&, const V&) const
2548+
-> typename MismatchedTypes<U,V,result_type>::type // type mismatch
2549+
{
2550+
return true;
2551+
}
25152552

25162553
template <class T>
25172554
result_type

0 commit comments

Comments
 (0)