Why does this code get through the compiler without a return statement?
-
wrote on 21 Dec 2010, 15:21 last edited by
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?
-
wrote on 21 Dec 2010, 15:43 last edited by
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.
-
wrote on 21 Dec 2010, 15:45 last edited by
VS throws an error.
@
error C4716: 'AAA::BBB' : must return a value
@
Just live tested with VS2008 SP1 -
wrote on 21 Dec 2010, 15:55 last edited by
Obviously depends on the compiler... With gcc, don't forget to set -Wall
VS2008 does it out of the box -
wrote on 21 Dec 2010, 16:05 last edited by
Yup, I'm using the MinGW tool chain under Windows 7.
Live and learn.
-
wrote on 21 Dec 2010, 16:21 last edited by
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
@ -
wrote on 22 Dec 2010, 08:02 last edited by
[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.
-
wrote on 22 Dec 2010, 08:14 last edited by
[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.
1/8