cppcheck/test
Rikard Falkeborn d7a8e25d92
Fix #9647: Set correct enum value (#2856)
* Tokenize: Set varId for variables in enum

Set varIds in enum values. It was previously disabled in 5119ae84b8
to avoid issues with enums named the same as global variables. Take care
to only set varids to variables used to set the value of an enumerator,
not the enumerator itself. This is somewhat complicated by the fact that
at the time this happens, astOperand1(), astOperand2(), astParent() etc
are not set. The current implementation is not perfect, for example in
the code below, y will not have a varid set, but x and z will. This is
deemed sufficient for now.

            int x, y, z;
            enum E { a = f(x, y, z); };

* Fix #9647: Value of enums with variables as init values

C++ allows enum values to be set using constexprs, which cppcheck did
not handle before. To solve this, add a new pass to valueflow to update
enum values after global consts have been processed. In order to do so,
I moved all settings of enum values to valueflow. After setting the enum
values, we need another call to valueFlowNumber() to actually set users
of the enums.

There is still room for improvements, since each pass of
valueFlowGlobalConstVar() and valueFlowEnumValue() only sets variables
that are possible to set directly, and not if setting the value of a
variable allows us to set the value of another. For example

	constexpr int a = 5;
	constexpr int b = a + 5;
	enum E { X = a };
	constexpr E e = X;

Here both b and e will not have their values set, even though cppcheck
should be possible to figure out their values. That's for another PR
though.

This was tested by running test-my-pr.py with 500 packages. The only
difference was one error message in fairy-stockfish_11.1, where cppcheck
now printed the correct size of an array instead of 2147483648 which I
assume is some kind of default value. In that package, using a constexpr
when setting enum values is common, but as mentioned, there was no
change in the number of warnings.
2020-10-22 07:45:04 +02:00
..
bug-hunting Bug hunting: Add test case for CVE-2019-12977. Passing uninitialized struct to function 2020-07-13 20:42:53 +02:00
cfg Astyle formatting code [ci skip] 2020-10-01 08:33:16 +02:00
cli Clang import; fixed ast for function call with multiple arguments 2020-10-09 07:54:16 +02:00
synthetic
testsuites Rename test cases, 'verification' was renamed to 'bug hunting' 2020-01-15 21:11:04 +01:00
CMakeLists.txt disabled precompiled headers in CMake as they currently do not emit any compiler warnings / adjusted check for precompiled header (#2820) 2020-09-23 07:51:21 +02:00
options.cpp Update Copyright 2019-06-29 07:49:14 +02:00
options.h Update Copyright 2019-06-29 07:49:14 +02:00
precompiled.h Update copyright year 2020-06-13 16:37:12 +02:00
redirect.h Update copyright year 2020-05-10 11:16:32 +02:00
test.cxx
test64bit.cpp
testassert.cpp Fix crash in cbmc detected with daca@home 2020-09-24 20:48:26 +02:00
testastutils.cpp optimized non-matchcompiled Token::simpleMatch() a bit (#2640) 2020-05-26 20:13:56 +02:00
testautovariables.cpp Fix issue 9939: False positive: Reference to temporary returned (static variable) (#2840) 2020-10-06 09:16:54 +02:00
testbool.cpp Update Copyright year 2020-10-03 09:15:56 +02:00
testboost.cpp Update copyright year 2020-05-10 11:16:32 +02:00
testbufferoverrun.cpp Fix some false positive in loop forward analysis (#2669) 2020-06-05 18:06:03 +02:00
testbughuntingchecks.cpp Bug hunting: Avoid uninit struct member false positives 2020-09-09 18:26:04 +02:00
testcharvar.cpp Remove test case, ValueFlow will truncate and sign-extend values 2019-05-01 19:33:47 +02:00
testclangimport.cpp Fix TestClangImport 2020-10-06 23:19:32 +02:00
testclass.cpp Fixed #9821 (False positive: Delegating constructor and initialization list) 2020-09-09 18:04:21 +02:00
testcmdlineparser.cpp Revert "Cleanup: Removed Tokenizer::simplifyTokenList2. As a side-effect, rules for "simple" token list are now executed on normal token list." (#2666) 2020-05-30 11:23:22 +02:00
testcondition.cpp Crash: Add regression test 2020-10-22 07:40:06 +02:00
testconstructors.cpp Clarify inconclusive uninitMemberVar warning in copy constructors, it's in general a good idea to copy all the data. 2020-08-05 13:57:40 +02:00
testcppcheck.cpp made check.h less heavy (#2633) 2020-05-23 07:16:49 +02:00
testerrorlogger.cpp Add cppcheck-id for warnings. To start with it's a simple id that changes when file is changed. 2020-07-14 22:30:42 +02:00
testexceptionsafety.cpp Use 'normal' checking instead of 'simplified' 2019-03-16 07:19:48 +01:00
testexprengine.cpp Bug hunting; Better handling of constant 2020-10-08 17:24:35 +02:00
testfilelister.cpp
testfunctions.cpp Fix testrunner fail, introduced by latest commit 2020-06-12 09:18:16 +02:00
testgarbage.cpp Fixed crash on garbage code: comparisson with an empty second operand 2020-07-18 07:02:12 +03:00
testimportproject.cpp ImportProject: Add test case 2020-09-06 16:08:42 +02:00
testincompletestatement.cpp Avoid constStatement false positives for 'foo() || x=5'. Found in daca@home. 2020-09-29 13:35:39 +02:00
testinternal.cpp Update copyright year 2020-05-10 11:16:32 +02:00
testio.cpp Update test. An inconclusive warning message is now shown. 2020-06-14 22:57:50 +02:00
testleakautovar.cpp Fix #9635 (FP: Memory leak with comma operator in if-statement) 2020-07-09 21:31:43 +02:00
testlibrary.cpp Library: Refactoring <alloc> init attribute 2020-06-28 21:01:43 +02:00
testmathlib.cpp Update copyright year 2020-05-10 11:16:32 +02:00
testmemleak.cpp Fix #9228 (FN common realloc mistake with assignment of NULL) 2020-09-13 21:49:49 +02:00
testnullpointer.cpp Fix issue 9842: ValueFlow: wrong handling of ?, seems to think that the whole expression is a condition (#2821) 2020-09-23 07:45:03 +02:00
testoptions.cpp Allow multiple test case arguments to testrunner (#1755) 2019-03-26 20:28:40 +01:00
testother.cpp Fixed #9929 (False positive: suspicious semicolon after macro) 2020-10-09 20:34:20 +02:00
testpath.cpp
testpathmatch.cpp Update copyright year 2020-05-10 11:16:32 +02:00
testplatform.cpp Update copyright year 2020-05-10 11:16:32 +02:00
testpostfixoperator.cpp Valid code for incrementing raw pointer (#2418) 2019-12-03 18:33:05 +01:00
testpreprocessor.cpp Update copyright year 2020-05-10 11:16:32 +02:00
testrunner.cpp Update Copyright 2019-06-29 07:49:14 +02:00
testrunner.vcxproj Visual Studio: Use new files precompiled.h with several common includes for core and testrunner. 2020-05-29 12:16:04 +02:00
testrunner.vcxproj.filters Visual Studio: Use new files precompiled.h with several common includes for core and testrunner. 2020-05-29 12:16:04 +02:00
testsamples.cpp made check.h less heavy (#2633) 2020-05-23 07:16:49 +02:00
testsimplifytemplate.cpp fix #9886 (Hang in TemplateSimplifier (gcc/gcc/testsuite/g++.dg/cpp0x/decltype34.C)) 2020-09-10 14:47:59 -04:00
testsimplifytokens.cpp Revert "Cleanup: Removed Tokenizer::simplifyTokenList2. As a side-effect, rules for "simple" token list are now executed on normal token list." (#2666) 2020-05-30 11:23:22 +02:00
testsimplifytypedef.cpp Clang import testing: Compare AST 2020-10-04 11:27:31 +02:00
testsimplifyusing.cpp Simplify empty anonymous namespaces. (#2673) 2020-06-07 13:49:04 +02:00
testsizeof.cpp Optimization: Reduced peak memory usage (30% in my test case) by immediately deleting simplecpp::TokenList while creating the cppcheck TokenList. 2020-05-19 12:08:17 +02:00
teststl.cpp Fix issue 9907: False positive: knownEmptyContainer after function call with :: (#2814) 2020-09-20 22:37:28 +02:00
teststring.cpp Update copyright year 2020-06-13 16:37:12 +02:00
testsuite.cpp Update copyright year 2020-06-13 16:37:12 +02:00
testsuite.h made check.h less heavy (#2633) 2020-05-23 07:16:49 +02:00
testsuppressions.cpp Add support for comments at end of suppression in suppression files (#2736) 2020-08-20 21:49:07 +02:00
testsymboldatabase.cpp Fix #9647: Set correct enum value (#2856) 2020-10-22 07:45:04 +02:00
testthreadexecutor.cpp
testtimer.cpp
testtoken.cpp Fixed #8506 (CPPCheck printing invalid characters in output) 2020-09-04 20:43:54 +02:00
testtokenize.cpp Clang import testing: Compare AST 2020-10-04 11:27:31 +02:00
testtokenlist.cpp Fixed Token::isKeyword: Actually set this flag to a reasonable value in all code paths 2020-05-19 13:47:25 +02:00
testtype.cpp Refactor: Simplify checkSignConversion 2020-07-20 11:16:56 +02:00
testuninitvar.cpp Fix issue 9855: false positive: uninitvar (#2754) 2020-08-26 07:02:15 +02:00
testunusedfunctions.cpp TestSuite: The ASSERT and ASSERT_EQUALS will now stop executing the test case upon failure. This can be used to avoid extra guard logic in tests. 2019-09-16 06:34:45 +02:00
testunusedprivfunc.cpp Update copyright year 2020-06-13 16:37:12 +02:00
testunusedvar.cpp Fixed #9707 (False positive: unreadVariable, union) 2020-10-02 20:22:22 +02:00
testutils.cpp Update copyright year 2020-05-10 11:16:32 +02:00
testutils.h Update copyright year 2020-06-13 16:37:12 +02:00
testvaarg.cpp Disable all simplified checks 2019-03-16 09:17:50 +01:00
testvalueflow.cpp Fix issue 9945: FP: containerOutOfBounds (#2845) 2020-10-22 07:41:52 +02:00
testvarid.cpp Fix #9647: Set correct enum value (#2856) 2020-10-22 07:45:04 +02:00