Fix compatibility with GCC 4.8

Closes #2045
This commit is contained in:
Benoit Blanchon
2024-02-01 21:37:45 +01:00
parent c98b05e207
commit 72642e3090
9 changed files with 50 additions and 9 deletions

View File

@ -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"
}
}
}
}

View File

@ -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

View File

@ -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)
------

View File

@ -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/)

View File

@ -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(

View File

@ -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 {

View File

@ -212,3 +212,8 @@ TEST_CASE("Polyfills/type_traits") {
CHECK(is_enum<double>::value == false);
}
}
TEST_CASE("is_std_string") {
REQUIRE(is_std_string<std::string>::value == true);
REQUIRE(is_std_string<EmptyClass>::value == false);
}

View File

@ -30,7 +30,8 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
}
// Move-constructor
JsonDocument(JsonDocument&& src) : JsonDocument() {
JsonDocument(JsonDocument&& src)
: JsonDocument(detail::DefaultAllocator::instance()) {
swap(*this, src);
}

View File

@ -9,15 +9,13 @@
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
template <class...>
using void_t = void;
template <class T, typename = void>
struct is_std_string : false_type {};
template <class T>
struct is_std_string<
T, void_t<decltype(T().push_back('a')), decltype(T().append(""))>>
T, typename enable_if<is_same<void, decltype(T().push_back('a'))>::value &&
is_same<T&, decltype(T().append(""))>::value>::type>
: true_type {};
template <typename TDestination>