Fix volatile bool serialized as 1 or 0

Fixes #2029
This commit is contained in:
Benoit Blanchon
2024-01-10 13:30:26 +01:00
parent 3e1be980d9
commit 5d1d2721d1
3 changed files with 10 additions and 1 deletions

View File

@ -5,6 +5,7 @@ HEAD
----
* Fix warning `function returns incomplete class type` on IAR (issue #2001)
* Fix `volatile bool` serialized as `1` or `0` instead of `true` or `false` (issue #2029)
v6.21.4 (2023-12-07)
-------

View File

@ -140,6 +140,13 @@ TEST_CASE("volatile") {
DynamicJsonDocument doc(4096);
JsonVariant variant = doc.to<JsonVariant>();
SECTION("volatile bool") { // issue #2029
volatile bool f = true;
variant.set(f);
CHECK(variant.is<bool>() == true);
CHECK(variant.as<bool>() == true);
}
SECTION("volatile int") {
volatile int f = 42;
variant.set(f);

View File

@ -137,7 +137,8 @@ VariantRefBase<TDerived>::is() const {
template <typename TDerived>
template <typename T>
inline bool VariantRefBase<TDerived>::set(const T& value) const {
Converter<T>::toJson(value, getOrCreateVariant());
Converter<typename detail::remove_cv<T>::type>::toJson(value,
getOrCreateVariant());
MemoryPool* pool = getPool();
return pool && !pool->overflowed();
}