cppcheck/lib
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
..
CMakeLists.txt Add option to disable pch since its broken with ccache 2020-06-24 18:41:16 -05:00
analyzerinfo.cpp Code cleanup, __temp__ files are not needed anymore 2020-07-14 16:54:00 +02:00
analyzerinfo.h Update copyright year 2020-06-13 16:37:12 +02:00
astutils.cpp Typos found by running "codespell" (#2846) 2020-10-15 19:24:13 +02:00
astutils.h Fix issue 9711: FP knownConditionTrueFalse for variable modified via pointer (#2813) 2020-09-20 14:27:09 +02:00
bughuntingchecks.cpp Token: add flag for splitted variable declaration with initialization 2020-09-09 16:22:47 +02:00
bughuntingchecks.h Add 'bughuntingchecks' 2020-06-19 13:16:48 +02:00
check.cpp daca: update WRONG_DATA interface 2020-10-03 15:36:02 +02:00
check.h daca: update WRONG_DATA interface 2020-10-03 15:36:02 +02:00
check64bit.cpp Update copyright year 2020-06-13 16:37:12 +02:00
check64bit.h Disable all simplified checks 2019-03-16 09:17:50 +01:00
checkassert.cpp Fix crash in cbmc detected with daca@home 2020-09-24 20:48:26 +02:00
checkassert.h added missing OVERRIDE usage and removed redundant virtual (#2190) 2019-09-20 21:57:16 +02:00
checkautovariables.cpp Fixed #9918 (False positive: autoVariable pointer is NULLed later) 2020-09-28 22:48:57 +02:00
checkautovariables.h Fixed #9918 (False positive: autoVariable pointer is NULLed later) 2020-09-28 22:48:57 +02:00
checkbool.cpp Use ValueFlow for compareBoolExpressionWithInt 2020-06-27 08:13:22 +02:00
checkbool.h Update Copyright year 2020-10-03 09:15:56 +02:00
checkboost.cpp Update copyright year 2020-06-13 16:37:12 +02:00
checkboost.h Disable all simplified checks 2019-03-16 09:17:50 +01:00
checkbufferoverrun.cpp made check.h less heavy (#2633) 2020-05-23 07:16:49 +02:00
checkbufferoverrun.h Update copyright year 2020-05-10 11:16:32 +02:00
checkclass.cpp Fixed #9821 (False positive: Delegating constructor and initialization list) 2020-09-09 18:04:21 +02:00
checkclass.h 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
checkcondition.cpp Another fix for the crash 2020-10-22 06:59:13 +02:00
checkcondition.h made check.h less heavy (#2633) 2020-05-23 07:16:49 +02:00
checkexceptionsafety.cpp Update Copyright year 2020-10-03 09:15:56 +02:00
checkexceptionsafety.h made check.h less heavy (#2633) 2020-05-23 07:16:49 +02:00
checkfunctions.cpp daca: group warnings for prohibited functions 2020-09-27 21:42:07 +02:00
checkfunctions.h Update copyright year 2020-06-13 16:37:12 +02:00
checkinternal.cpp fixed some modernize-loop-convert clang-tidy warnings (#2815) 2020-09-21 19:30:47 +02:00
checkinternal.h Update copyright year 2020-05-10 11:16:32 +02:00
checkio.cpp fixed some modernize-loop-convert clang-tidy warnings (#2815) 2020-09-21 19:30:47 +02:00
checkio.h Update copyright year 2020-06-13 16:37:12 +02:00
checkleakautovar.cpp Refactor: Use visitAstNodes in checkleakautovar 2020-07-20 10:25:00 +02:00
checkleakautovar.h Update copyright year 2020-06-13 16:37:12 +02:00
checkmemoryleak.cpp Fix #9228 (FN common realloc mistake with assignment of NULL) 2020-09-13 21:49:49 +02:00
checkmemoryleak.h made check.h less heavy (#2633) 2020-05-23 07:16:49 +02:00
checknullpointer.cpp Fix issue 737: new check: Dereference end iterator 2020-08-17 16:36:45 -05:00
checknullpointer.h Update copyright year 2020-06-13 16:37:12 +02:00
checkother.cpp Fixed #9929 (False positive: suspicious semicolon after macro) 2020-10-09 20:34:20 +02:00
checkother.h More fixing for #9914. New warning id and warning message when variable expression is explicitly hidden. 2020-09-26 13:49:47 +02:00
checkpostfixoperator.cpp Update copyright year 2020-06-13 16:37:12 +02:00
checkpostfixoperator.h Disable all simplified checks 2019-03-16 09:17:50 +01:00
checksizeof.cpp Update copyright year 2020-06-13 16:37:12 +02:00
checksizeof.h Disable all simplified checks 2019-03-16 09:17:50 +01:00
checkstl.cpp Remove known conditions 2020-09-08 12:39:27 -05:00
checkstl.h Improve check: check for known empty containers passed to algorithms (#2768) 2020-09-02 07:11:23 +02:00
checkstring.cpp Refactor: Use visitAstNodes in checkstring 2020-07-20 10:25:00 +02:00
checkstring.h Checkstring fixes (#1783) 2019-04-06 06:54:38 +02:00
checktype.cpp Refactor: Simplify checkSignConversion 2020-07-20 11:16:56 +02:00
checktype.h Clarify signConversion warning message 2019-08-05 12:41:08 +02:00
checkuninitvar.cpp Refactor: Use visitAstNodes in checkuninitvar 2020-07-20 11:03:52 +02:00
checkuninitvar.h made check.h less heavy (#2633) 2020-05-23 07:16:49 +02:00
checkunusedfunctions.cpp made check.h less heavy (#2633) 2020-05-23 07:16:49 +02:00
checkunusedfunctions.h Silence unused variable warning (#2223) 2019-09-27 08:19:45 +02:00
checkunusedvar.cpp Fixed #9707 (False positive: unreadVariable, union) 2020-10-02 20:22:22 +02:00
checkunusedvar.h Update copyright year 2020-05-10 11:16:32 +02:00
checkvaarg.cpp made check.h less heavy (#2633) 2020-05-23 07:16:49 +02:00
checkvaarg.h added missing OVERRIDE usage and removed redundant virtual (#2190) 2019-09-20 21:57:16 +02:00
clangimport.cpp Clang import; fixed ast for function call with multiple arguments 2020-10-09 07:54:16 +02:00
clangimport.h Clang import; Rename files/namespace 2020-01-10 16:29:06 +01:00
config.h Replace noreturn with macro 2020-06-29 15:54:51 -05:00
cppcheck.cpp fixed some modernize-loop-convert clang-tidy warnings (#2815) 2020-09-21 19:30:47 +02:00
cppcheck.h 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
cppcheck.natvis Fixed Visual Studio Natvis file after recent refactoring (#1299) 2018-07-09 08:27:26 +02:00
cppcheck.vcxproj Try to fix compilation with cppcheck.vcxproj 2020-06-20 09:47:35 +02:00
cppcheck.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
ctu.cpp astyle formatting 2020-07-23 10:09:06 +02:00
ctu.h Update copyright year 2020-06-13 16:37:12 +02:00
errorlogger.cpp Fix output when note contains 2020-09-25 19:04:22 +02:00
errorlogger.h Rename 'cppcheckID' to 'hash' 2020-07-21 11:27:03 +02:00
errortypes.cpp astyle formatting 2020-05-23 07:30:22 +02:00
errortypes.h made check.h less heavy (#2633) 2020-05-23 07:16:49 +02:00
exprengine.cpp Bug hunting; Better handling of constant 2020-10-08 17:24:35 +02:00
exprengine.h exprengine: Use and tweak ExprEngine::ArrayValue::MAXSIZE 2020-10-04 11:21:13 +02:00
forwardanalyzer.cpp Fix issue 9898: false positive: knownConditionTrueFalse (#2806) 2020-09-14 18:43:11 +02:00
forwardanalyzer.h astyle formatting 2020-09-11 08:51:12 +02:00
importproject.cpp TestImportProject: Use raw strings 2020-09-06 16:00:19 +02:00
importproject.h Fix false skipping of folder-seperator (#2749) 2020-09-06 15:35:14 +02:00
lib.pri Add 'bughuntingchecks' 2020-06-19 13:16:48 +02:00
library.cpp Library: Refactoring <alloc> init attribute 2020-06-28 21:01:43 +02:00
library.h Library: Refactoring <alloc> init attribute 2020-06-28 21:01:43 +02:00
matchcompiler.h
mathlib.cpp made check.h less heavy (#2633) 2020-05-23 07:16:49 +02:00
mathlib.h Update copyright year 2019-02-09 07:24:06 +01:00
path.cpp Various clang-tidy fixes (#2192) 2019-09-25 15:25:19 +02:00
path.h Update copyright year 2019-02-09 07:24:06 +01:00
pathanalysis.cpp Refactorization: Moved code from header to source 2020-05-19 08:35:12 +02:00
pathanalysis.h made check.h less heavy (#2633) 2020-05-23 07:16:49 +02:00
pathmatch.cpp Update Copyright year 2020-10-03 09:15:56 +02:00
pathmatch.h Updated copyright year 2018-10-13 18:20:31 +02:00
pcrerules.pri
platform.cpp use range loops / constness (#2181) 2019-09-19 20:29:33 +02:00
platform.h Update copyright year 2020-05-10 11:16:32 +02:00
precompiled.h Visual Studio: Use new files precompiled.h with several common includes for core and testrunner. 2020-05-29 12:16:04 +02:00
preprocessor.cpp Suppressions: Add special case for backwards compatibility. suppression comment after a {. 2020-10-02 18:56:26 +02:00
preprocessor.h Update Copyright year 2020-10-03 09:15:56 +02:00
programmemory.cpp FIx issue 9895: ValueFlow: Wrong known value below function call with reference parameter 2020-09-11 16:03:57 -05:00
programmemory.h FIx issue 9895: ValueFlow: Wrong known value below function call with reference parameter 2020-09-11 16:03:57 -05:00
settings.cpp extended the --clang command-line option so you can specify a custom … (#2734) 2020-09-06 07:46:51 +02:00
settings.h extended the --clang command-line option so you can specify a custom … (#2734) 2020-09-06 07:46:51 +02:00
standards.h Update Copyright year 2020-10-03 09:15:56 +02:00
suppressions.cpp Suppressions: Add special case for backwards compatibility. suppression comment after a {. 2020-10-02 18:56:26 +02:00
suppressions.h Fix Cppcheck warning 2020-10-02 19:35:24 +02:00
symboldatabase.cpp Fix #9647: Set correct enum value (#2856) 2020-10-22 07:45:04 +02:00
symboldatabase.h Fixed #9707 (False positive: unreadVariable, union) 2020-10-02 20:22:22 +02:00
templatesimplifier.cpp fix daca insighttoolkit crash in template simplifier (#2826) 2020-09-28 22:51:13 +02:00
templatesimplifier.h Resolve C4800 Visual C++ warning 2019-12-16 18:11:12 +03:00
timer.cpp Check for JSON error when parsing addon .json files + fixes (#2374) 2019-11-20 15:37:09 +01:00
timer.h Check for JSON error when parsing addon .json files + fixes (#2374) 2019-11-20 15:37:09 +01:00
token.cpp Clang import; fixed ast for function call with multiple arguments 2020-10-09 07:54:16 +02:00
token.h Token: add flag for splitted variable declaration with initialization 2020-09-09 16:22:47 +02:00
tokenize.cpp Fix #9647: Set correct enum value (#2856) 2020-10-22 07:45:04 +02:00
tokenize.h Fixed #9266 (handle operator() better) 2020-09-06 21:02:06 +02:00
tokenlist.cpp Clang import testing: Compare AST 2020-10-04 11:27:31 +02:00
tokenlist.h Fixed Token::isKeyword: Actually set this flag to a reasonable value in all code paths 2020-05-19 13:47:25 +02:00
utils.cpp Refactorization: Moved code from header to source 2020-05-19 08:35:12 +02:00
utils.h Fixed compilation (next attempt): Added more missing includes 2020-05-19 08:53:38 +02:00
valueflow.cpp Fix #9647: Set correct enum value (#2856) 2020-10-22 07:45:04 +02:00
valueflow.h astyle formatting 2020-09-10 08:02:45 +02:00
valueptr.h Update copyright year 2020-05-10 11:16:32 +02:00
version.h set version 2.2.99 2020-10-03 13:54:17 +02:00
version.rc