diff --git a/CHANGELOG.md b/CHANGELOG.md index f3866b3c..18417919 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ ArduinoJson: change log ======================= +HEAD +---- + +* Fixed support for `volatile float` and `volatile double` (issue #1557) + v6.18.0 (2021-05-05) ------- diff --git a/extras/tests/JsonVariant/types.cpp b/extras/tests/JsonVariant/types.cpp index 106f6eb3..d2665bfa 100644 --- a/extras/tests/JsonVariant/types.cpp +++ b/extras/tests/JsonVariant/types.cpp @@ -135,3 +135,29 @@ TEST_CASE("JsonVariant set()/get()") { checkValue(object); } } + +TEST_CASE("volatile") { + DynamicJsonDocument doc(4096); + JsonVariant variant = doc.to(); + + SECTION("volatile int") { + volatile int f = 42; + variant.set(f); + CHECK(variant.is() == true); + CHECK(variant.as() == 42); + } + + SECTION("volatile float") { // issue #1557 + volatile float f = 3.14f; + variant.set(f); + CHECK(variant.is() == true); + CHECK(variant.as() == 3.14f); + } + + SECTION("volatile double") { + volatile double f = 3.14; + variant.set(f); + CHECK(variant.is() == true); + CHECK(variant.as() == 3.14); + } +} diff --git a/extras/tests/Misc/TypeTraits.cpp b/extras/tests/Misc/TypeTraits.cpp index a8f030ac..de76f4c5 100644 --- a/extras/tests/Misc/TypeTraits.cpp +++ b/extras/tests/Misc/TypeTraits.cpp @@ -32,6 +32,12 @@ TEST_CASE("Polyfills/type_traits") { SECTION("is_integral") { CHECK(is_integral::value == false); CHECK(is_integral::value == false); + CHECK(is_integral::value == false); + CHECK(is_integral::value == false); + CHECK(is_integral::value == false); + CHECK(is_integral::value == false); + CHECK(is_integral::value == false); + CHECK(is_integral::value == false); CHECK(is_integral::value == true); CHECK(is_integral::value == true); @@ -43,6 +49,36 @@ TEST_CASE("Polyfills/type_traits") { CHECK(is_integral::value == true); CHECK(is_integral::value == true); CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); CHECK(is_integral::value == true); } @@ -56,6 +92,33 @@ TEST_CASE("Polyfills/type_traits") { CHECK(is_signed::value == true); CHECK(is_signed::value == true); CHECK(is_signed::value == false); + + CHECK(is_signed::value == true); + CHECK(is_signed::value == true); + CHECK(is_signed::value == true); + CHECK(is_signed::value == true); + CHECK(is_signed::value == true); + CHECK(is_signed::value == true); + CHECK(is_signed::value == true); + CHECK(is_signed::value == false); + + CHECK(is_signed::value == true); + CHECK(is_signed::value == true); + CHECK(is_signed::value == true); + CHECK(is_signed::value == true); + CHECK(is_signed::value == true); + CHECK(is_signed::value == true); + CHECK(is_signed::value == true); + CHECK(is_signed::value == false); + + CHECK(is_signed::value == true); + CHECK(is_signed::value == true); + CHECK(is_signed::value == true); + CHECK(is_signed::value == true); + CHECK(is_signed::value == true); + CHECK(is_signed::value == true); + CHECK(is_signed::value == true); + CHECK(is_signed::value == false); } SECTION("is_unsigned") { @@ -67,6 +130,45 @@ TEST_CASE("Polyfills/type_traits") { CHECK(is_unsigned::value == false); CHECK(is_unsigned::value == false); CHECK(is_unsigned::value == false); + + CHECK(is_unsigned::value == true); + CHECK(is_unsigned::value == true); + CHECK(is_unsigned::value == true); + CHECK(is_unsigned::value == true); + CHECK(is_unsigned::value == true); + CHECK(is_unsigned::value == false); + CHECK(is_unsigned::value == false); + CHECK(is_unsigned::value == false); + + CHECK(is_unsigned::value == true); + CHECK(is_unsigned::value == true); + CHECK(is_unsigned::value == true); + CHECK(is_unsigned::value == true); + CHECK(is_unsigned::value == true); + CHECK(is_unsigned::value == false); + CHECK(is_unsigned::value == false); + CHECK(is_unsigned::value == false); + + CHECK(is_unsigned::value == true); + CHECK(is_unsigned::value == true); + CHECK(is_unsigned::value == true); + CHECK(is_unsigned::value == true); + CHECK(is_unsigned::value == true); + CHECK(is_unsigned::value == false); + CHECK(is_unsigned::value == false); + CHECK(is_unsigned::value == false); + } + + SECTION("is_floating_point") { + CHECK(is_floating_point::value == false); + CHECK(is_floating_point::value == true); + CHECK(is_floating_point::value == true); + CHECK(is_floating_point::value == true); + CHECK(is_floating_point::value == true); + CHECK(is_floating_point::value == true); + CHECK(is_floating_point::value == true); + CHECK(is_floating_point::value == true); + CHECK(is_floating_point::value == true); } SECTION("is_convertible") { diff --git a/src/ArduinoJson/Polyfills/type_traits/is_floating_point.hpp b/src/ArduinoJson/Polyfills/type_traits/is_floating_point.hpp index b7e9d3d2..fb42f059 100644 --- a/src/ArduinoJson/Polyfills/type_traits/is_floating_point.hpp +++ b/src/ArduinoJson/Polyfills/type_traits/is_floating_point.hpp @@ -5,15 +5,16 @@ #pragma once #include "integral_constant.hpp" +#include "is_same.hpp" +#include "remove_cv.hpp" namespace ARDUINOJSON_NAMESPACE { -template -struct is_floating_point : false_type {}; +template +struct is_floating_point + : integral_constant< + bool, // + is_same::type>::value || + is_same::type>::value> {}; -template <> -struct is_floating_point : true_type {}; - -template <> -struct is_floating_point : true_type {}; } // namespace ARDUINOJSON_NAMESPACE diff --git a/src/ArduinoJson/Polyfills/type_traits/is_integral.hpp b/src/ArduinoJson/Polyfills/type_traits/is_integral.hpp index 26e895c8..65918cf9 100644 --- a/src/ArduinoJson/Polyfills/type_traits/is_integral.hpp +++ b/src/ArduinoJson/Polyfills/type_traits/is_integral.hpp @@ -5,29 +5,33 @@ #pragma once #include + +#include "integral_constant.hpp" #include "is_same.hpp" +#include "remove_cv.hpp" namespace ARDUINOJSON_NAMESPACE { -// A meta-function that returns true if T is an integral type. +// clang-format off template -struct is_integral { - static const bool value = - is_same::value || is_same::value || - is_same::value || is_same::value || - is_same::value || is_same::value || - is_same::value || is_same::value || +struct is_integral : integral_constant::type, signed char>::value || + is_same::type, unsigned char>::value || + is_same::type, signed short>::value || + is_same::type, unsigned short>::value || + is_same::type, signed int>::value || + is_same::type, unsigned int>::value || + is_same::type, signed long>::value || + is_same::type, unsigned long>::value || #if ARDUINOJSON_HAS_LONG_LONG - is_same::value || - is_same::value || + is_same::type, signed long long>::value || + is_same::type, unsigned long long>::value || #endif #if ARDUINOJSON_HAS_INT64 - is_same::value || - is_same::value || + is_same::type, signed __int64>::value || + is_same::type, unsigned __int64>::value || #endif - is_same::value || is_same::value; -}; - -template -struct is_integral : is_integral {}; + is_same::type, char>::value || + is_same::type, bool>::value> {}; +// clang-format on } // namespace ARDUINOJSON_NAMESPACE diff --git a/src/ArduinoJson/Polyfills/type_traits/is_signed.hpp b/src/ArduinoJson/Polyfills/type_traits/is_signed.hpp index fbb701cf..3e064e31 100644 --- a/src/ArduinoJson/Polyfills/type_traits/is_signed.hpp +++ b/src/ArduinoJson/Polyfills/type_traits/is_signed.hpp @@ -5,39 +5,26 @@ #pragma once #include "integral_constant.hpp" +#include "is_same.hpp" +#include "remove_cv.hpp" + namespace ARDUINOJSON_NAMESPACE { -template -struct is_signed : false_type {}; - -template <> -struct is_signed : true_type {}; - -template <> -struct is_signed : true_type {}; - -template <> -struct is_signed : true_type {}; - -template <> -struct is_signed : true_type {}; - -template <> -struct is_signed : true_type {}; - -template <> -struct is_signed : true_type {}; - -template <> -struct is_signed : true_type {}; - +// clang-format off +template +struct is_signed : integral_constant::type, char>::value || + is_same::type, signed char>::value || + is_same::type, signed short>::value || + is_same::type, signed int>::value || + is_same::type, signed long>::value || #if ARDUINOJSON_HAS_LONG_LONG -template <> -struct is_signed : true_type {}; + is_same::type, signed long long>::value || #endif - #if ARDUINOJSON_HAS_INT64 -template <> -struct is_signed : true_type {}; + is_same::type, signed __int64>::value || #endif + is_same::type, float>::value || + is_same::type, double>::value> {}; +// clang-format on } // namespace ARDUINOJSON_NAMESPACE diff --git a/src/ArduinoJson/Polyfills/type_traits/is_unsigned.hpp b/src/ArduinoJson/Polyfills/type_traits/is_unsigned.hpp index be264982..57acff23 100644 --- a/src/ArduinoJson/Polyfills/type_traits/is_unsigned.hpp +++ b/src/ArduinoJson/Polyfills/type_traits/is_unsigned.hpp @@ -5,33 +5,24 @@ #pragma once #include "integral_constant.hpp" +#include "is_same.hpp" +#include "remove_cv.hpp" + namespace ARDUINOJSON_NAMESPACE { -template -struct is_unsigned : false_type {}; - -template <> -struct is_unsigned : true_type {}; - -template <> -struct is_unsigned : true_type {}; - -template <> -struct is_unsigned : true_type {}; - -template <> -struct is_unsigned : true_type {}; - -template <> -struct is_unsigned : true_type {}; - +// clang-format off +template +struct is_unsigned : integral_constant::type, unsigned char>::value || + is_same::type, unsigned short>::value || + is_same::type, unsigned int>::value || + is_same::type, unsigned long>::value || #if ARDUINOJSON_HAS_INT64 -template <> -struct is_unsigned : true_type {}; + is_same::type, unsigned __int64>::value || #endif - #if ARDUINOJSON_HAS_LONG_LONG -template <> -struct is_unsigned : true_type {}; + is_same::type, unsigned long long>::value || #endif + is_same::type, bool>::value> {}; +// clang-format on } // namespace ARDUINOJSON_NAMESPACE diff --git a/src/ArduinoJson/Polyfills/type_traits/remove_cv.hpp b/src/ArduinoJson/Polyfills/type_traits/remove_cv.hpp new file mode 100644 index 00000000..021e0ec5 --- /dev/null +++ b/src/ArduinoJson/Polyfills/type_traits/remove_cv.hpp @@ -0,0 +1,27 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include + +namespace ARDUINOJSON_NAMESPACE { + +template +struct remove_cv { + typedef T type; +}; +template +struct remove_cv { + typedef T type; +}; +template +struct remove_cv { + typedef T type; +}; +template +struct remove_cv { + typedef T type; +}; +} // namespace ARDUINOJSON_NAMESPACE