After the last update, I’ve found that C++17 now seems to be supported for Arduino at ESP-8266 with build_unflags = -std=gnu++11 and build_flags = -std=c++17
At least, I can use features with deconstruction and namespaces:
namespace A::B::C
{
void TestCpp17()
{
auto p = std::pair<int, int>(1, 2);
auto [a, b] = p;
Serial.printf("OK: [%d, %d]", a, b);
}
} // namespace
using namespace A::B::C;
Configuration from build log:
PLATFORM: Espressif 8266 (3.2.0) > WeMos D1 R2 and mini
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
PACKAGES:
- framework-arduinoespressif8266 3.30002.0 (3.0.2)
- tool-esptool 1.413.0 (4.13)
- tool-esptoolpy 1.30000.201119 (3.0.0)
- toolchain-xtensa 2.100300.210717 (10.3.0)
But, unfortunately, I couldn’t achieve the same result for ESP32 in such a simple way with build flags, new syntax features don’t work with errors:
src\main.cpp:4:12: error: expected '{' before '::' token
namespace A::B::C
^
src\main.cpp:4:14: error: 'B' in namespace '::' does not name a type
namespace A::B::C
^
src\main.cpp:16:20: error: 'A::B' has not been declared
using namespace A::B::C;
^
src\main.cpp:16:23: error: 'C' is not a namespace-name
using namespace A::B::C;
^
src\main.cpp:16:24: error: expected namespace-name before ';' token
using namespace A::B::C;
^
src\main.cpp: In function 'void A::setup()':
src\main.cpp:26:15: error: 'TestCpp17' was not declared in this scope
TestCpp17();
^
src\main.cpp: At global scope:
src\main.cpp:31:1: error: expected '}' at end of input
}
^
*** [.pio\build\ESP-32-Dev\src\main.cpp.o] Error 1
Configuration from build log:
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (3.3.2) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
- framework-arduinoespressif32 3.10006.210326 (1.0.6)
- tool-esptoolpy 1.30100.210531 (3.1.0)
- toolchain-xtensa32 2.50200.97 (5.2.0)
So, is it now possible to use C++17 somehow for Arduino and ESP32 or still not yet?