Skip to content

Commit 9e9015f

Browse files
committed
Fix compatibility with GCC 5.2 (fixes #1897)
1 parent 74601b2 commit 9e9015f

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ HEAD
55
----
66

77
* Double speed of `DynamicJsonDocument::garbageCollect()`
8+
* Fix compatibility with GCC 5.2 (issue #1897)
89

910
v6.21.0 (2023-03-14)
1011
-------

extras/tests/JsonDeserializer/input_types.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,30 @@ TEST_CASE("deserializeJson(char*)") {
2424
}
2525
}
2626

27+
TEST_CASE("deserializeJson(unsigned char*, unsigned int)") { // issue #1897
28+
StaticJsonDocument<1024> doc;
29+
30+
unsigned char input[] = "{\"hello\":\"world\"}";
31+
unsigned char* input_ptr = input;
32+
unsigned int size = sizeof(input);
33+
34+
DeserializationError err = deserializeJson(doc, input_ptr, size);
35+
36+
REQUIRE(err == DeserializationError::Ok);
37+
}
38+
39+
TEST_CASE("deserializeJson(uint8_t*, size_t)") { // issue #1898
40+
StaticJsonDocument<1024> doc;
41+
42+
uint8_t input[] = "{\"hello\":\"world\"}";
43+
uint8_t* input_ptr = input;
44+
size_t size = sizeof(input);
45+
46+
DeserializationError err = deserializeJson(doc, input_ptr, size);
47+
48+
REQUIRE(err == DeserializationError::Ok);
49+
}
50+
2751
TEST_CASE("deserializeJson(const std::string&)") {
2852
DynamicJsonDocument doc(4096);
2953

src/ArduinoJson/Deserialization/deserialize.hpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@
1212

1313
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
1414

15+
// A meta-function that returns the first type of the parameter pack
16+
// or void if empty
17+
template <typename...>
18+
struct first_or_void {
19+
using type = void;
20+
};
21+
template <typename T, typename... Rest>
22+
struct first_or_void<T, Rest...> {
23+
using type = T;
24+
};
25+
1526
template <template <typename, typename> class TDeserializer, typename TReader,
1627
typename TWriter>
1728
TDeserializer<TReader, TWriter> makeDeserializer(MemoryPool* pool,
@@ -22,7 +33,9 @@ TDeserializer<TReader, TWriter> makeDeserializer(MemoryPool* pool,
2233
}
2334

2435
template <template <typename, typename> class TDeserializer, typename TStream,
25-
typename... Args>
36+
typename... Args,
37+
typename = typename enable_if< // issue #1897
38+
!is_integral<typename first_or_void<Args...>::type>::value>::type>
2639
DeserializationError deserialize(JsonDocument& doc, TStream&& input,
2740
Args... args) {
2841
auto reader = makeReader(detail::forward<TStream>(input));

0 commit comments

Comments
 (0)