Commit Graph

113 Commits

Author SHA1 Message Date
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
Daniel Marjamäki 742c437953 Fixed #9354 (Unknown macro is not reported and then Cppcheck is silent about issues) 2019-09-13 13:05:48 +02:00
IOBYTE e5220bdf0c make ellipsis ... a single token (#2143)
* make ellipsis ... a single token

Using cppcheck -E to preprocess code with ellipsis produces output that
can't be compiled because ... is split into 3 tokens.

* try to fix addon
2019-09-04 08:07:30 +02:00
IOBYTE bee248b2de token simplifier: fix namespace, token link and syntax error support for template type aliases (#1863) 2019-06-01 10:52:29 +02:00
Daniel Marjamäki 57c6628732 Revert 'Cleaning up unsimplified templates'. This fix caused problems. 2019-05-16 21:11:04 +02:00
Daniel Marjamäki 27fad38e00 Fixed #9084 (Tokenizer::setVarId: Same varid for member variable and argument, unknown template type) 2019-05-12 09:10:37 +02:00
Daniel Marjamäki d58d4273f9 Cleaning up unsimplified templates 2019-05-11 13:00:03 +02:00
IOBYTE 7799ed4243 Fixed #8889 (varid on function when using trailing return type.) (#1800)
* Fixed #8889 (varid on function when using trailing return type.)

Don't set varid for trailing return type.

* Add a test for #9066 (Tokenizer::setVarId: varid set for trailing return type)
2019-04-18 20:22:39 +02:00
Daniel Marjamäki e0f1418228 Fixed #9034 (Tokenizer::setVarId: function call parameter is not variable declaration) 2019-03-24 07:06:21 +01:00
IOBYTE 155e4ce912 Fixed #8971 ("(debug) Unknown type 'x'." using alias in class members) (#1653)
* Fixed #8971 ("(debug) Unknown type 'x'." using alias in class members)

* template simplifier: partial fix for #8972

Add support for multi-token default template parameters.

* template simplifier: fix for #8971

Remove typename outside of templates.
2019-02-09 08:34:59 +01:00
Daniel Marjamäki bd7790fd8c Update copyright year 2019-02-09 07:24:06 +01:00
Daniel Marjamäki ae001d4336 Fixed #8957 (Tokenizer::setVarId: varid not set when lambda function is used) 2019-02-03 08:57:04 +01:00
IOBYTE 98fc6d1d32 Fixed #8959 ("(debug) Unknown type 'x'" with using/alias) (#1635)
* Fixed #8959 ("(debug) Unknown type 'x'" with using/alias)

* fix cppcheck warning
2019-01-31 23:57:37 +01:00
Daniel Marjamäki 022259caf3 Fix Cppcheck warning
[ci skip]
2019-01-12 19:11:18 +01:00
Daniel Marjamäki 8dd641b8be Use OVERRIDE in test 2019-01-12 15:45:25 +01:00
Daniel Marjamäki 8087cfed5d Fixed #8627 (Tokenizer::setVarIdPass2: constructor parameter) 2018-12-02 09:28:05 +01:00
Daniel Marjamäki 69f2e0938a VarId: Improved varids for struct members (#8844) 2018-11-14 19:11:35 +01:00
Daniel Marjamäki 93cde415a7 Fixed #7988 (variable in condition gets wrong varid) 2018-11-11 07:50:25 +01:00
Daniel Marjamäki c3e6e7c338 Fixed #8664 (setVarId: Wrongly set varid for lambda argument) 2018-10-07 20:40:59 +02:00
Daniel Marjamäki 45379a3aa6 Updated copyright year for modified files
[ci skip]
2018-06-10 22:07:21 +02:00
IOBYTE ce50df8047 Fix override warnings. (#1234) 2018-05-15 16:37:40 +02:00
Daniel Marjamäki c4caee6b18 Updated copyright year 2018-01-14 15:37:52 +01:00
Daniel Marjamäki fc1ac180e6 Fixed #6218 (Template type aliasing misdetection) 2017-12-29 22:47:07 +01:00
Daniel Marjamäki 6b1a2dcc5d Fixed #7788 (Varid missing for member variable in ctor of template class) 2017-11-10 21:03:15 +01:00
Daniel Marjamäki 799f953c00 Fixed #8269 (Tokenizer: wrong varid (using namespace A::B)) 2017-11-09 23:15:16 +01:00
Daniel Marjamäki 2408f01cc0 Fixed #8270 (Tokenizer: wrong varid (using namespace std)) 2017-11-09 22:08:58 +01:00
Daniel Marjamäki b67cf0a475 Improved handling of varid in complex scopes 2017-11-09 15:58:08 +01:00
Daniel Marjamäki 26b9e1528c Fixed #7000 (Invalid varid - matching class with same name from other namespace) 2017-11-08 22:52:27 +01:00
Daniel Marjamäki 8b384f8ee5 Fixed #4988 (Tokenizer::setVarId: Wrong varid for inline function parameter) 2017-11-05 22:25:46 +01:00