From 91dd45c387345bafcaebeef35e24f1492f2e7cbc Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Fri, 1 Mar 2019 18:11:27 +0100 Subject: [PATCH] Fixed naming conflict with "CAPACITY" (issue #839) --- CHANGELOG.md | 1 + .../Document/StaticJsonDocument.hpp | 16 +++---- test/Misc/CMakeLists.txt | 2 +- test/Misc/conflicts.cpp | 42 +++++++++++++++++++ test/Misc/empty.cpp | 7 ---- 5 files changed, 52 insertions(+), 16 deletions(-) create mode 100644 test/Misc/conflicts.cpp delete mode 100644 test/Misc/empty.cpp diff --git a/CHANGELOG.md b/CHANGELOG.md index e733c30b..94680fef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ HEAD * Fixed warning "unused variable" with GCC 4.4 (issue #912) * Fixed warning "cast increases required alignment" (issue #914) * Fixed warning "conversion may alter value" (issue #914) +* Fixed naming conflict with "CAPACITY" (issue #839) * Muted warning "will change in GCC 7.1" (issue #914) * Added a clear error message for `StaticJsonBuffer` and `DynamicJsonBuffer` * Marked ArduinoJson.h as a "system header" diff --git a/src/ArduinoJson/Document/StaticJsonDocument.hpp b/src/ArduinoJson/Document/StaticJsonDocument.hpp index 5de4da5a..a93a4366 100644 --- a/src/ArduinoJson/Document/StaticJsonDocument.hpp +++ b/src/ArduinoJson/Document/StaticJsonDocument.hpp @@ -8,28 +8,28 @@ namespace ARDUINOJSON_NAMESPACE { -template +template class StaticJsonDocument : public JsonDocument { - static const size_t ACTUAL_CAPACITY = - AddPadding::value>::value; + static const size_t _capacity = + AddPadding::value>::value; public: - StaticJsonDocument() : JsonDocument(_buffer, ACTUAL_CAPACITY) {} + StaticJsonDocument() : JsonDocument(_buffer, _capacity) {} StaticJsonDocument(const StaticJsonDocument& src) - : JsonDocument(_buffer, ACTUAL_CAPACITY) { + : JsonDocument(_buffer, _capacity) { set(src); } template StaticJsonDocument(const T& src, typename enable_if::value>::type* = 0) - : JsonDocument(_buffer, ACTUAL_CAPACITY) { + : JsonDocument(_buffer, _capacity) { set(src); } // disambiguate - StaticJsonDocument(VariantRef src) : JsonDocument(_buffer, ACTUAL_CAPACITY) { + StaticJsonDocument(VariantRef src) : JsonDocument(_buffer, _capacity) { set(src); } @@ -45,7 +45,7 @@ class StaticJsonDocument : public JsonDocument { } private: - char _buffer[ACTUAL_CAPACITY]; + char _buffer[_capacity]; }; } // namespace ARDUINOJSON_NAMESPACE diff --git a/test/Misc/CMakeLists.txt b/test/Misc/CMakeLists.txt index 65c35d6f..9e8817ab 100644 --- a/test/Misc/CMakeLists.txt +++ b/test/Misc/CMakeLists.txt @@ -3,7 +3,7 @@ # MIT License add_executable(MiscTests - empty.cpp + conflicts.cpp FloatParts.cpp StringWriter.cpp TypeTraits.cpp diff --git a/test/Misc/conflicts.cpp b/test/Misc/conflicts.cpp new file mode 100644 index 00000000..fe91bdef --- /dev/null +++ b/test/Misc/conflicts.cpp @@ -0,0 +1,42 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2019 +// MIT License + +// All cores +#define bit() +#define constrain() +#define DEFAULT +#define DISABLED +#define HIGH +#define INPUT +#define LOW +#define max() +#define min() +#define OUTPUT +#define round() +#define sq() +#define word() +#define bitRead() +#define bitSet() +#define bitClear() +#define bitWrite() +#define interrupts() +#define lowByte() +#define highByte() +#define DEC +#define HEX +#define OCT +#define BIN +#define cbi() +#define sbi() + +// ESP8266 +#define _max() +#define _min() + +// issue #839 +#define BLOCKSIZE +#define CAPACITY + +// catch.hpp mutes several warnings, this file also allows to detect them +#include "ArduinoJson.h" diff --git a/test/Misc/empty.cpp b/test/Misc/empty.cpp deleted file mode 100644 index b1436217..00000000 --- a/test/Misc/empty.cpp +++ /dev/null @@ -1,7 +0,0 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 -// MIT License - -// catch.hpp mutes several warnings, this file allows to detect them - -#include "ArduinoJson.h"