Compilation error with Variable Length Array (VLA)
Created by: rswift
Hello,
So far, the library has been a joy to use. I just updated to 5.8.0 and started seeing problems, my code reads:
char probePacket[probePacketLength + 1];
memset(probePacket, 0, probePacketLength + 1);
probeUdp.read(probePacket, probePacketLength);
DynamicJsonBuffer jsonBuffer;
JsonObject& probeJson = jsonBuffer.parseObject(probePacket);
and the error I get is lengthy, I'll include it fully below by the salient but seems to be:
/Users/robert/Documents/Arduino/libraries/ArduinoJson/include/ArduinoJson/JsonBufferBase.hpp:66:15: note: template argument deduction/substitution failed: /Users/robert/Development/Arduino/WiFiTemperatureBroadcast/HallEffectBroadcast/fnProbeStatus.ino:18:63: note: variable-sized array type 'char [(((sizetype)((ssizetype)probePacketLength)) + 1)]' is not a valid template argument JsonObject& probeJson = jsonBuffer.parseObject(probePacket); ^ exit status 1 no matching function for call to 'ArduinoJson::DynamicJsonBufferBaseArduinoJson::DefaultAllocator::parseObject(char [(((sizetype)((ssizetype)probePacketLength)) + 1)])'
If I modify the first line of code to something like:
char probePacket[100 + 1];
there are no compilation errors.
EDIT: I should have said, reverting to 5.7.3 and the problem goes away.
Thanks in advance for any guidance - Robert...
The full compiler error is here:
/Users/robert/Development/Arduino/WiFiTemperatureBroadcast/HallEffectBroadcast/fnProbeStatus.ino: In function 'void updateProbeStatus()': fnProbeStatus:18: error: no matching function for call to 'ArduinoJson::DynamicJsonBufferBaseArduinoJson::DefaultAllocator::parseObject(char [(((sizetype)((ssizetype)probePacketLength)) + 1)])' JsonObject& probeJson = jsonBuffer.parseObject(probePacket); ^ /Users/robert/Development/Arduino/WiFiTemperatureBroadcast/HallEffectBroadcast/fnProbeStatus.ino:18:63: note: candidates are: In file included from /Users/robert/Documents/Arduino/libraries/ArduinoJson/include/ArduinoJson/DynamicJsonBuffer.hpp:10:0, from /Users/robert/Documents/Arduino/libraries/ArduinoJson/include/ArduinoJson.hpp:10, from /Users/robert/Documents/Arduino/libraries/ArduinoJson/include/ArduinoJson.h:8, from /Users/robert/Documents/Arduino/libraries/ArduinoJson/ArduinoJson.h:8, from /Users/robert/Development/Arduino/WiFiTemperatureBroadcast/HallEffectBroadcast/HallEffectBroadcast.ino:48: /Users/robert/Documents/Arduino/libraries/ArduinoJson/include/ArduinoJson/JsonBufferBase.hpp:60:15: note: template ArduinoJson::JsonObject& ArduinoJson::JsonBufferBase::parseObject(const TString&, uint8_t) [with TString = TString; TDerived = ArduinoJson::DynamicJsonBufferBaseArduinoJson::DefaultAllocator] JsonObject &parseObject( ^ /Users/robert/Documents/Arduino/libraries/ArduinoJson/include/ArduinoJson/JsonBufferBase.hpp:60:15: note: template argument deduction/substitution failed: /Users/robert/Development/Arduino/WiFiTemperatureBroadcast/HallEffectBroadcast/fnProbeStatus.ino:18:63: note: variable-sized array type 'char [(((sizetype)((ssizetype)probePacketLength)) + 1)]' is not a valid template argument JsonObject& probeJson = jsonBuffer.parseObject(probePacket); ^ In file included from /Users/robert/Documents/Arduino/libraries/ArduinoJson/include/ArduinoJson/DynamicJsonBuffer.hpp:10:0, from /Users/robert/Documents/Arduino/libraries/ArduinoJson/include/ArduinoJson.hpp:10, from /Users/robert/Documents/Arduino/libraries/ArduinoJson/include/ArduinoJson.h:8, from /Users/robert/Documents/Arduino/libraries/ArduinoJson/ArduinoJson.h:8, from /Users/robert/Development/Arduino/WiFiTemperatureBroadcast/HallEffectBroadcast/HallEffectBroadcast.ino:48: /Users/robert/Documents/Arduino/libraries/ArduinoJson/include/ArduinoJson/JsonBufferBase.hpp:66:15: note: template ArduinoJson::JsonObject& ArduinoJson::JsonBufferBase::parseObject(TString&, uint8_t) [with TString = TString; TDerived = ArduinoJson::DynamicJsonBufferBaseArduinoJson::DefaultAllocator] JsonObject &parseObject( ^ /Users/robert/Documents/Arduino/libraries/ArduinoJson/include/ArduinoJson/JsonBufferBase.hpp:66:15: note: template argument deduction/substitution failed: /Users/robert/Development/Arduino/WiFiTemperatureBroadcast/HallEffectBroadcast/fnProbeStatus.ino:18:63: note: variable-sized array type 'char [(((sizetype)((ssizetype)probePacketLength)) + 1)]' is not a valid template argument JsonObject& probeJson = jsonBuffer.parseObject(probePacket); ^ exit status 1 no matching function for call to 'ArduinoJson::DynamicJsonBufferBaseArduinoJson::DefaultAllocator::parseObject(char [(((sizetype)((ssizetype)probePacketLength)) + 1)])'