Should I be concerned about "is a C++11 extension"?



  • Newbie here

    I am seeing the following warnings during compile. It still compiles however, and seems to run okay. Should I be concerned? Should I change my code to avoid this? Will I have problems during deployment?

    In file included from ../project1/mainwindow.cpp:1:
    ../project1/mainwindow.h:65:31: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
        const int DIALOG_REGISTER = 0;
                                  ^
    ../project1/mainwindow.h:66:27: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
        const int DIALOG_HELP = 1;
                              ^
    ../project1/mainwindow.cpp:400:29: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
        for(const QString &sLine: asStyle) {
                                ^
    ../project1/mainwindow.cpp:434:26: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
        for (const QString &k: settings.childKeys()) {
    


  • @maximo said:

    Should I be concerned? Should I change my code to avoid this? Will I have problems during deployment?

    The compiler is telling you that your code uses some C++11 extensions (there's a warning enabled for that).
    You have to change your code only if you want build your code with old compilers not supporting this standard. If is not the case you can also safely remove the warning flag.

    As general rule, IMO, use C++11 if you can.


  • Qt Champions 2016

    Hi

    You should always try to remove all warning. (IMO)

    do you have
    CONFIG +=C++11
    in .pro
    file ?
    (this enable c++ 11)

    Also, it think you did
    class SomeClass {
    int A=10; <---- old compilers wont allow.
    };



  • @mrjj He said tho code build and run so C++11 is enabled. The warning is generated by some compiler option

    @maximo Which compiler are you using? Which flags do you pass to it?


  • Moderators

    @mcosta C++11 is not enabled. The warning says that he is using a C++11 extension i.e. he's using C++03 with that feature enabled as an extension.

    The best solution to avoid this warning is to add CONFIG += C++11 to the .pro file to enable proper C++11 mode, instead of using extensions with earlier standard version (which is sadly still the default for clang and gcc).



  • @mcosta I'm using the XCode on OSX in this case.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.