[libc++] Fix fuzzing tests with older GCC compilers.

GCC 5 doesn't support `if constexpr`, so we need to do old-style tag
dispatching.
This commit is contained in:
Eric Fiselier 2019-12-11 16:36:21 -05:00
parent 0ca0fba94d
commit 5c9816b84e
1 changed files with 17 additions and 7 deletions

View File

@ -652,6 +652,8 @@ enum InitKind {
VectorResultType
};
template <class Dist>
struct ParamTypeHelper {
using ParamT = typename Dist::param_type;
@ -659,16 +661,24 @@ struct ParamTypeHelper {
static_assert(std::is_same<ResultT, typename ParamT::distribution_type::result_type>::value, "");
static ParamT Create(const uint8_t* data, size_t size, bool &OK) {
if constexpr (std::is_constructible<ParamT, ResultT*, ResultT*, ResultT*>::value)
return CreateVectorResult(data, size, OK);
else if constexpr (std::is_constructible<ParamT, double*, double*>::value)
return CreateVectorDouble(data, size, OK);
else
return CreateDefault(data, size, OK);
constexpr bool select_vector_result = std::is_constructible<ParamT, ResultT*, ResultT*, ResultT*>::value;
constexpr bool select_vector_double = std::is_constructible<ParamT, double*, double*>::value;
constexpr int selector = select_vector_result ? 0 : (select_vector_double ? 1 : 2);
return DispatchAndCreate(std::integral_constant<int, selector>{}, data, size, OK);
}
static ParamT DispatchAndCreate(std::integral_constant<int, 0>, const uint8_t *data, size_t size, bool &OK) {
return CreateVectorResult(data, size, OK);
}
static ParamT DispatchAndCreate(std::integral_constant<int, 1>, const uint8_t *data, size_t size, bool &OK) {
return CreateVectorDouble(data, size, OK);
}
static ParamT DispatchAndCreate(std::integral_constant<int, 2>, const uint8_t *data, size_t size, bool &OK) {
return CreateDefault(data, size, OK);
}
static ParamT
static ParamT
CreateVectorResult(const uint8_t *data, size_t size, bool &OK) {
auto Input = GetValues<ResultT>(data, size);
OK = false;