Sam3x : witch c++ version PIO use?


I use the arduino DUE for quite some time, but more recently on PIO. But to try something, I but a [[nodiscard]] atribute to a function to see the error result. But to my surprise, it work. But this is a c++14 feature. And tried the same function in arduino IDE and get there the error of c++11, that the attibute is ignore (more expected).

Is PIO use another SAM3x compiler then arduino use ?


1 Like

PlatformIO uses

 - toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)

while the Arduino core currently uses

which is however subject to change

If you want to try C++14 features, you must unset the default -std=gnu++11 switch and replace ith with c++14. As can be seen in build_flag and build_unflags docs, write in the platformio.ini

build_unflags = -std=gnu++11
build_flags = -std=c++14

So without that, for the code

void setup()  {}

you’re getting

Compiling .pio\build\due\src\main.cpp.o
src\main.cpp:4:12: warning: 'nodiscard' attribute applied to 'void setup()' with void return type [-Wattributes]
 void setup() {

and with it, no error at all, and in the “Verbose Build” you can see the invocation being arm-none-eabi-g++ -o .pio\build\due\src\main.cpp.o -c -std=c++14 -fno-rtti [...].

1 Like

Good info about the flag that I didn’t knew.

It is not that I so want to use c++14 feature (may be one day…), but that I was very surprise that nodiscard works on PIO, because in verbose , it is said it is compiling c++11…

Is that some feature of ++14 have been introduce before by peace ?

I could now see that the version differ from the arduino version (I add once have to use SAMD compiler for a DUE sketch because of a bug…) but I did not find what outside bugfix are change between them…