cppcheck/test
rikardfalkeborn 869e4ba6ab Add check for return value of boolean function (#1451)
* Add check for return value of boolean function

The rule for converting an integer to a boolean is that 0 is mapped to
false and everything else is mapped to true. There is nothing wrong with
the following code (according to the standards):

    bool f()
    {
        return -1;
    }

and neither gcc nor clang will warn about it. However, it's a bit
confusing. This commit adds a check that warns when a value other than 0
or 1 is returned from a boolean function (similar to the existing check
that functions with boolean arguments are only passed 0 or 1). Since the
code is perfectly legal, set the severity to "Style".

* Use early continue and remove some braces

* Add testcase with multiple returns

* Avoid null pointer dereference in case of return without operand

* Skip lambdas

Add TODO-test cases that shows FPs when the return type of lambdas are
specified explicitly (this is a problem with findLambdaEndToken).

* Enable testcases
2018-11-01 11:08:16 +01:00
..
cfg Fix compile error in test code 2018-10-28 21:36:28 +01:00
synthetic
CMakeLists.txt
options.cpp
options.h
redirect.h
test.cxx
test64bit.cpp Updated copyright year for modified files 2018-06-10 22:07:21 +02:00
testassert.cpp Updated copyright year for modified files 2018-06-10 22:07:21 +02:00
testastutils.cpp findLambdaEndToken handle explicit type (#1458) 2018-10-31 12:36:08 +01:00
testautovariables.cpp Fix issue 8740: Add a pass to check for valid operators (#1372) 2018-09-08 21:10:34 +02:00
testbool.cpp Add check for return value of boolean function (#1451) 2018-11-01 11:08:16 +01:00
testboost.cpp Updated copyright year for modified files 2018-06-10 22:07:21 +02:00
testbufferoverrun.cpp insecureCmdLineArgs: Fixed FN in case strdup() copies argv[]. (#1438) 2018-10-19 11:04:15 +02:00
testcharvar.cpp Updated copyright year for modified files 2018-06-10 22:07:21 +02:00
testclass.cpp Fixed #8693 (Template specialization: Constructor detected as normal … (#1418) 2018-10-14 16:57:07 +02:00
testcmdlineparser.cpp Improved const correctness of local variables. (#1396) 2018-09-24 15:08:16 +02:00
testcondition.cpp Fix FPs with return conditions (#1455) 2018-10-31 09:47:48 +01:00
testconstructors.cpp Remove header tests from testconstructors, because they were invalid (using preprocessor directive) 2018-10-26 07:03:15 +02:00
testcppcheck.cpp Fix override warnings. (#1234) 2018-05-15 16:37:40 +02:00
testerrorlogger.cpp --suppress on line 0 (#1354) 2018-09-18 12:58:14 +02:00
testexceptionsafety.cpp Updated copyright year for modified files 2018-06-10 22:07:21 +02:00
testfilelister.cpp Updated copyright year for modified files 2018-06-10 22:07:21 +02:00
testfiles.pri
testfunctions.cpp Fix false positive: Invalid string argument with array (#1439) 2018-10-19 07:48:47 +02:00
testgarbage.cpp Fix issue 8757: Throw syntax error on invalid code (#1378) 2018-10-28 17:17:53 +01:00
testimportproject.cpp Updated copyright year for modified files 2018-06-10 22:07:21 +02:00
testincompletestatement.cpp Updated copyright year for modified files 2018-06-10 22:07:21 +02:00
testinternal.cpp Updated copyright year for modified files 2018-06-10 22:07:21 +02:00
testio.cpp Fix override warnings. (#1234) 2018-05-15 16:37:40 +02:00
testleakautovar.cpp Fixed #8794 - Memory leak false positive triggered by !(x != NULL) (#1450) 2018-10-26 06:21:45 +02:00
testlibrary.cpp Rename Library::isargvalid() 2018-07-15 23:05:48 +02:00
testmathlib.cpp Improved const correctness of local variables. (#1396) 2018-09-24 15:08:16 +02:00
testmemleak.cpp Fix FP with fclose after comma (#7525) (#1407) 2018-10-01 11:58:27 +02:00
testnullpointer.cpp Updated copyright year for modified files 2018-06-10 22:07:21 +02:00
testoptions.cpp Updated copyright year for modified files 2018-06-10 22:07:21 +02:00
testother.cpp Enable checking duplicate expressions across associative operators (#1445) 2018-10-21 07:09:20 +02:00
testpath.cpp Updated copyright year for modified files 2018-06-10 22:07:21 +02:00
testpathmatch.cpp Updated copyright year for modified files 2018-06-10 22:07:21 +02:00
testplatform.cpp Fix override warnings. (#1234) 2018-05-15 16:37:40 +02:00
testpostfixoperator.cpp Fix override warnings. (#1234) 2018-05-15 16:37:40 +02:00
testpreprocessor.cpp Fixed handling of macros with known value defined in header file in configuration splitting (#8404) 2018-10-08 16:38:47 +02:00
testrunner.cpp Updated copyright year 2018-10-13 18:20:31 +02:00
testrunner.vcxproj
testrunner.vcxproj.filters
testsamples.cpp Improved const correctness of local variables. (#1396) 2018-09-24 15:08:16 +02:00
testsimplifytemplate.cpp Fixed #8798 (template simplifier: wrong simpifications for namespaces) (#1452) 2018-10-26 14:20:13 +02:00
testsimplifytokens.cpp Fixed #8796 (Tokenizer::simplifyCompoundAssignment: Wrong simplification of return) 2018-10-20 21:33:43 +02:00
testsimplifytypedef.cpp Tokenizer::simplifyTypedef: Fix bug with arrays 2018-10-21 21:15:34 +02:00
testsizeof.cpp Fix override warnings. (#1234) 2018-05-15 16:37:40 +02:00
teststl.cpp astyle formatting 2018-10-18 20:08:32 +02:00
teststring.cpp Fix wrong message 2018-08-12 08:01:15 +02:00
testsuite.cpp CheckStl: rewrite and refactor out of bounds checker 2018-08-11 11:40:48 +02:00
testsuite.h Improved const correctness of local variables. (#1396) 2018-09-24 15:08:16 +02:00
testsuppressions.cpp Fixed compiler warning from VS2017: testsuppressions.cpp(450): warning C4458: declaration of 'errmsg' hides class member. (#1397) 2018-09-25 17:19:25 +02:00
testsymboldatabase.cpp Fixed #8798 (template simplifier: wrong simpifications for namespaces) (#1452) 2018-10-26 14:20:13 +02:00
testthreadexecutor.cpp Updated copyright year for modified files 2018-06-10 22:07:21 +02:00
testtimer.cpp Fix testrunner compiling 2018-06-16 22:28:14 +02:00
testtoken.cpp Improved const correctness of local variables. (#1396) 2018-09-24 15:08:16 +02:00
testtokenize.cpp findLambdaEndToken handle explicit type (#1458) 2018-10-31 12:36:08 +01:00
testtokenlist.cpp Updated copyright year for modified files 2018-06-10 22:07:21 +02:00
testtype.cpp Improved const correctness of local variables. (#1396) 2018-09-24 15:08:16 +02:00
testuninitvar.cpp Ticket #8734: Skip static member variables in CheckUninitVar. (#1388) 2018-09-22 16:52:34 +02:00
testunusedfunctions.cpp Fixed #8677 (False positive: unused method) 2018-08-08 11:31:35 +02:00
testunusedprivfunc.cpp Updated copyright year for modified files 2018-06-10 22:07:21 +02:00
testunusedvar.cpp Updated copyright year for modified files 2018-06-10 22:07:21 +02:00
testutils.h Updated copyright year for modified files 2018-06-10 22:07:21 +02:00
testvaarg.cpp Updated copyright year for modified files 2018-06-10 22:07:21 +02:00
testvalueflow.cpp ValueFlow: Improve containerSize handling of string like classes 2018-10-28 19:14:00 +01:00
testvarid.cpp Fixed #8664 (setVarId: Wrongly set varid for lambda argument) 2018-10-07 20:40:59 +02:00