Commit Graph

2805 Commits

Author SHA1 Message Date
Daniel Marjamäki 70511464f5 Fixed Cppcheck self-check 2021-02-14 15:53:46 +01:00
Daniel Marjamäki f08dde1140 Fixed #10013 (Tokenizer: Code with 'not' is not handled) 2021-02-13 20:32:49 +01:00
IOBYTE 1eafed9e75
fix hang in simplifyUsing (#3128)
Co-authored-by: Robert Reif <reif@FX6840>
2021-02-12 16:21:51 +01:00
IOBYTE e57a674458
fix #10173 (syntax error from wrong simplifications for using type al… (#3126) 2021-02-12 09:47:16 +01:00
IOBYTE b6e93bb575
fix #10172 (debug: Executable scope 'x' with unknown function.) (#3121) 2021-02-11 08:08:45 +01:00
IOBYTE d3d2e16137
fix hang from f48e195c31 (fix #10136 TODO test (#3117)) (#3120)
Co-authored-by: Robert Reif <reif@FX6840>
2021-02-09 14:19:01 +01:00
IOBYTE f48e195c31
fix #10136 TODO test (#3117) 2021-02-07 21:46:35 +01:00
IOBYTE 1872725ca2
fix #10171 (debug: Executable scope 'x' with unknown function.) (#3116) 2021-02-07 09:04:57 +01:00
Daniel Marjamäki b7c4aeca16 astyle formatting 2021-02-06 12:27:51 +01:00
IOBYTE c70fcf8e2b
fix #10136 (debug: Executable scope 'x' with unknown function.) (#3113) 2021-02-05 15:50:32 +01:00
Oliver Stöneberg e8b8cfec78
some minor optimizations (#3057) 2021-01-28 22:18:17 +01:00
Simon Martin 9d10f4f572
Ticket #10028: Properly simplify auto variables' initialization. (#3079) 2021-01-23 17:56:58 +01:00
IOBYTE a4953575f1
fix #10127 (debug: Executable scope 'x' with unknown function.) (#3077) 2021-01-23 17:55:25 +01:00
orbitcowboy bb451ca289 Running astlye [ci skip] 2021-01-22 21:47:24 +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 664289792c
fix simplifyTypedef removing needed type qualification (#3058) 2021-01-18 10:08:55 +01:00
IOBYTE dd866f2898
fix using type alias with derived class (#3050) 2021-01-17 16:10:53 +01:00
Oliver Stöneberg 7aa85aa408
Use std::unordered_* containers for faster lookups (#3052) 2021-01-16 13:52:09 +01:00
Daniel Marjamäki a5babf25a7 Fixed #10080 (syntax error: operator) 2021-01-14 20:56:11 +01:00
Daniel Marjamäki 5f21d9d97b Fixed #8975 (Syntax error for valid C code) 2021-01-12 21:28:07 +01:00
Oliver Stöneberg ac7647fcd8
some self-check suppression cleanups (#3032) 2021-01-09 20:32:38 +01:00
IOBYTE cb02628c7c
fix #10075 (namespace alias changes variable name) (#3020) 2021-01-06 17:30:11 +01:00
IOBYTE 8897ad3408
fix #10068 (typedef not replaced when namespace is involved) (#3009) 2021-01-05 16:53:56 +01:00
Oliver Stöneberg d59abfd977
fixed clang-tidy warnings (#3006)
* clang_tidy.cmake: added clang-tidy-11 to list of executables to look for

* .clang-tidy: disabled warnings we are (currently) not interested in

* fixed clang-tidy warnings
2021-01-02 23:10:27 +01:00
Oliver Stöneberg fbf5858f76
fixed and enabled several clang-tidy warnings (#2816) 2021-01-02 19:10:25 +01:00
IOBYTE e7bdf5f71c
remove cleanupAfterSimplify from the template simplifier (#2998)
The template simplifier works well enough now so cleanupAfterSimplify is
no longer necessary.  In fact cleanupAfterSimplify was introducing a bug
which improperly simplified C++ style casts.

Bugs should be exposed and fixed properly rather than just hiding them.

Co-authored-by: Robert Reif <reif@FX6840>
2020-12-31 09:33:23 +01:00
IOBYTE 277da763aa
fix #10054 (debug: Executable scope 'x' with unknown function.) (#2994) 2020-12-30 08:09:34 +01:00
IOBYTE 765c1ace87
fix #10008 (false negative: knownEmptyContainer with alias in namespace and "using namespace") (#2979) 2020-12-26 13:45:17 +01:00
Daniel Marjamäki 37a5ec8cd5 Summaries: Moved to its own files 2020-12-20 19:53:58 +01:00
Daniel Marjamäki 1bf6a2f62b Summaries: Enhanced merge of noreturn info 2020-12-20 14:49:43 +01:00
Daniel Marjamäki 96caaedbd5 Generate basic function summaries 2020-12-19 19:02:42 +01:00
Daniel Marjamäki d340e8770c Fixed Tokenizer::setVarId when removing last scope name 2020-12-08 17:39:04 +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 7a4462dac5 Tokenizer: Refactoring, use isFunctionHead in setVarId. It should be more reliable. 2020-12-08 16:53:55 +01:00
IOBYTE 8161baf1e9
fix template debug output line numbers (#2938) 2020-12-08 10:35:13 +01:00
IOBYTE ab16603666
fix #9685 (Handle 'extern "C++"') (#2933) 2020-12-05 09:26:11 +01:00
Daniel Marjamäki 62810af7f3 Tokenizer: Avoid null pointer dereference in garbage code 2020-12-02 23:06:11 +01:00
Daniel Marjamäki cbb388d458 Tokenizer: Avoid wrong simplification of template right angle bracket 2020-12-02 20:21:32 +01:00
Daniel Marjamäki f250e06df7 Improved daca check for wrong detection of template right angle brackets 2020-11-30 20:00:38 +01:00
Daniel Marjamäki 9aa69661b5 More robust Token::findClosingBracket 2020-11-30 19:26:28 +01:00
Daniel Marjamäki 8a1c16a560 Tokenizer: add daca debug messages when right angle brackets in templates are not handled well 2020-11-29 16:07:56 +01:00
Daniel Marjamäki e2debac882 Fix testcases 2020-11-29 08:46:42 +01:00
Daniel Marjamäki fd75837494 Tokenizer: Remove extra 'template' keywords 2020-11-28 21:57:06 +01:00
Daniel Marjamäki 5b89b179ec Detect syntax error when script is checked 2020-11-28 14:41:05 +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 54a93c4374 Fixed #9452 (FP syntaxError - _Pragma before struct with two constructors) 2020-11-15 15:03:47 +01:00
Daniel Marjamäki c95b0d2a51 Fixed #9977 (Template simplifier does not simplify in header) 2020-11-11 09:50:51 +01:00
uhziel aad29ddb9a
fix an error in Tokenizer::simplifyTypedef() (#2880) 2020-11-04 13:32:31 +01:00
Daniel Marjamäki 7804b28e70 AST: Tweaked debug output 2020-10-31 18:57:48 +01:00
Daniel Marjamäki 4eb829933e Tokenizer: Fixed unwanted unknownMacro warning for decltype 2020-10-27 09:08:13 +01:00
Daniel Marjamäki eb2c0bb6ee Fix TestExprEngine 2020-10-24 22:53:15 +02:00
Daniel Marjamäki 3876b601d5 Fixed #9476 (Tokenizer: report unknown macro) 2020-10-24 22:12:10 +02: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
Armin Müller 08cef9e815
Typos found by running "codespell" (#2846) 2020-10-15 19:24:13 +02:00
Daniel Marjamäki f956dee58a Tokenizer: Fixed simplification of parentheses in expression 'a=(b,c);' 2020-09-29 12:06:30 +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 4c9db17742 Tokenizer: replace all or none of the alternative tokens in a translation unit 2020-09-28 19:01:31 +02:00
Daniel Marjamäki fa42d8c49c Fixed #9920 (Tokenizer: The keyword is not replaced, leads to false positive) 2020-09-28 16:35:50 +02:00
Oliver Stöneberg 7189b303ae
fixed some modernize-loop-convert clang-tidy warnings (#2815) 2020-09-21 19:30:47 +02:00
Daniel Marjamäki 3459f0da32 Fixed #9812 (False positive; syntax error 'using array_p = const array_t *;') 2020-09-14 21:59:58 +02:00
Daniel Marjamäki 687b44dbb7 Token: add flag for splitted variable declaration with initialization 2020-09-09 16:22:47 +02:00
Daniel Marjamäki e802d85315 Fixed #9445 (Syntax error on typeof word in C) 2020-09-08 17:12:54 +02:00
Daniel Marjamäki c0ef640304 Fixed #9881 ((Regression) Hang with operator() in function call) 2020-09-07 21:32:29 +02:00
Daniel Marjamäki cfd41fea83 Fixed #9879 (Tokenizer: Better handling of operator() '(*this)(...)') 2020-09-07 20:07:21 +02:00
Daniel Marjamäki 136ac2c643 Fixed #9266 (handle operator() better) 2020-09-06 21:02:06 +02:00
Daniel Marjamäki 9a943e7616 misra: rewrote rule 12.3 2020-09-06 11:33:37 +02:00
Daniel Marjamäki 7969bf7ae8 Token: Add 'isSplittedVarDecl attribute 2020-09-06 11:02:22 +02:00
Daniel Marjamäki 12d51ae5c4 Fixed #9809 (Tokenizer; Fix handling of variable declaration with @) 2020-09-02 13:04:33 +02:00
IOBYTE 8774e97f26
fix #9771 (Syntax error; operator != <> ()) (#2757) 2020-08-26 18:39:33 +02:00
Daniel Marjamäki 72fa5f2e27 Fixed #9752 (ValueFlow: Uninit after assignment with '&') 2020-08-05 22:57:06 +02:00
Georgy Komarov 6bc13080ee
Simplify condition 2020-07-18 07:07:20 +03:00
Georgy Komarov 382f21a5c9
Fixed crash on garbage code: comparisson with an empty second operand
This will fix #9774.
2020-07-18 07:02:12 +03:00
Daniel Marjamäki ddd21a260f Fixed #6978 (False positive: unusedLabel shown for labels that are used in some preprocessor configurations) 2020-06-30 18:26:24 +02:00
Daniel Marjamäki 0583763cc6 Fixed #3088 (False positive: Dont report "struct or union member is never used" for structs with __attribute__((packed)) or #pragma pack(push)) 2020-06-30 11:00:40 +02:00
Daniel Marjamäki af6e76d623 Fixed #9787 (Better handling of user defined literals) 2020-06-25 22:06:34 +02:00
Simon Martin 1705d096f7
Simplify empty anonymous namespaces. (#2673) 2020-06-07 13:49:04 +02:00
Ken-Patrick Lehrmann a45c7752a5
9185: Don't syntax error on nested lambdas (#2672) 2020-06-07 08:58:12 +02:00
Ken-Patrick Lehrmann 99ff04f617
9757: skip template parameters when computing scope (#2670)
The template parameter is confusing simplifyUsing: it does not compute
properly the scope, and we end up replace "type" in "to_string" with
"void", then later "void" is removed and we have an internal error.
2020-06-06 17:51:15 +02:00
Paul Fultz II eed2e829a7
Revert "Cleanup: Removed Tokenizer::simplifyTokenList2. As a side-effect, rules for "simple" token list are now executed on normal token list." (#2666)
This reverts commit 187cde183d.
2020-05-30 11:23:22 +02:00
PKEuS 187cde183d Cleanup: Removed Tokenizer::simplifyTokenList2. As a side-effect, rules for "simple" token list are now executed on normal token list. 2020-05-29 21:21:07 +02:00
Daniel Marjamäki 67115491ea Fixed #9739 (Tokenizer: simplifyTypedef: wrong simplification in using) 2020-05-29 11:16:49 +02:00
Daniel Marjamäki 7ff692341e Fixed #9730 (Regression: TEXT macro not handled in windows code) 2020-05-28 22:03:16 +02:00
Daniel Marjamäki 4d5fe6ec5e astyle formatting
[ci skip]
2020-05-26 23:28:19 +02:00
Oliver Stöneberg 4f68d85633
optimized non-matchcompiled Token::simpleMatch() a bit (#2640) 2020-05-26 20:13:56 +02:00
Daniel Marjamäki f7f26ffe90 Tokenizer: Better handling of c alternative tokens in const method 2020-05-25 15:07:23 +02:00
Oliver Stöneberg 37bc0483a4
made check.h less heavy (#2633) 2020-05-23 07:16:49 +02:00
Paul Fultz II 8301fa8244
Fix issue 8144: valueFlowBeforeCondition: struct (#2645) 2020-05-21 08:47:48 +02:00
PKEuS 662745b504 Fixed several coverity messages 2020-05-20 18:54:16 +02:00
PKEuS c155062cf2 Optimization: Speed up SymbolDatabase creation and Tokenizer::findGarbageCode() by using Token::isKeyword() for pre-checks 2020-05-19 13:48:15 +02:00
PKEuS f6788c0472 Fixed Token::isKeyword: Actually set this flag to a reasonable value in all code paths 2020-05-19 13:47:25 +02:00
PKEuS c9d8f607df Optimization: Reduced peak memory usage (30% in my test case) by immediately deleting simplecpp::TokenList while creating the cppcheck TokenList. 2020-05-19 12:08:17 +02:00
PKEuS 09a30bd6b5 Optimization: Speed up Tokenizer::findGarbageCode() (by 15% in my test case) by avoiding iterating through token list multiple times 2020-05-19 08:54:47 +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 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 00d1091506 Tokenizer: operator handling, fix tests 2020-05-04 23:00:51 +02:00
Daniel Marjamäki 06cb0e99d1 Tokenizer: Fix syntax error when operator* is called 2020-05-04 21:33:30 +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
Daniel Marjamäki bda73600e0 Tokenizer: Improved removal of unused template (#9588) 2020-04-20 20:48:22 +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 266c8d2c09 Remove temporary daca bailouts 2020-04-15 19:54:56 +02:00
Daniel Marjamäki 98be091d80 Fixed typedef simplification for array of function pointers 2020-04-13 16:28:01 +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
shaneasd 82c09f243b
Maybeunusedsupport (#2570)
* Add rudimentary support for [[maybe_unused]]

* Add more test cases. use the symboldatabase rather than reparsing. Fix travis error.

* test review actions

* change var to usage._var
2020-04-12 20:35:54 +02:00
Daniel Marjamäki 97b04ba9a7 Syntax check: Using keyword in global scope 2020-04-11 17:36:22 +02:00
Daniel Marjamäki e8e3c2660d Detect syntax error 'x ==> y' 2020-04-11 11:05:27 +02:00
Daniel Marjamäki 05769e8dcc Code cleanup 2020-04-10 13:14:38 +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 8e9d7290b2 Tokenizer::simplifyTypedef: Better handling of r-value references 2020-04-08 22:40:45 +02:00
Oliver Stöneberg 1dd8d4afaf
fixes for Clang and clang-tidy 10 (#2588)
* clang_tidy.cmake: added clang-tidy-10 to program list

* fixed -Wrange-loop-construct Clang warnings

* fixed readability-qualified-auto clang-tidy warnings

* .clang-tidy: actually disable clang-analyzer-* warnings

* .clang-tidy: disabled some new warnings introduced with clang-tidy-10
2020-04-04 11:44:59 +02:00
Daniel Marjamäki ac45bf7af2 Small refactoring 2020-04-04 11:19:39 +02:00
Daniel Marjamäki e0acd1abf8 Tokenizer: Report unknown macro that contains '.x=..' argument 2020-04-04 10:32:56 +02:00
Daniel Marjamäki 7577bdb1df DACA: Try to avoid some crashes/hangs for the most crazy code so we can focus on most serious bugs first 2020-03-31 11:33:38 +02:00
Daniel Marjamäki 1173186876 Fixed daca@home crash by stopping for unknown macro 'MACRO(a();b();)' 2020-03-12 13:28:09 +01:00
Daniel Marjamäki 900b99fbd8 Tokenizer; Report unknown macro used in function declaration 2020-03-10 20:22:46 +01:00
Daniel Marjamäki 5df6d5bc7c Tokenizer; Warn about unknown macro used in string concatenation 2020-02-28 21:52:01 +01: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 f07a71e3e1 Report unknown macros for pattern '%name% %num%' 2020-02-22 11:57:36 +01:00
Daniel Marjamäki ec8c733afb Improved Qt simplification 2020-02-21 19:04:21 +01:00
Daniel Marjamäki 6f6f9dd5bc Tokenizer: Throw unknownMacro in non-executable scope 2020-02-19 21:12:58 +01:00
Daniel Marjamäki ae0a73a538 Fixed #9618 (isCast flag not set for c++ casts) 2020-02-16 16:46:40 +01:00
Paul Fultz II 921887a281
Use valueFlowGeneric for valueFlowForwardExpression (#2537) 2020-02-16 16:02:22 +01:00
Daniel Marjamäki dcee189146 Tokenizer::setVarId: better handling of decltype() 2020-01-29 17:40:22 +01:00
Simon Martin 2840173a72 Ticket #9569: Do not substitute type aliases within enum definitions. (#2504) 2020-01-25 10:18:37 +01:00
Simon Martin 224a41361d Ticket #9572: Properly detect designated initializers. (#2496) 2020-01-25 10:14:16 +01:00
Rikard Falkeborn 7514544d94 Fix #8758 (add syntax error for invalid code) (#2466) 2020-01-01 15:46:09 +01:00
Daniel Marjamäki c84ba10b37 Fixed #8774 (Wrong handling of function with name 'or') 2019-12-19 19:22:39 +01:00
Daniel Marjamäki f614d32d6a Fixed #9519 (Syntax error on valid C++ 'enum {} (a)') 2019-12-15 08:40:04 +01:00
IOBYTE 0e4efea530 fix #9539 (Syntax error for valid C++14 code) (#2446) 2019-12-12 20:50:20 +01:00
RobkeBaer 370196a14c Fix extern c typedef syntax error (#2438)
* Fix extern c typedef syntax error

* Fix extraWhiteSpaceError

* Move test from testgarbage to testtokenize
2019-12-12 13:51:14 +01:00
IOBYTE f637d97080 Fix 9509 (Syntax error on empty attribute list) (#2423) 2019-12-06 05:17:19 +01:00
IOBYTE 5979eec2c0 Fix 9518 (Syntax error on valid C++) (#2424) 2019-12-05 20:51:36 +01:00
Paul Fultz II f77347d7b4 Fix crash 9492: Crash in FwdAnalysis::checkRecursive() (condTok is nullptr) (#2411)
* Fix crash 9492: Crash in FwdAnalysis::checkRecursive() (condTok is nullptr)

* Formatting
2019-12-01 14:53:03 +01:00
Daniel Marjamäki ebd32cfd73 Syntax error: if (retval==) 2019-11-23 18:50:46 +01:00
IOBYTE fb1d60bfb1 fix syntax error for num.operator std::string()[0] (#2389) 2019-11-23 17:42:24 +01:00
IOBYTE df952926f8 fix syntax error for a.operator++() ? a.operator--() : 0 (#2382) 2019-11-20 22:13:32 +01:00
Sebastian c990d10ffa
Check for JSON error when parsing addon .json files + fixes (#2374)
* cppcheck.cpp: Check for JSON error when parsing addon .json files

This fixes that errors in JSON files given via `--addon=*.json` are
silently ignored and maybe only a part of the JSON file is used.
Now the error message which picojson can return is checked and a
corresponding error message is returned again by getAddonInfo().

* naming.json: Fix missing comma

* CLI: Fix naming violations detected by addon naming.py via naming.json

* Addon naming: Add argument for validating names of constants

* LIB: Rename functions/variables so they are valid, loosen naming rules

* GUI: Fix naming violations
2019-11-20 15:37:09 +01:00
IOBYTE 7f6ebaa6b2 fix syntax error for VTK_LEGACY_BODY(vtkMatrix3x3::operator[], "VTK 7.0"); (#2372) 2019-11-18 06:38:53 +01:00
IOBYTE 754c1fff66 fix syntax error for conversion operator for type with global namespace (#2365)
* fix syntax error for conversion operator for type with global namespace

* fix syntax error when taking address of operator function

* fix syntax error for using ::operator "" _a;

* fix syntax error for template<> void operator "" _h<'a', 'b', 'c'>() {}

* fix syntax error for operator in parentheses
2019-11-16 08:03:13 +01:00
Daniel Marjamäki b9835fd4f9 Fixed #9445 (Syntax error on typeof word in C) 2019-11-15 21:20:57 +01:00
IOBYTE 3a617fa04a Fix #9472 (Syntax error on valid C++ code) (#2363)
There are probably a lot more valid code patterns that generates syntax
errors so I added "operator" to the error message to make it easier to
find them.
2019-11-15 07:03:57 +01:00
Daniel Marjamäki 7e0fc4fb00 Tokenizer: Detect more syntax errors when operator does not have operands 2019-11-14 21:18:31 +01:00
IOBYTE 2eb575d990 Fix #9468 (Syntax error on valid C++) (#2358) 2019-11-14 09:26:21 +01:00
IOBYTE 0fed6f0091 fix clang testsuite crash (#2341) 2019-11-09 18:00:21 +01:00
Daniel Marjamäki 8c8952ae7c Fixed #9324 (FP compareBoolExpressionWithInt - when using C++ and/or operator synonyms) 2019-11-03 12:53:30 +01:00
Daniel Marjamäki 791242ea78 Fixed #6975 and #9376 (Tokenizer: unknown macro without semicolon) 2019-11-02 19:34:19 +01:00
IOBYTE 3f0ef01154 Fix #9446 (Syntax error on valid C++ code) (#2316) 2019-11-01 09:11:29 +01:00
Daniel Marjamäki b96a347914 Tokenizer: Report unknown macro when argument list contains if/for/while/switch 2019-10-30 19:36:19 +01:00
Rikard Falkeborn 5c061c1c12 Set correct type and size of string and char literals (#2275)
* Set correct type and size of string and char literals

Use that string and char literal tokens store the prefix. This makes
it possible to distinghuish between different type of string literals
(i.e., utf8 encoded strings, utf16, wide strings, etc) which have
different type.

When the tokens holding the string and character values have the correct
type, it is possible to improve Token::getStrSize() to give the correct
result for all string types. Previously, it would return the number of
characters in the string, i.e., it would give the wrong size unless
the type of the string was char*.

Since strings now can have different size (in number of bytes) and
length (in number of elements), add a new helper function that returns
the number of characters. Checkers have been updated to use the correct
functions.

Having the size makes it possible to find more problems with prefixed
strings, and to reduce false positives, for example in the buffer
overflow checker.

Also, improve the stringLiteralWrite error message to also print the
prefix of the string (if there is one).

* Add comment and update string length
2019-10-20 07:11:57 +02:00
IOBYTE e4d2e9d2af Fix #9421 (syntaxError on incomplete code (from z3)) (#2274) 2019-10-16 20:56:53 +02:00
Rikard Falkeborn 297360920a Keep prefix in string and char literals (#2272)
Keeping the prefix in the token allows cppcheck to print the correct
string and char literals in debug and error messages.

To achieve this, move some of the helper functions from token.cpp to
utils.h so that checks that look at string and char literals can reuse
them. This is a large part of this commit.

Note that the only user visible change is that when string and char
literals are printed in error messages, the prefix is now included.

For example:

	int f() {
		return test.substr( 0 , 4 ) == U"Hello" ? 0 : 1 ;
	};

now prints U"Hello" instead of "Hello" in the error message.
2019-10-16 11:41:33 +02:00
Daniel Marjamäki 62d972061b astyle formatting
[ci skip]
2019-10-14 19:41:51 +02:00
Sebastian 267d23f1b8
gnu.cfg: Define `__typeof__` as `typeof`, fix simplifyTypedef() (#2260)
`__typeof__` is just an alternative keyword for `typeof`, see
https://gcc.gnu.org/onlinedocs/gcc/Typeof.html
Since `typeof` is handled in several checkers it makes sense to define
`__typeof__` as `typeof`.
Tokenizer::simplifyTypedef(): Use `typeof` instead of `__typeof__` to
be consistent with the rest of the code.
2019-10-14 08:20:22 +02:00
KenPatrickLehrmann 5a08ac361a Better handle const/noexcept methods (#2211)
* Better handle const/noexcept methods/conversion operator

const or noexcept in a method / (conversion) operator definition were
badly parsed, ending in a bad ast.
This patch tries to make it better, at least making the ast less bad,
so as to avoid errors in later checks.

* Fix parsing of some operator

It is still very broken, but at least, it does not fail.

Here is the previous error:
```
TestSimplifyTypedef::simplifyTypedef129
terminate called after throwing an instance of 'InternalError'

Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
51	../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
 #0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
 #1  0x00007ffff612a801 in __GI_abort () at abort.c:79
 #2  0x00007ffff6b1d957 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
 #3  0x00007ffff6b23ab6 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
 #4  0x00007ffff6b23af1 in std::terminate() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
 #5  0x00007ffff6b23d24 in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
 #6  0x0000555556366bf8 in Tokenizer::cppcheckError (this=0x7fffffffc2d0, tok=0x607000006760) at ../lib/tokenize.cpp:8721
 #7  0x000055555636a4bb in Tokenizer::validate (this=0x7fffffffc2d0) at ../lib/tokenize.cpp:9154
 #8  0x000055555633e3aa in Tokenizer::simplifyTokenList1 (this=0x7fffffffc2d0, FileName=0x603000002d50 "test.cpp") at ../lib/tokenize.cpp:4477
 #9  0x00005555563223ca in Tokenizer::simplifyTokens1 (this=0x7fffffffc2d0, configuration="") at ../lib/tokenize.cpp:2286
 #10 0x00005555563235c8 in Tokenizer::tokenize (this=0x7fffffffc2d0, code=..., FileName=0x555556fda9a0 "test.cpp", configuration="") at ../lib/tokenize.cpp:2345
 #11 0x00005555569410ea in TestSimplifyTypedef::tok[abi:cxx11](char const*, bool, cppcheck::Platform::PlatformType, bool) (this=0x555557728580 <(anonymous namespace)::instance_TestSimplifyTypedef>,
     code=0x7fffffffcb70 "class c {\n  typedef char foo[4];\n  foo _a;\n  constexpr operator foo &() const noexcept { return _a; }\n};", simplify=false, type=cppcheck::Platform::Native, debugwarnings=true) at ../test/testsimplifytypedef.cpp:192
 #12 0x000055555697239e in TestSimplifyTypedef::simplifyTypedef129 (this=0x555557728580 <(anonymous namespace)::instance_TestSimplifyTypedef>) at ../test/testsimplifytypedef.cpp:2599
 #13 0x000055555694092c in TestSimplifyTypedef::run (this=0x555557728580 <(anonymous namespace)::instance_TestSimplifyTypedef>) at ../test/testsimplifytypedef.cpp:167
 #14 0x00005555569cab84 in TestFixture::run (this=0x555557728580 <(anonymous namespace)::instance_TestSimplifyTypedef>, str="simplifyTypedef129") at ../test/testsuite.cpp:306
 #15 0x00005555569cb445 in TestFixture::runTests (args=...) at ../test/testsuite.cpp:329
 #16 0x000055555687bdfb in main (argc=2, argv=0x7fffffffd988) at ../test/testrunner.cpp:44
```

* Replace some ASSERT_EQUALS with TODO_ASSERT_EQUALS when the actual result is still wrong

* Remove invalid code from simplifyTypedef129

* Properly skip parentheses
2019-10-12 11:46:00 +02:00
IOBYTE f99e83ece0 Fix #9411 (new daca crash related to using namespace) (#2264) 2019-10-12 11:39:14 +02:00
IOBYTE c98732dd8b fix using type aliases in out of class destructors (#2250) 2019-10-08 19:30:41 +02:00
Steve Mokris 506a952ad2 Parse `extern "C"`, and use it to avoid FP reference warnings (#2234)
Previously, cppcheck discarded the `extern "C"` specifier.  This patch modifies cppcheck to parse each as a Scope in the symbol database, then uses that scope to avoid false positives when making recommendations about changing a function argument to be a reference (since variable references is a C++ feature, unavailable in C, and thus unavailable in `extern "C"`).
2019-10-08 17:48:09 +02: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 46f3f58e5f Fix #9388 ("debug: Executable scope 'x' with unknown function." with alias used in initialization list) (#2239) 2019-10-05 09:34:37 +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
IOBYTE 50d82763fc Fix #9385 ("debug: Executable scope 'func' with unknown function" with parameter in member function) (#2235) 2019-10-03 21:13:03 +02:00
IOBYTE 3e17c24dd8 fix syntax error on template operator (#2225) 2019-10-03 12:26:45 +02:00
IOBYTE 4ba00d0694 Fix #9381 (alias in namespace not replaced in method declaration) (#2232) 2019-10-02 08:11:04 +02:00
IOBYTE d0968a1377 Warn about unknown macro causing template syntax error (#2222) 2019-09-26 16:01:01 +02:00
IOBYTE 4475c4c7e2 template simplifier: fix syntax error (#2218) 2019-09-26 10:31:19 +02:00
Oliver Stöneberg eac040a00b Various clang-tidy fixes (#2192)
* use range loops

* removed redundant string initializations

* use nullptr

* use proper boolean false

* removed unnecessary continue from end of loop

* removed unnecessary c_str() usage

* use emplace_back()

* removed redundant void arguments
2019-09-25 15:25:19 +02:00
Oliver Stöneberg 9028b4a81d do not access static methods through instance (#2189) 2019-09-20 21:54:30 +02:00
IOBYTE 8c5cf8c029 Fixed #9046 syntaxError (#2180)
* Fixed #9046 syntaxError

* fix another syntax error

* fix some more syntax errors
2019-09-20 12:35:01 +02:00
Daniel Marjamäki 033640310b One more fix for #9354 (Unknown macro is not reported and then Cppcheck is silent about issues) 2019-09-15 21:07:20 +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
Thomas Niederberger d122b1c722 Fix issue with __declspec and final (#2107)
* Add missing Qt macros

Add two Qt macros that were missing

* Fix issue with __declspec and final

This change is a bit naive but it fixes the issues I was having when combining __declspec(dllexport) and final classes. Without the fix I get errors along the line of "The code 'class x final :' is not handled. You can use -I or --include to add handling of this code. "
2019-08-23 06:43:02 +02:00
IOBYTE 4b231c53a4 Fixed #9287 and #9288 (Syntax error on valid C++ code) (#2104) 2019-08-20 20:25:18 +02:00
Daniel Marjamäki ef47d3d304 Fixed #9286 (FP: syntax error: { .abc.a = 1) 2019-08-20 13:56:38 +02:00
Daniel Marjamäki 2d9a131817 Refactoring: Rename variables. Do not use leading _. Renamed 'col' to 'column' 2019-08-18 12:19:05 +02:00
Paul Fultz II 3e0d1141d3 Fix issue 9277: FP: Dont warn for knwon conditions in if constexpr (#2085) 2019-08-16 07:56:39 +02:00
Daniel Marjamäki f33a8a417f Put 'isExpandedMacro' info in the dump files 2019-08-15 14:24:56 +02:00
IOBYTE c6c50567cf Fix #9250 (Regression: crash in gcc testsuite) (#2067)
* Fix #9250 (Regression: crash in gcc testsuite)

* fix cppcheck warning
2019-08-07 08:05:02 +02:00
Daniel Marjamäki ebcca4edd1 Improve --debug-warnings output for 'auto' tokens without type. Do not report that prematurely before the type is set properly. 2019-08-05 13:42:06 +02:00
Daniel Marjamäki cdc602e1be Fixed #9137 (Tokenizer: Wrong handling of volatile pointer) 2019-08-03 12:28:50 +02:00
rebnridgway d2b9c1f15a Fix some bugs in new Scope Calculation code (#2060)
* Fix for too much information in scope name

When the scope calculation encounters code such as 
"friend class X::Y;"
or
"template<> class X<void> {"
it will now reset the additional name component of the scope that is about to be opened.

* Made sure new scope name is reset after being used
2019-08-02 19:55:08 +02:00
orbitcowboy a9bdf99e07 std.cfg: Added *experimental* support for math constants liken M_PI. These are *NOT* standard, but they are supported by GCC/Clang and VS. 2019-07-31 11:11:01 +02:00
rebnridgway e629f9a90f Calculate token scopes in advance rather than as the tokenlist is iterated (#2038)
* Removed redundant scope calculation

* Add scope propagation code to insertToken

* Add relevant scope code to Token class

* Add code to calculate the scope of Tokens

* Add calculateScopes method to class

* Add missing include for shared_ptr
2019-07-31 09:19:27 +02:00
IOBYTE 07ac6c5f08 Fix ternary operator simplification to accept template parameters. (#2048)
Also simplify decltype of bool and numeric literals in template
arguments.
2019-07-28 21:52:52 +02:00
IOBYTE 999d2f797c Fix #9225 (Crash on valid C++14 code) (#2031)
* Fix #9225 (Crash on valid C++14 code)

This only fixes the crash. Specialization of nested templates is still
broken.

* fix cppcheck warnings

* fixed another cppcheck warning
2019-07-24 19:20:19 +02:00
Daniel Marjamäki 2da75d5af4 Split up Cppcheck attribute. low and high values can be specified separately and they can be used for variables also. 2019-07-24 15:08:26 +02:00
Paul Fultz II 8cd8a2671c Fix issue 9211: No error on divide by zero outside template instatiation
I am not sure how to add a test for this.
2019-07-18 14:55:30 +02:00
Daniel Marjamäki 64ef879ebf Fix syntaxError for struct initialization 2019-07-17 15:21:17 +02:00
Daniel Marjamäki b15e6801a4 Replace 'unsigned' with 'nonneg' in tokenizer 2019-07-17 10:36:49 +02:00
Daniel Marjamäki b3688f22e8 Unknown macro: Detect and warn about unknown macro before throw/return 2019-07-16 20:32:46 +02:00
Daniel Marjamäki 7a4a9eba4b remove cast 2019-07-16 09:28:48 +02:00
Daniel Marjamäki af051a3787 astyle formatting
[ci skip]
2019-07-15 09:29:47 +02:00