C++17 support for Arduino ESP32

Duplicate of Possible to use C++17. Together with the info in Missing branch #idf-release/v4.0 · Issue #4998 · espressif/arduino-esp32 · GitHub due to Arduino-ESP32 deleting the idf-release/v4.0 branch, one can deduce that

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
build_unflags = -std=gnu++11
build_flags = -std=c++17
; GCC 8.4.0 plus
; Arduino-ESP32 that does not shit
; itself when compiling with C++17
platform_packages =
   toolchain-xtensa32@~2.80400.0
   framework-arduinoespressif32 @ https://github.com/marcovannoord/arduino-esp32.git#idf-release/v4.0
monitor_speed = 115200

is the most minimal way of compiling

#include <Arduino.h>

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;

void setup(){
  Serial.begin(115200);
  TestCpp17();
}
void loop(){}
   framework-arduinoespressif32 @ https://github.com/marcovannoord/arduino-esp32.git#idf-release/v4.0

successfully.

>pio run -t upload -t monitor
...
RAM:   [          ]   4.2% (used 13624 bytes from 327680 bytes)
Flash: [==        ]  16.1% (used 211462 bytes from 1310720 bytes)
Building .pio\build\esp32dev\firmware.bin
..
--- Miniterm on COM4  115200,8,N,1 ---
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ets Jun  8 2016 00:22:57

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1364
load:0x40078000,len:12656
load:0x40080400,len:3512
entry 0x40080624
OK: [1, 2]
--- exit ---

Note that it’ll probably also be possible to compile the new Arduino-ESP32 2.0.0 core version with C++17, however, since Support for the latest Arduino v2.0 · Issue #619 · platformio/platform-espressif32 · GitHub is not resolved yet, it can’t be used with PlatformIO. The previous stable core (1.0.6) does not compile with C++17, the idf-release/v4.0 version does, but it’s of course not the latest 2.0.0 one.

1 Like