Skip to content

Commit

Permalink
Added InvalidConversion to identify invalid conversions (closes #1585)
Browse files Browse the repository at this point in the history
  • Loading branch information
bblanchon committed Jun 11, 2021
1 parent dc76c51 commit 1d24caf
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ HEAD
* Fixed error `[Pe070]: incomplete type is not allowed` on IAR (issue #1560)
* Fixed `serializeJson(doc, String)` when allocation fails (issue #1572)
* Fixed clang-tidy warnings (issue #1574, PR #1577 by @armandas)
* Added fake class `InvalidConversion<T1,T2>` to easily identify invalid conversions (issue #1585)

v6.18.0 (2021-05-05)
-------
Expand Down
2 changes: 2 additions & 0 deletions src/ArduinoJson/Array/ArrayRef.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ struct Converter<ArrayRef> {
return ArrayRef(pool, data != 0 ? data->asArray() : 0);
}

static InvalidConversion<VariantConstRef, ArrayRef> fromJson(VariantConstRef);

static bool checkJson(VariantConstRef) {
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions src/ArduinoJson/Object/ObjectRef.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ struct Converter<ObjectRef> {
return ObjectRef(pool, data != 0 ? data->asObject() : 0);
}

static InvalidConversion<VariantConstRef, ObjectRef> fromJson(
VariantConstRef);

static bool checkJson(VariantConstRef) {
return false;
}
Expand Down
5 changes: 5 additions & 0 deletions src/ArduinoJson/Variant/Converter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ namespace ARDUINOJSON_NAMESPACE {
template <typename T, typename Enable = void>
struct Converter;

// clang-format off
template <typename T1, typename T2>
class InvalidConversion; // Error here? See https://arduinojson.org/v6/invalid-conversion/
// clang-format on

} // namespace ARDUINOJSON_NAMESPACE
6 changes: 6 additions & 0 deletions src/ArduinoJson/Variant/VariantRef.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,19 @@ struct Converter<VariantRef> {
static bool toJson(VariantRef src, VariantRef dst) {
return variantCopyFrom(getData(dst), getData(src), getPool(dst));
}

static VariantRef fromJson(VariantRef src) {
return src;
}

static InvalidConversion<VariantConstRef, VariantRef> fromJson(
VariantConstRef);

static bool checkJson(VariantRef src) {
VariantData *data = getData(src);
return !!data;
}

static bool checkJson(VariantConstRef) {
return false;
}
Expand Down

0 comments on commit 1d24caf

Please sign in to comment.