From 72642e30907f3dbd8f56b5f2b0676f1fbb6aeb56 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Thu, 1 Feb 2024 21:37:45 +0100 Subject: [PATCH] Fix compatibility with GCC 4.8 Closes #2045 --- .devcontainer/gcc48/devcontainer.json | 20 +++++++++++++++++++ .github/workflows/ci.yml | 2 ++ CHANGELOG.md | 1 + README.md | 2 +- extras/CompileOptions.cmake | 14 +++++++++++-- extras/tests/Helpers/Allocators.hpp | 6 +++++- extras/tests/Misc/TypeTraits.cpp | 5 +++++ src/ArduinoJson/Document/JsonDocument.hpp | 3 ++- .../Serialization/Writers/StdStringWriter.hpp | 6 ++---- 9 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 .devcontainer/gcc48/devcontainer.json diff --git a/.devcontainer/gcc48/devcontainer.json b/.devcontainer/gcc48/devcontainer.json new file mode 100644 index 00000000..660eac45 --- /dev/null +++ b/.devcontainer/gcc48/devcontainer.json @@ -0,0 +1,20 @@ +{ + "name": "GCC 4.8", + "image": "conanio/gcc48", + "runArgs": [ + "--name=ArduinoJson-gcc48" + ], + "customizations": { + "vscode": { + "extensions": [ + "ms-vscode.cmake-tools", + "josetr.cmake-language-support-vscode", + "ms-vscode.cpptools" + ], + "settings": { + "cmake.generator": "Unix Makefiles", + "cmake.buildDirectory": "/tmp/build" + } + } + } +} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 79b2336a..c179dfb9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,6 +33,7 @@ jobs: fail-fast: false matrix: include: + - gcc: "4.8" - gcc: "5" - gcc: "6" - gcc: "7" @@ -49,6 +50,7 @@ jobs: - name: Install run: | sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 40976EAF437D05B5 3B4FE6ACC0B21F32 + sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ xenial main universe' sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ bionic main universe' sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ focal main universe' sudo apt-get update diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d3b5d6a..8c24619f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ HEAD * Improve error messages when using `char` or `char*` (issue #2043) * Reduce `serializeJson()`'s size and stack usage (issue #2046) +* Fix compatibility with GCC 4.8 (issue #2045) v7.0.2 (2024-01-19) ------ diff --git a/README.md b/README.md index a490af33..2900240e 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things). * [Unit test coverage close to 100%](https://coveralls.io/github/bblanchon/ArduinoJson?branch=7.x) * Continuously tested on * [Visual Studio 2017, 2019, 2022](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/7.x) - * [GCC 5, 6, 7, 8, 9, 10, 11, 12](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22) + * [GCC 4.8, 5, 6, 7, 8, 9, 10, 11, 12](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22) * [Clang 3.9, 4.0, 5.0, 6.0, 7, 8, 9, 10, 11, 12, 13, 14, 15](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22) * [Continuously fuzzed with Google OSS Fuzz](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson) * Passes all default checks of [clang-tidy](https://releases.llvm.org/10.0.0/tools/clang/tools/extra/docs/clang-tidy/) diff --git a/extras/CompileOptions.cmake b/extras/CompileOptions.cmake index 65c90827..ae1139ff 100644 --- a/extras/CompileOptions.cmake +++ b/extras/CompileOptions.cmake @@ -32,8 +32,18 @@ endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8) AND(NOT ${COVERAGE})) add_compile_options(-g -Og) - else() - add_compile_options(-g -O0) + else() # GCC 4.8 + add_compile_options( + -g + -O0 # GCC 4.8 doesn't support -Og + -Wno-shadow # allow the same name for a function parameter and a member functions + -Wp,-w # Disable preprocessing warnings (see below) + ) + # GCC 4.8 doesn't support __has_include, so we need to help him + add_definitions( + -DARDUINOJSON_ENABLE_STD_STRING=1 + -DARDUINOJSON_ENABLE_STD_STREAM=1 + ) endif() add_compile_options( diff --git a/extras/tests/Helpers/Allocators.hpp b/extras/tests/Helpers/Allocators.hpp index f45a1221..5df98ed4 100644 --- a/extras/tests/Helpers/Allocators.hpp +++ b/extras/tests/Helpers/Allocators.hpp @@ -90,6 +90,10 @@ class AllocatorLog { append(entry); } + void clear() { + log_.str(""); + } + void append(const AllocatorLogEntry& entry) { for (size_t i = 0; i < entry.count(); i++) log_ << entry.str() << "\n"; @@ -165,7 +169,7 @@ class SpyingAllocator : public ArduinoJson::Allocator { } void clearLog() { - log_ = AllocatorLog(); + log_.clear(); } const AllocatorLog& log() const { diff --git a/extras/tests/Misc/TypeTraits.cpp b/extras/tests/Misc/TypeTraits.cpp index 8301f93f..7beb4658 100644 --- a/extras/tests/Misc/TypeTraits.cpp +++ b/extras/tests/Misc/TypeTraits.cpp @@ -212,3 +212,8 @@ TEST_CASE("Polyfills/type_traits") { CHECK(is_enum::value == false); } } + +TEST_CASE("is_std_string") { + REQUIRE(is_std_string::value == true); + REQUIRE(is_std_string::value == false); +} diff --git a/src/ArduinoJson/Document/JsonDocument.hpp b/src/ArduinoJson/Document/JsonDocument.hpp index d2daf97a..6e07ce2e 100644 --- a/src/ArduinoJson/Document/JsonDocument.hpp +++ b/src/ArduinoJson/Document/JsonDocument.hpp @@ -30,7 +30,8 @@ class JsonDocument : public detail::VariantOperators { } // Move-constructor - JsonDocument(JsonDocument&& src) : JsonDocument() { + JsonDocument(JsonDocument&& src) + : JsonDocument(detail::DefaultAllocator::instance()) { swap(*this, src); } diff --git a/src/ArduinoJson/Serialization/Writers/StdStringWriter.hpp b/src/ArduinoJson/Serialization/Writers/StdStringWriter.hpp index 46dc8ba5..6ac4d973 100644 --- a/src/ArduinoJson/Serialization/Writers/StdStringWriter.hpp +++ b/src/ArduinoJson/Serialization/Writers/StdStringWriter.hpp @@ -9,15 +9,13 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE -template -using void_t = void; - template struct is_std_string : false_type {}; template struct is_std_string< - T, void_t> + T, typename enable_if::value && + is_same::value>::type> : true_type {}; template