Skip to content

Commit 5c9816b

Browse files
committed
[libc++] Fix fuzzing tests with older GCC compilers.
GCC 5 doesn't support `if constexpr`, so we need to do old-style tag dispatching.
1 parent 0ca0fba commit 5c9816b

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

libcxx/fuzzing/fuzzing.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -652,23 +652,33 @@ enum InitKind {
652652
VectorResultType
653653
};
654654

655+
656+
655657
template <class Dist>
656658
struct ParamTypeHelper {
657659
using ParamT = typename Dist::param_type;
658660
using ResultT = typename Dist::result_type;
659661
static_assert(std::is_same<ResultT, typename ParamT::distribution_type::result_type>::value, "");
660662
static ParamT Create(const uint8_t* data, size_t size, bool &OK) {
661663

662-
if constexpr (std::is_constructible<ParamT, ResultT*, ResultT*, ResultT*>::value)
663-
return CreateVectorResult(data, size, OK);
664-
else if constexpr (std::is_constructible<ParamT, double*, double*>::value)
665-
return CreateVectorDouble(data, size, OK);
666-
else
667-
return CreateDefault(data, size, OK);
664+
constexpr bool select_vector_result = std::is_constructible<ParamT, ResultT*, ResultT*, ResultT*>::value;
665+
constexpr bool select_vector_double = std::is_constructible<ParamT, double*, double*>::value;
666+
constexpr int selector = select_vector_result ? 0 : (select_vector_double ? 1 : 2);
667+
return DispatchAndCreate(std::integral_constant<int, selector>{}, data, size, OK);
668+
668669
}
669670

671+
static ParamT DispatchAndCreate(std::integral_constant<int, 0>, const uint8_t *data, size_t size, bool &OK) {
672+
return CreateVectorResult(data, size, OK);
673+
}
674+
static ParamT DispatchAndCreate(std::integral_constant<int, 1>, const uint8_t *data, size_t size, bool &OK) {
675+
return CreateVectorDouble(data, size, OK);
676+
}
677+
static ParamT DispatchAndCreate(std::integral_constant<int, 2>, const uint8_t *data, size_t size, bool &OK) {
678+
return CreateDefault(data, size, OK);
679+
}
670680

671-
static ParamT
681+
static ParamT
672682
CreateVectorResult(const uint8_t *data, size_t size, bool &OK) {
673683
auto Input = GetValues<ResultT>(data, size);
674684
OK = false;

0 commit comments

Comments
 (0)