Fixed naming conflict with "CAPACITY" (issue #839)

This commit is contained in:
Benoit Blanchon
2019-03-01 18:11:27 +01:00
parent 136ee0d576
commit 91dd45c387
5 changed files with 52 additions and 16 deletions

View File

@ -7,6 +7,7 @@ HEAD
* Fixed warning "unused variable" with GCC 4.4 (issue #912) * Fixed warning "unused variable" with GCC 4.4 (issue #912)
* Fixed warning "cast increases required alignment" (issue #914) * Fixed warning "cast increases required alignment" (issue #914)
* Fixed warning "conversion may alter value" (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) * Muted warning "will change in GCC 7.1" (issue #914)
* Added a clear error message for `StaticJsonBuffer` and `DynamicJsonBuffer` * Added a clear error message for `StaticJsonBuffer` and `DynamicJsonBuffer`
* Marked ArduinoJson.h as a "system header" * Marked ArduinoJson.h as a "system header"

View File

@ -8,28 +8,28 @@
namespace ARDUINOJSON_NAMESPACE { namespace ARDUINOJSON_NAMESPACE {
template <size_t CAPACITY> template <size_t desiredCapacity>
class StaticJsonDocument : public JsonDocument { class StaticJsonDocument : public JsonDocument {
static const size_t ACTUAL_CAPACITY = static const size_t _capacity =
AddPadding<Max<1, CAPACITY>::value>::value; AddPadding<Max<1, desiredCapacity>::value>::value;
public: public:
StaticJsonDocument() : JsonDocument(_buffer, ACTUAL_CAPACITY) {} StaticJsonDocument() : JsonDocument(_buffer, _capacity) {}
StaticJsonDocument(const StaticJsonDocument& src) StaticJsonDocument(const StaticJsonDocument& src)
: JsonDocument(_buffer, ACTUAL_CAPACITY) { : JsonDocument(_buffer, _capacity) {
set(src); set(src);
} }
template <typename T> template <typename T>
StaticJsonDocument(const T& src, StaticJsonDocument(const T& src,
typename enable_if<IsVisitable<T>::value>::type* = 0) typename enable_if<IsVisitable<T>::value>::type* = 0)
: JsonDocument(_buffer, ACTUAL_CAPACITY) { : JsonDocument(_buffer, _capacity) {
set(src); set(src);
} }
// disambiguate // disambiguate
StaticJsonDocument(VariantRef src) : JsonDocument(_buffer, ACTUAL_CAPACITY) { StaticJsonDocument(VariantRef src) : JsonDocument(_buffer, _capacity) {
set(src); set(src);
} }
@ -45,7 +45,7 @@ class StaticJsonDocument : public JsonDocument {
} }
private: private:
char _buffer[ACTUAL_CAPACITY]; char _buffer[_capacity];
}; };
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE

View File

@ -3,7 +3,7 @@
# MIT License # MIT License
add_executable(MiscTests add_executable(MiscTests
empty.cpp conflicts.cpp
FloatParts.cpp FloatParts.cpp
StringWriter.cpp StringWriter.cpp
TypeTraits.cpp TypeTraits.cpp

42
test/Misc/conflicts.cpp Normal file
View File

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

View File

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