Commit Graph

141 Commits

Author SHA1 Message Date
PKEuS 99ce89c003
Improvement: Set varId for variables with global scope operator :: Refactorization: Moved internal class from tokenize.h to tokenize.cpp (#4184)
Merged from LCppC.
2022-06-11 08:11:16 +02:00
Paul Fultz II e2c35abde5
Fix 11050: False positive: unreadVariable for class variable when another function uses the same variable name (#4121) 2022-05-22 09:20:32 +02:00
chrchr-github 6a914dc435
Add tests for # 10773, #108787, #8991 (#4063)
* Add test for #10773

* Add test for #10878

* Add test for #8991
2022-04-30 08:20:00 +02:00
chrchr-github 6df0f9b3e3
Add tests for #7377, #8692, #9180 (#4053) 2022-04-27 12:43:21 +02:00
chrchr-github 961ecfbe33
Fix #11003 cppcheckError with nested template arguments (#4049) 2022-04-25 22:23:06 +02:00
Paul Fultz II d2a0b0f78e
Fix 10951: FP knownEmptyContainer with east-const (#3988)
* Fix 10951: FP knownEmptyContainer with east-const

* Format

* Use simpleMatch
2022-04-08 08:22:39 +02:00
chrchr-github 4bf8718dcb
Fix #10849 FP constStatement with pointers in lambda (#3961) 2022-04-01 19:50:40 +02:00
Paul Fultz II 5bea50cd36
Fix 10908: FP: uninitvar after for-loop (#3942) 2022-03-31 21:24:20 +02:00
chrchr-github 183969cd4b
Fix #10936 FP constStatement with extern declaration (#3960) 2022-03-31 21:08:04 +02:00
chrchr-github fb1170b10b
Fix #10872 FP constStatement with variable called std (#3906) 2022-03-16 15:29:34 +01:00
chrchr-github d1f740a289
Partial fix for #9384 varid 0 with lambda (II) (#3889)
* Partial fix for #9384 varid 0 with lamba

* Format

* Undo

* Undo

* Partial fix for #9384 varid 0 with lambda (II)
2022-03-12 06:17:37 +01:00
chrchr-github c9f47dec8b
Partial fix for #9384 varid 0 with lambda (#3875) 2022-03-08 20:10:51 +01:00
Oliver Stöneberg 4a63af02ed
enabled functionConst and functionStatic in selfcheck (#3862)
* fixed functionConst findings and enabled it in selfcheck

* fixed functionStatic findings and enabled it in selfcheck

* .travis_suppressions: adjusted comment

* testimportproject.cpp: added missing asserts
2022-03-02 07:46:47 +01:00
Oliver Stöneberg f32583e097
removed OVERRIDE and FINAL defines and use the keywords directly (#3767) 2022-02-10 23:02:24 +01:00
Daniel Marjamäki 3989408738 Update copyright year 2022-02-05 11:45:17 +01:00
Oliver Stöneberg 171da2e6f9
avoid dependency on transitive includes - based on include-what-you-use (#3757) 2022-01-27 19:03:20 +01:00
chrchr-github ca311ebcdf
ASSERT() on calls to Tokenizer::tokenize() in test code (#3501) 2021-11-29 07:34:39 +01:00
Paul Fultz II 3cb252bd99
Fix 9873: False negative: null pointer when checking raw pointer (#3485) 2021-10-06 08:39:58 +02:00
Paul Fultz II 7f358b2bed
Format with uncrustify (#3388) 2021-08-07 20:51:18 +02:00
Daniel Marjamäki 8aa9e448f5 Parser; Set varid for structured binding variables 2021-04-26 18:04:27 +02:00
dummyunit b18e6f1e10
Fix varId assignment for uses of variables declared in the if condition (#3231)
Variables declared in the if condition (or in C++17 init-statement) are
visible not only in the if body but also in the else body. But logic in
Tokenizer::setVarIdPass1() handled such variables as if they were
declared in the if body.

As the result they were removed from variablesMap by the time the else
block was parsed and their uses in the else block were either given an
incorrect varId from variables in some outer scope or not given a varId
at all.

This then resulted in false positive unreadVariable errors for variables
declared in the if condition (or init-statement) and used only in the
else block.

Simplification from "else if ..." to "else { if ... }" was moved before
setVarId() to simplify detection for ends of blocks in if-else chains.
2021-04-26 07:38:03 +02:00
Ken-Patrick Lehrmann cddaa6d671
10221: Fix setVarId in template code (#3187)
The computation of the classname was not expecting templates. Simply
skipping the template part seems to fix the issue.
2021-03-29 12:16:02 +02:00
Lars Even Almaas 9786f1c34b
Suggested implementation for rule 8.2 (#3169) 2021-03-25 08:25:43 +01:00
Daniel Marjamäki 42437277dc Update Copyright year 2021-03-21 20:58:32 +01:00
PKEuS cf1937294a Refactorization: Removed unnecessary \n and spaces in strings
Merged from LCppC.
2021-02-20 12:58:42 +01:00
Daniel Marjamäki 245284acde Tokenizer; Fixed varid for base class member variable 2020-12-08 17:25:50 +01:00
Daniel Marjamäki 2cd8ea83a7 Fixed #9860 (unused template not removed properly by default) 2020-11-22 16:43:36 +01:00
Daniel Marjamäki 22d6160624 Improve handling of decltype 2020-11-16 20:11:26 +01:00
Daniel Marjamäki 8b0699cd6a Revert "improved decltype() handling"
This reverts commit 6e8f77c519.
2020-11-15 21:32:05 +01:00
Daniel Marjamäki 6e8f77c519 improved decltype() handling 2020-11-15 20:58:17 +01:00
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
Daniel Marjamäki ad9b2741cd varid: set varid for 'extern const char (*x[256]);'. This is a partial fix for #9922 2020-09-29 10:53:20 +02:00
Daniel Marjamäki 2bb73840fc astyle formatting 2020-08-23 17:17:33 +02:00
Paul Fultz II a332062385
Add exprId to tokens (#2744) 2020-08-20 18:21:29 +02:00
Daniel Marjamäki 9edca82138 Fix testrunner 2020-05-25 16:02:34 +02:00
PKEuS fb1afe2345 Fixed test suite: Do no longer apply simplifyTokenList2 to token lists, except for those tests that test those simplifications, because checks are no longer run on that simplified token list
Changed failing unit test to TODO tests, as they indicate patterns we do no longer understand properly.
2020-05-20 18:54:16 +02:00
Daniel Marjamäki 9eda399323 Less strict unknownMacro 2020-05-17 19:12:16 +02:00
Daniel Marjamäki 08ddd84780 Update copyright year 2020-05-10 11:16:32 +02:00
Daniel Marjamäki 3e0218299b Revert "Update copyright year"
This reverts commit 6eec6c4bd5.
2020-05-10 11:13:05 +02:00
Daniel Marjamäki 6eec6c4bd5 Update copyright year 2020-05-10 11:11:34 +02:00
Daniel Marjamäki 47c998e52d Fixed #9689 (setVarId: wrong varid when 'not' is used) 2020-04-25 14:42:45 +02:00
Oliver Stöneberg 1af959af2c
fixed -Wextra-semi-stmt Clang warnings (#2553)
* fixed -Wextra-semi-stmt Clang warnings

* adjusted REDIRECT macro to require a semicolon

* testmathlib.cpp: rolled back accidental change
2020-04-21 17:27:51 +02:00
Zorgovskiy 08fc956990
Fixes issue #9664 (#2614) 2020-04-20 08:59:35 +02:00
Daniel Marjamäki de53f63f76 Fixed #9665 (Tokenizer::setVarId: for loop variables) 2020-04-18 12:08:53 +02:00
Daniel Marjamäki e4bea02cad Fixed #7578 (varid not set for 'pointer to array' member variable in method) 2020-04-15 20:56:21 +02:00
Daniel Marjamäki 0725c2290c Tokenizer: Do not simplify function pointers to normal pointers as we loose important information 2020-04-10 11:53:32 +02:00
Daniel Marjamäki 84995485ea VarId: fixed varids for 'for (auto [x,y]: xy)' 2020-02-27 07:18:07 +01:00
Daniel Marjamäki dcee189146 Tokenizer::setVarId: better handling of decltype() 2020-01-29 17:40:22 +01:00
IOBYTE 78b9fd9bb9 Fix #9383 ("debug: Function::addArguments found argument 'x' with varid 0." with variadic templates) (#2238) 2019-10-06 12:45:42 +02:00
IOBYTE c32a568c1f fix #8965 ("(debug) Executable scope 'x' with unknown function." with rvalue parameter in method) (#2237)
I fixed the AST enough to pass testrunner but I don't believe it is
correct.

This code:

void Foo4(int&&b);

has this AST:

( 'void'
|-Foo4
`-&& 'bool'
  |-int
  `-b 'signed int'

but I don't believe && should have `bool`.
2019-10-04 12:30:11 +02:00