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
checkassert.cpp Fix crash in cbmc detected with daca@home 2020-09-24 20:48:26 +02:00
checkassert.h
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
checkbufferoverrun.cpp
checkbufferoverrun.h
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
checkexceptionsafety.cpp Update Copyright year 2020-10-03 09:15:56 +02:00
checkexceptionsafety.h
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
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
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
checksizeof.cpp Update copyright year 2020-06-13 16:37:12 +02:00
checksizeof.h
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
checktype.cpp Refactor: Simplify checkSignConversion 2020-07-20 11:16:56 +02:00
checktype.h
checkuninitvar.cpp Refactor: Use visitAstNodes in checkuninitvar 2020-07-20 11:03:52 +02:00
checkuninitvar.h
checkunusedfunctions.cpp
checkunusedfunctions.h
checkunusedvar.cpp Fixed #9707 (False positive: unreadVariable, union) 2020-10-02 20:22:22 +02:00
checkunusedvar.h
checkvaarg.cpp made check.h less heavy (#2633) 2020-05-23 07:16:49 +02:00
checkvaarg.h
clangimport.cpp Clang import; fixed ast for function call with multiple arguments 2020-10-09 07:54:16 +02:00
clangimport.h
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
cppcheck.natvis
cppcheck.vcxproj Try to fix compilation with cppcheck.vcxproj 2020-06-20 09:47:35 +02:00
cppcheck.vcxproj.filters
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
errortypes.h
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 Update copyright year to 2007-2016. 2016-01-01 15:34:45 +02:00
mathlib.cpp
mathlib.h
path.cpp
path.h
pathanalysis.cpp
pathanalysis.h
pathmatch.cpp Update Copyright year 2020-10-03 09:15:56 +02:00
pathmatch.h
pcrerules.pri
platform.cpp
platform.h
precompiled.h
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
timer.cpp
timer.h
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
utils.cpp
utils.h
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
version.h set version 2.2.99 2020-10-03 13:54:17 +02:00
version.rc