Skip to content

Commit 72642e3

Browse files
committed
Fix compatibility with GCC 4.8
Closes #2045
1 parent c98b05e commit 72642e3

File tree

9 files changed

+50
-9
lines changed

9 files changed

+50
-9
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "GCC 4.8",
3+
"image": "conanio/gcc48",
4+
"runArgs": [
5+
"--name=ArduinoJson-gcc48"
6+
],
7+
"customizations": {
8+
"vscode": {
9+
"extensions": [
10+
"ms-vscode.cmake-tools",
11+
"josetr.cmake-language-support-vscode",
12+
"ms-vscode.cpptools"
13+
],
14+
"settings": {
15+
"cmake.generator": "Unix Makefiles",
16+
"cmake.buildDirectory": "/tmp/build"
17+
}
18+
}
19+
}
20+
}

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ jobs:
3333
fail-fast: false
3434
matrix:
3535
include:
36+
- gcc: "4.8"
3637
- gcc: "5"
3738
- gcc: "6"
3839
- gcc: "7"
@@ -49,6 +50,7 @@ jobs:
4950
- name: Install
5051
run: |
5152
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 40976EAF437D05B5 3B4FE6ACC0B21F32
53+
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ xenial main universe'
5254
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ bionic main universe'
5355
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ focal main universe'
5456
sudo apt-get update

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ HEAD
66

77
* Improve error messages when using `char` or `char*` (issue #2043)
88
* Reduce `serializeJson()`'s size and stack usage (issue #2046)
9+
* Fix compatibility with GCC 4.8 (issue #2045)
910

1011
v7.0.2 (2024-01-19)
1112
------

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).
7979
* [Unit test coverage close to 100%](https://coveralls.io/github/bblanchon/ArduinoJson?branch=7.x)
8080
* Continuously tested on
8181
* [Visual Studio 2017, 2019, 2022](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/7.x)
82-
* [GCC 5, 6, 7, 8, 9, 10, 11, 12](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22)
82+
* [GCC 4.8, 5, 6, 7, 8, 9, 10, 11, 12](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22)
8383
* [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)
8484
* [Continuously fuzzed with Google OSS Fuzz](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson)
8585
* Passes all default checks of [clang-tidy](https://releases.llvm.org/10.0.0/tools/clang/tools/extra/docs/clang-tidy/)

extras/CompileOptions.cmake

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,18 @@ endif()
3232
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
3333
if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8) AND(NOT ${COVERAGE}))
3434
add_compile_options(-g -Og)
35-
else()
36-
add_compile_options(-g -O0)
35+
else() # GCC 4.8
36+
add_compile_options(
37+
-g
38+
-O0 # GCC 4.8 doesn't support -Og
39+
-Wno-shadow # allow the same name for a function parameter and a member functions
40+
-Wp,-w # Disable preprocessing warnings (see below)
41+
)
42+
# GCC 4.8 doesn't support __has_include, so we need to help him
43+
add_definitions(
44+
-DARDUINOJSON_ENABLE_STD_STRING=1
45+
-DARDUINOJSON_ENABLE_STD_STREAM=1
46+
)
3747
endif()
3848

3949
add_compile_options(

extras/tests/Helpers/Allocators.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ class AllocatorLog {
9090
append(entry);
9191
}
9292

93+
void clear() {
94+
log_.str("");
95+
}
96+
9397
void append(const AllocatorLogEntry& entry) {
9498
for (size_t i = 0; i < entry.count(); i++)
9599
log_ << entry.str() << "\n";
@@ -165,7 +169,7 @@ class SpyingAllocator : public ArduinoJson::Allocator {
165169
}
166170

167171
void clearLog() {
168-
log_ = AllocatorLog();
172+
log_.clear();
169173
}
170174

171175
const AllocatorLog& log() const {

extras/tests/Misc/TypeTraits.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,8 @@ TEST_CASE("Polyfills/type_traits") {
212212
CHECK(is_enum<double>::value == false);
213213
}
214214
}
215+
216+
TEST_CASE("is_std_string") {
217+
REQUIRE(is_std_string<std::string>::value == true);
218+
REQUIRE(is_std_string<EmptyClass>::value == false);
219+
}

src/ArduinoJson/Document/JsonDocument.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
3030
}
3131

3232
// Move-constructor
33-
JsonDocument(JsonDocument&& src) : JsonDocument() {
33+
JsonDocument(JsonDocument&& src)
34+
: JsonDocument(detail::DefaultAllocator::instance()) {
3435
swap(*this, src);
3536
}
3637

src/ArduinoJson/Serialization/Writers/StdStringWriter.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99

1010
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
1111

12-
template <class...>
13-
using void_t = void;
14-
1512
template <class T, typename = void>
1613
struct is_std_string : false_type {};
1714

1815
template <class T>
1916
struct is_std_string<
20-
T, void_t<decltype(T().push_back('a')), decltype(T().append(""))>>
17+
T, typename enable_if<is_same<void, decltype(T().push_back('a'))>::value &&
18+
is_same<T&, decltype(T().append(""))>::value>::type>
2119
: true_type {};
2220

2321
template <typename TDestination>

0 commit comments

Comments
 (0)