How to enable C++20 support for the ESP32-S3

I’ve seen mixed message in various posts about how to enable this. But the best i can do it have it enable c++2017. (according to __cplusplus) I was trying to enable 20 for support of default struct equality comparisons.

The output looks like:

src/main.cpp:5:63: note: '#pragma message: C++ standard version: 201703L'
    5 | #pragma message "C++ standard version: " STRINGIFY(__cplusplus)
      |
^
src/main.cpp:3:30: note: in definition of macro 'STRINGIFY_HELPER'    
    3 | #define STRINGIFY_HELPER(x) #x
      |                              ^
src/main.cpp:5:42: note: in expansion of macro 'STRINGIFY'
    5 | #pragma message "C++ standard version: " STRINGIFY(__cplusplus)
      |                                          ^~~~~~~~~
src/main.cpp:13:8: error: defaulted 'bool Derp::operator==(const Derp&) const' only available with '-std=c++20' or '-std=gnu++20'
   13 |   bool operator== (const Derp& other) const = default;        
      |        ^~~~~~~~
*** [.pio\build\esp32-s3-devkitm-1\src\main.cpp.o] Error 1

The “trick” is to not use PlatformIO on ESP32 for anything vaguely modern. If you look at the compiler that’s invoked (pio run -v target upload -e $BLABLA) you’ll see that you’re getting GCC8.2 or so, that’s a patched version from 2017. The GNU Compiler team is awesome for implementing things before they’re formally ratified, but their future vision isn’t perfect.

Leave platformio completely if you can as the project is adrift with just a few volunteers left trying to keep it afloat on modern, popular chips like Espressif and Raspberry Pi. If you can’t, at least use a fork that is actively maintained, such as the PIOArduino project. That’ll put you on GCC 14.2, I think, and not last year’s 15, but you get a comfortable amount of 20 (modules remain unsolved) , 23, and even a smattering of 26. Since you’re coding in Arduino, you’ll also need to move to Arduino 3 instead of Arduino 2. I’m pretty sure that’s the default in PIOArduino.

Arduino Migration for old Arduino
https://docs.espressif.com/projects/arduino-esp32/en/latest/migration_guides/2.x_to_3.0.html

If you don’t want to be left behind in the future, probably best to eliminate this long tail of dependencies and just move to ESP-IDF. Some of the biggest IoT open-source efforts got in a logjam after they hitched their trees to PlatformIO and couldn’t keep waiting, so they forked PIOArduino to let development from community get integrated (look at how many contributions there are for ESP32 and Pi here that don’t get merged) and fixes and updates flowing.

1 Like

Thank you very much for your detailed reply.

1 Like