Why does this code get through the compiler without a return statement?



  • This must be a real newbie question.

    I have this method declaration in the header (dbaccess.h):
    @static QStringList indexProperties();@

    and this definition in dbaccess.cpp:
    @QStringList DBAccess::indexProperties()
    {
    }@

    ie I've failed to provide return a value. I've just spent ages attempting to debug the problem, before spotting the obvious. Why doesn't the compiler pick up the missing return?



  • With gcc you only get a warning:

    @
    dbaccess.cpp:91: warning: control reaches end of non-void function
    @

    Visual Studio emit something similar if I remember correctly.



  • VS throws an error.
    @
    error C4716: 'AAA::BBB' : must return a value
    @
    Just live tested with VS2008 SP1



  • Obviously depends on the compiler... With gcc, don't forget to set -Wall
    VS2008 does it out of the box



  • Yup, I'm using the MinGW tool chain under Windows 7.

    Live and learn.



  • You can turn warnings into errors in gcc with -Werror switch. You can enable this by adding this to your .pro file:

    @
    QMAKE_CXXFLAGS += -Werror
    @



  • [quote author="florent.revelut" date="1292946918"]VS2008 does it out of the box[/quote] Depends on your warning level just like with gcc, if I recall correctly.



  • [quote author="Franzk" date="1293004949"][quote author="florent.revelut" date="1292946918"]VS2008 does it out of the box[/quote] Depends on your warning level just like with gcc, if I recall correctly.

    [/quote]

    Hi,

    In MSVS it's an error not a warning. I always use default levels: Warning level 3, no warning --> error translation. The MS compilers throw errors for such constructs.


Log in to reply
 

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