From 5c297ba4a2a8b2e718fe7b30ae1c584f9bf61e78 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Thu, 28 Feb 2019 12:20:46 +0100 Subject: [PATCH] Fixed warning "maybe uninitialized" (issue #909) --- CHANGELOG.md | 1 + src/ArduinoJson/JsonVariantImpl.hpp | 2 ++ test/CMakeLists.txt | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2096a8b9..cb6afb8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ HEAD ---- * Fixed warning "unused variable" with GCC 4.4 (issue #912) +* Fixed warning "maybe uninitialized" (issue #909) v5.13.4 ------- diff --git a/src/ArduinoJson/JsonVariantImpl.hpp b/src/ArduinoJson/JsonVariantImpl.hpp index 98db39ac..f9fe7d7f 100644 --- a/src/ArduinoJson/JsonVariantImpl.hpp +++ b/src/ArduinoJson/JsonVariantImpl.hpp @@ -23,6 +23,7 @@ inline JsonVariant::JsonVariant(const JsonArray &array) { _content.asArray = const_cast(&array); } else { _type = Internals::JSON_UNDEFINED; + _content.asArray = 0; // <- prevent warning 'maybe-uninitialized' } } @@ -32,6 +33,7 @@ inline JsonVariant::JsonVariant(const JsonObject &object) { _content.asObject = const_cast(&object); } else { _type = Internals::JSON_UNDEFINED; + _content.asObject = 0; // <- prevent warning 'maybe-uninitialized' } } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 49f5a6a1..b5f7be8a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -46,6 +46,12 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.6) add_compile_options(-Wnoexcept) endif() + + if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.7 AND + CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8) + # avoid false positive with GCC 4.7 + add_compile_options(-Wno-maybe-uninitialized) + endif() endif() if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")