Fix compatibility with GCC 5.2

This commit is contained in:
Benoit Blanchon
2023-03-27 11:00:20 +02:00
parent b3eada9c7f
commit 0328f66340
2 changed files with 38 additions and 1 deletions

View File

@ -24,6 +24,30 @@ TEST_CASE("deserializeJson(char*)") {
}
}
TEST_CASE("deserializeJson(unsigned char*, unsigned int)") { // issue #1897
JsonDocument doc(1024);
unsigned char input[] = "{\"hello\":\"world\"}";
unsigned char* input_ptr = input;
unsigned int size = sizeof(input);
DeserializationError err = deserializeJson(doc, input_ptr, size);
REQUIRE(err == DeserializationError::Ok);
}
TEST_CASE("deserializeJson(uint8_t*, size_t)") { // issue #1898
JsonDocument doc(1024);
uint8_t input[] = "{\"hello\":\"world\"}";
uint8_t* input_ptr = input;
size_t size = sizeof(input);
DeserializationError err = deserializeJson(doc, input_ptr, size);
REQUIRE(err == DeserializationError::Ok);
}
TEST_CASE("deserializeJson(const std::string&)") {
JsonDocument doc(4096);

View File

@ -12,6 +12,17 @@
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
// A meta-function that returns the first type of the parameter pack
// or void if empty
template <typename...>
struct first_or_void {
using type = void;
};
template <typename T, typename... Rest>
struct first_or_void<T, Rest...> {
using type = T;
};
template <template <typename, typename> class TDeserializer, typename TReader,
typename TWriter>
TDeserializer<TReader, TWriter> makeDeserializer(MemoryPool* pool,
@ -22,7 +33,9 @@ TDeserializer<TReader, TWriter> makeDeserializer(MemoryPool* pool,
}
template <template <typename, typename> class TDeserializer, typename TStream,
typename... Args>
typename... Args,
typename = typename enable_if< // issue #1897
!is_integral<typename first_or_void<Args...>::type>::value>::type>
DeserializationError deserialize(JsonDocument& doc, TStream&& input,
Args... args) {
auto reader = makeReader(detail::forward<TStream>(input));