Commit Graph

539 Commits

Author SHA1 Message Date
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
Daniel Marjamäki ae1b9cb14e SymbolDatabase: Improved function matching in C code 2020-11-04 07:17: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
Rikard Falkeborn 2624d791e6
Symboldatabase: Don't set unknown enum values (#2852)
Previously, if an enum value was set to a value unknown to cppcheck, the
next enum value would erroneously be set to the last set value plus one
(or zero, if no enum value had been set before). This partially fixes
Trac ticket #9647, in the sense that it no longer sets wrong values for
these enum values. Further improvements to this would be to set the
correct values instead. It also fixes the false positive mentioned in the
comments in the ticket.
2020-10-18 20:41:36 +02:00
Rikard Falkeborn 33739d23aa
Fix #9941: Return value type of library functions returning unsigned (#2848)
Fix return value types of library functions returning unsigned.
Previously, the valueType of auto x = f() would be signed even if f()
was specified to return an unsigned type.

This fixes #9941, which is a regression in cppcheck 2.2 compared to 2.1.
The regression was introduced in 32df807b22.
2020-10-16 07:56:31 +02:00
Daniel Marjamäki c3517924d0 Clang import testing: Compare AST 2020-10-04 11:27:31 +02:00
Daniel Marjamäki 1251d35ba4 Fix SymbolDatabase for 'extern const char ( * x [ 256 ] ) ;' 2020-10-02 08:25:43 +02:00
Daniel Marjamäki e03a8e1dc1 Fixed #9892 (Crash: endless recursion in Token::typeDecl for expression 'auto combo = widget->combo = new Combo{};') 2020-09-11 21:29:48 +02:00
Paul b26c581556 Fix issue 9888: False positive: Using reference to dangling temporary with std::move 2020-09-10 22:38:31 -05:00
Daniel Marjamäki 136ac2c643 Fixed #9266 (handle operator() better) 2020-09-06 21:02:06 +02:00
shaneasd 9712c136bd
make result of <<|>> an xvalue (#2775) 2020-09-05 12:07:06 +02:00
Daniel Marjamäki 5acd6fcdc8 astyle formatting 2020-09-03 18:55:40 +02:00
shaneasd 08ea6435ac
fix false positives in constParameter (#2758) 2020-09-03 18:44:44 +02:00
Daniel Marjamäki 3fe46239cf SymbolDatabase; Refactoring, use Tokenizer::isFunctionHead to skip function attributes 2020-09-03 11:21:12 +02:00
Dan 974b6fb8e5
Add test cases for assign operators with default implementation (#2767) 2020-09-03 07:29:54 +02:00
Daniel Marjamäki f5ace9ffbe SymbolDatabase; Improved ValueType when container methods items 2020-06-26 22:47:28 +02:00
Daniel Marjamäki 3f1f62e078 Fixed #9746 (SymbolDatabase: Wrong valueType for return) 2020-06-10 21:13:53 +02:00
Oliver Stöneberg 4f68d85633
optimized non-matchcompiled Token::simpleMatch() a bit (#2640) 2020-05-26 20:13:56 +02:00
PKEuS d6390dbd14 Optimization: Improved performance of simplifyTypedef for code with lots of typedefs
20% performance gain when checking ExtremeTuxRacer sourcecode (with glext.h available)
2020-05-19 08:35:13 +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 5eeeba97eb SymbolDatabase: Better handling of function pointer function argument 2020-05-02 17:04:54 +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
Daniel Marjamäki 219180b00a Fixed #9038 (Auto type with explicit pointer symbol detected as integer) 2020-04-19 20:08:47 +02:00
Daniel Marjamäki e8bbfdbfee Fixed #9559 (Multiple checks to std::atomic are not redundant) 2020-04-19 17:29:40 +02:00
Oliver Stöneberg 2c1e36e63e
cleaned up includes based on include-what-you-use (#2600)
* cleaned up includes based on include-what-you-use

* check.h: trying to work around Visual Studio 2012 bug

* fixed Visual Studio compilation
2020-04-13 13:44:48 +02:00
Daniel Marjamäki 97b04ba9a7 Syntax check: Using keyword in global scope 2020-04-11 17:36:22 +02:00
Daniel Marjamäki f01783238e Fixed #9596 (False positive: Returning an integer in a function with a pointer return type auto handling) 2020-04-04 20:03:48 +02:00
Sebastian b8432b7e23
testsymboldatabase.cpp: Fix AppVeyor build error (#2568) 2020-03-10 12:26:00 +01:00
Daniel Marjamäki f093d23a36 SymbolDatabase: Fixed addArguments 2020-03-09 15:13:50 +01:00
Daniel Marjamäki cdee62c032 AST: Fixed AST for struct cast '(struct T){...}' 2020-03-08 16:21:22 +01:00
Daniel Marjamäki 5ea01c5d60 Fix Cppcheck warning 2020-03-08 10:02:46 +01:00
Daniel Marjamäki 5376ba1701 AST: Throw validation exception if ternary operator is missing operands 2020-03-07 21:46:38 +01:00
Daniel Marjamäki 6f6f9dd5bc Tokenizer: Throw unknownMacro in non-executable scope 2020-02-19 21:12:58 +01:00
Rikard Falkeborn f6e7fb4bd9
Bugfix valuetype for some integer constants (#2545) 2020-02-19 07:51:39 +01:00
Daniel Marjamäki 95ac456e13 Fixed #9582 (false positive "error: Out of bounds access" with std::array and constant) 2020-02-19 07:36:02 +01:00
Daniel Marjamäki e31b2f8b73 SymbolDatabase; Set smart pointer type in Variable valueType 2020-02-14 09:40:27 +01:00
Daniel Marjamäki 18124fe248 Fixed #9591 (SymbolDatabase: decltype) 2020-01-29 17:29:40 +01:00
Daniel Marjamäki 830f901206 Fixed #9586 (Valuetype: Wrong type for 'true << 1') 2020-01-27 11:46:59 +01:00
Dmitry-Me 895910b769 Fixed #7159 (wrong handling of function parameters) 2019-12-31 18:26:12 +03:00
Dmitry-Me 9133f9fe75 Improve test coverage for function arguments count 2019-12-20 18:28:32 +03:00
IOBYTE ec4c979cd8 fix daca error: Internal Error: Invalid syntax (#2452)
* fix daca error: Internal Error: Invalid syntax

* fix cppcheck warnings
2019-12-18 11:48:36 +01:00
Daniel Marjamäki 6d1c84e3a6 Fixed #9449 (SymbolDatabase: Function lookup fails when string literal is converted to bool) 2019-10-30 21:05:42 +01:00
IOBYTE 6b4a3bc830 fix #9431 (Invalid syntax error on valid C++ code) (#2298) 2019-10-26 17:39:46 +02:00
Georgy Komarov 72f07c8a33 Add MISRA checks for rules 21.1 and 21.12 (#2284)
* Add MISRA 21.1 check

This also required add static field for functions in symboldatabase.

* Add MISRA R21.12

* Use newer ASSERT macroses in tests
2019-10-26 08:32:46 +02:00
Daniel Marjamäki dedee2b173 SymbolDatabase: Better ValueType handling for containers 2019-10-23 19:54:59 +02:00
Daniel Marjamäki 87f65230ae SymbolDatabase: Better valuetype handling of container addition 2019-10-23 12:42:46 +02:00