PlatformIO Community

ESP8266 vs ESP32 compiler error

H
I’m not sure if this is the correct forum.
I’m using PlatformIO within VSC and using ESP8266 and ESP32 arduino libraries.

Simply put when I have the following…see example below:

somewhere in the main code I create the object as below…

ObjA newObject(value1, value2, value3, value4);`

The definition of this class looks like below (note the class order of inherited classes and the constructor are different):

    class ObjA : public ObjB, public ObjC, public ObjD
    {
    public:
 // constructor...NOTE: inheritance DOES not match the class definition in terms of order
    ObjA() : ObjB(int value1) : ObjA(int value2) : ObjD(int value3) : ObjC(int value4) 
    {
    }
    .....
    };

In the above case it compiles fine with ESP8266 and with no warnings BUT with ESP32 it fails to compile
The error is:

 error: base 'ObjD' will be initialised after [-Werror=reorder]

However if I change the order of the class definition to match the constructor it compiles fine for ESP32 i.e.

    class ObjA : public ObjB, public ObjC, public ObjD
    {
    public:
 // constructor...inheritance matched the class definition in terms of order
    ObjA() : ObjA(int value1) : ObjB(int value2) : ObjC(int value3) : ObjD(int value4) 
    {
    }
    .....
    };

Anyone with better knowledge of C++ and the compiler know what may be going on ?

I understand that it now compiles without error and without warnings on both platforms, right?

It’s a more recent features that compilers started to check the initialization order. So my guess is (I was too lazy to verify it) that ESP32 and ESP8266 use different compiler versions and/or different settings regarding checks, warnings and what to treat as error.

1 Like

Yes, because for the ESP32 build, g++ and friends are given the -Werror=reorder commandline which elevates the “Warning: reorder” to “Error: reorder” and let the build fail. This is done here (also see https://github.com/espressif/arduino-esp32/blob/master/platform.txt#L20 and https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html).

Thes ESP8266 builder does not activate such a switch. Compare here.

Thus your warning is an error in one case and and a warning in another.

2 Likes

thanks all for replies. I see the issues being:
g++ and friends are given the -Werror=reorder is setup by default for ESP32 and not ESP8266 compiles when using PlatformIO and Arduino.