Commit Graph

570 Commits

Author SHA1 Message Date
Robert Reif c7be967769
fix #10295 (false negatives by inconsistent 'void' in argument list (declaration vs definition)) (#3274)
Co-authored-by: Robert Reif <reif@FX6840>
2021-05-24 19:32:15 +02:00
Daniel Marjamäki bd97b8eb8a SymbolDatabase; Add variables when structured binding is used 2021-04-26 18:21:07 +02:00
Daniel Marjamäki 4f43dbf954 Parser; fixed ast and auto type deduction for c++17 braced init lists 2021-04-25 10:38:33 +02:00
Daniel Marjamäki eacc9e552e Function::returnsReference: handle type scope better 2021-04-10 14:31:50 +02:00
Paul Fultz II 5cf2f7e633
Fix issue 10087: false positive: error: Reference to temporary returned. (#3205) 2021-04-09 07:44:20 +02:00
Paul Fultz II f8dc9862da
Fix issue 10202: FP: constParameter (#3202) 2021-04-08 16:02:11 +02:00
Oliver Stöneberg 6397e29f84
cleaned up includes based on include-what-you-use (#3141) 2021-04-03 21:30:50 +02:00
Daniel Marjamäki 42437277dc Update Copyright year 2021-03-21 20:58:32 +01:00
Daniel Marjamäki 51564504a8 astyle formatting 2021-03-20 18:54:46 +01:00
Tetrix 9b7f1f6280
simplifyCPPAttribute tokenizer strips alignas (#3171) 2021-03-20 10:38:47 +01:00
PKEuS cf1937294a Refactorization: Removed unnecessary \n and spaces in strings
Merged from LCppC.
2021-02-20 12:58:42 +01:00
IOBYTE 5810171336
fix daca crashes in Type::findDependency() (#3101) 2021-01-31 10:07:03 +01:00
IOBYTE 6914f375e1
fix #10135 ("debug: Executable scope 'what' with unknown function." with custom std::exception) (#3089) 2021-01-28 12:38:36 +01:00
IOBYTE a4953575f1
fix #10127 (debug: Executable scope 'x' with unknown function.) (#3077) 2021-01-23 17:55:25 +01:00
Paul Fultz II d80f2fb46f
Reapply f1cc3ad and fix performance regression (#3076) 2021-01-23 08:47:39 +01:00
Daniel Marjamäki 0fa89ff2ba Revert 14365ffc7 and f1cc3ada8, there was a performance regression 2021-01-22 10:51:46 +01:00
Paul Fultz II f1cc3ada86
Refactor valueFlowTerminatingCondition to handle inner conditions and complex conditions (#3060) 2021-01-21 20:18:53 +01:00
IOBYTE d39956414f
fix #10122, #10124 and #10125 (debug: Executable scope 'x' with unknown function.) (#3073) 2021-01-21 19:47:51 +01:00
IOBYTE 952857195b
fix out of line member functions using global namespace (#3063) 2021-01-19 18:52:47 +01:00
IOBYTE fde5994cc3
fix #10061 (debug: Executable scope 'x' with unknown function.) (#3062) 2021-01-18 19:01:04 +01:00
Rikard Falkeborn bedf3118ef
library: Refactor to use enum class (#3026) 2021-01-08 10:29:01 +01:00
IOBYTE c085151eb0
fix exprengine.cpp:2833:18: debug: Executable scope 'executeAllFunctions' with unknown function. (#3019) 2021-01-06 17:29:23 +01:00
IOBYTE 22b10f8987
fix token.cpp:745:19: debug: Executable scope 'getStrSize' with unknown function. (#3015) 2021-01-05 22:07:53 +01:00
IOBYTE 23da5c9815
fix #9885 (SymbolDatabase: function lookup fails calling variadic method) (#3002)
Co-authored-by: Robert Reif <reif@FX6840>
2021-01-03 11:17:32 +01:00
Ken-Patrick Lehrmann aad723bf3a
Fix false positive AssignmentIntegerToAddress (#2971) 2020-12-24 19:57:02 +01:00
IOBYTE 2ecab32fbe
fix debug printing of valuetype name with namespaces (#2968) 2020-12-21 19:47:54 +01:00
Wolfgang Stöggl 079255d913
Fix gcc11 build errors (#2963) 2020-12-19 21:54:19 +01:00
IOBYTE f2cf11682a
fix #10040 (symbolDatabaseWarning: debug: Executable scope 'x' with unknown function.) (#2955) 2020-12-18 07:46:01 +01:00
Daniel Marjamäki cb7eee2aa9 SymbolDatabase: Improved types for 'std::string + x' 2020-12-05 13:24:21 +01:00
Daniel Marjamäki 009ad11b3e SymbolDatabase: set proper valuetype for string addition result (#9161) 2020-12-01 20:16:39 +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
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