'getOrAddElement': is not a member of ElementProxy::JsonDocument &>' (reopened issue)
Created by: ewaldc
- short description of the problem
This error is generated when compiling
src/extras/tests/ElementProxy/subscript.cpp
- target platform Windows 10 x64, AJ 6.15.2 (GitHub master)
- compiler model and version Microsoft Visual Studio Enterprise 2017 Version 15.9.24 +28307.1177 Microsoft Visual C++ 2017
- MVCE (https://stackoverflow.com/help/mcve)
#include <ArduinoJson.h>
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
TEST_CASE("MemberProxy::operator[]") {
DynamicJsonDocument doc(4096);
ElementProxy<JsonDocument&> ep = doc[1];
SECTION("set member") {
ep["world"] = 42;
REQUIRE(doc.as<std::string>() == "[null,{\"world\":42}]");
}
SECTION("set element") {
ep[2] = 42; // ---> **error is here**
REQUIRE(doc.as<std::string>() == "[null,[null,null,42]]");
}
}
- compiler output Error C2039 'getOrAddElement': is not a member of 'ArduinoJson6152_1100000::ElementProxy<ArduinoJson6152_1100000::JsonDocument &>' ElementProxyTest c:\users\ewald\documents\visual studio 2017\projects\openhabesp_test\src\arduinojson\array\elementproxy.hpp 163
As I was validating my 5.x port for relocatable VariantSlot onto v6.x, I stumbled on this test that refused to compile. When substituted for the original AJ 6.15.2/Head, it seems the compiler generates the same error.
The problem is solved by adding the following lines here
FORCE_INLINE VariantRef getOrAddElement(size_t index) const {
return getOrAddUpstreamElement().getOrAddElement(index);
Apologies for the extra time taken. I had to redo the port to 6.15.2 as I was unable to keep the 200 test nodes alive on 6.15.1 for a week. Somehow it all works OK in 6.15.2, but that took a bit more time to port (e.g. the new way to implement VariantCompare using the Visitor was a bit of a challenge).
Could you reopen this issue?