Commit Graph

439 Commits

Author SHA1 Message Date
dummyunit ac505afe69
Fixed #9729 (AST broken: lambda with noexcept keyword) (#3243)
The previous fix for the issue (43b58dbc9e) didn't seem to actually fix
it because it added a check for noexcept without a condition, but when
AST is created noexcept always has a condition due to simplification
from "noexcept" to "noexcept(true)" in Tokenizer::simplifyKeyword().
The issue from the ticket couldn't be reproduced neither on 43b58dbc9e
nor on the previous commit, so it is hard to tell whether the fix was
effective or not.

The issue appeared again after a refactoring of AST code in ac67049661.
Test added with the original fix was unable to catch that because it
used testAst() helper function which skips most simplification steps.

To fix the issue we now check for noexcept with a condition and add a
proper regression test that:
1. Uses tokenizeAndStringify() to ensure that all simplifications are
   performed before AST is created.
2. Parses the code snippet from the ticket, as having "if (cond)" is
   crucial to reproducing the original issue (internalAstError).

Also fix AST creation for lambdas that have both constexpr and mutable
keywords.
2021-05-02 21:34:28 +02:00
Daniel Marjamäki d2d2124238 Revert "Clang import; This experimental feature didn't "take off" much. After a lot of work we are still far fram the goal. I remove it now but don't rule out completely that it could ever be added again."
This reverts commit 207361b174.
2021-04-30 16:47:02 +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 a41d8b436e Fix testrunner 2021-04-24 14:07:26 +02:00
Daniel Marjamäki c9dc92c266 Parser; C++20 for loop with initialization expression 2021-04-24 11:47:51 +02:00
Daniel Marjamäki 26c0945309 Handle c++20 spaceship operator 2021-04-22 19:15:22 +02:00
Daniel Marjamäki 207361b174 Clang import; This experimental feature didn't "take off" much. After a lot of work we are still far fram the goal. I remove it now but don't rule out completely that it could ever be added again. 2021-04-21 18:59:48 +02:00
Daniel Marjamäki 42437277dc Update Copyright year 2021-03-21 20:58:32 +01:00
Oliver Stöneberg ac7647fcd8
some self-check suppression cleanups (#3032) 2021-01-09 20:32:38 +01:00
orbitcowboy f1688667a5 Running astyle [ci skip] 2020-12-27 12:38:21 +01:00
Daniel Marjamäki d024eb3ee0 Fixed #10051 (AST: Wrong ast for function call with initializer list) 2020-12-26 18:33:54 +01:00
IOBYTE 6103da59be
add column number to TokenList::addtoken (#2939) 2020-12-08 10:34:23 +01:00
Daniel Marjamäki 58af3c7ad7 Suppress Cppcheck false positive 2020-12-04 19:37:58 +01:00
Daniel Marjamäki c69bfbf495 AST: Fixed ast for multidimensional array initialisation 2020-12-02 07:38:21 +01:00
Daniel Marjamäki af26697ceb AST: Generate proper AST for 'f = []() -> foo&& {}' 2020-11-28 06:53:46 +01:00
Daniel Marjamäki b4db52bf61 Fixed #9860 (wrong ast for placement new 'new ( uBAR ? uBAR : sizeof ( T ) ) T') 2020-11-23 22:03:50 +01:00
Daniel Marjamäki 22d6160624 Improve handling of decltype 2020-11-16 20:11:26 +01:00
Daniel Marjamäki 7878eb2512 AST: Do not generate AST for decltype 2020-11-15 16:47:36 +01:00
Ken-Patrick Lehrmann 7c3afa0b36
9955: Fix ast when throwing a cast (#2900)
```
throw (std::string)"Error: " + strerror(errnum);
```
would result in a broken ast:
```
throw
`-::
  |-std
  `-string
```
instead of
```
throw
`-+ 'signed char *'
  |-( 'container(std :: string|wstring|u16string|u32string)'
  | `-"Error: " 'const char *'
  `-( 'signed char *'
    |-strerror
    `-errnum 'signed int'
```
2020-11-15 10:37:29 +01:00
Daniel Marjamäki 26e6eed189 Revert "AST: Adjust AST for variable declaration 'char var[] = str;'"
This reverts commit 376860f796.
2020-11-01 11:41:41 +01:00
Daniel Marjamäki 376860f796 AST: Adjust AST for variable declaration 'char var[] = str;' 2020-10-31 17:05:42 +01:00
Daniel Marjamäki 4eb829933e Tokenizer: Fixed unwanted unknownMacro warning for decltype 2020-10-27 09:08:13 +01:00
Daniel Marjamäki c3517924d0 Clang import testing: Compare AST 2020-10-04 11:27:31 +02:00
Daniel Marjamäki 2748201d73 Fixed #9782 (Segmentation fault due to broken AST) 2020-09-27 20:41:09 +02:00
Daniel Marjamäki 0ec77879ea Fix crash in createAST when checking wiggle in daca@home 2020-09-26 19:22:24 +02:00
Daniel Marjamäki c563944fdd astyle formatting 2020-09-20 20:14:30 +02:00
shaneasd 53a0760fdf
Improve ast generation for templated function parameters (#2803) 2020-09-14 18:44:50 +02:00
Paul Fultz II ac67049661
Fix issue 9858: Token::astOperand1() cyclic dependency on valid C++ code (#2784) 2020-09-07 10:54:32 +02:00
Paul Fultz II cc2bc74084
Track lifetime for lambdas with explicit capture (#2776) 2020-09-05 07:56:01 +02:00
Daniel Marjamäki 2bb73840fc astyle formatting 2020-08-23 17:17:33 +02:00
Daniel Friedrich f413c9cad8 Improve handling of decltype( in for loops
Simplify pattern macht and token selection

Improve handling of decltype( in for loops
2020-08-17 20:52:14 +02:00
Daniel Marjamäki 7e65b561f0 AST: Fix ast for 'for ((..initexpr..);;)' 2020-07-19 11:10:38 +02:00
Daniel Marjamäki 9b5986505e AST; Improved ast for variable declaration with assignment 2020-06-22 08:34:31 +02:00
Ken-Patrick Lehrmann 7ddb7aef7d 8526: Fix ast construction for ternary operator
This tries to decide a bit more properly when ':' can be part of a
ternary operator. More precisely, there are some times when we want to
delay the construction of the ast for ':', so that it is place
accordingly to the matching '?'.

Typically, this fixes an issue with
`return val < 0 ? throw 1 : val;`,
where the ast for ':' would be constructed during as part of the
`throw`, and the ast for `?` would be invalid.

This patch is a bit of a hardcode, stating that we don't expect ':'
inside a throw, unless there is a complete ternary operator in there
(there can't be a range based for loop, a case in a switch). When we
reach ':', we know we are and the end of the `throw`.
2020-06-14 18:57:18 +02:00
Ken-Patrick Lehrmann 4023a487ff 9768: Fix ast with throw in the middle of return
```
int f(bool x)
{
    return x ? 0 : throw 0;
}
```

The `throw` part was not included in the ast, leading to an invalid
ternary operator.
2020-06-14 14:49:10 +02:00
Daniel Marjamäki d31d778bf4 Fixed #9533 (Syntax Error: AST broken, 'for' doesn't have two operands incrementing pointer in initializer) 2020-06-09 20:57:00 +02:00
Ken-Patrick Lehrmann 084529575f
Skip ast validation inside template (#2661) 2020-05-23 21:11:08 +02:00
Oliver Stöneberg 37bc0483a4
made check.h less heavy (#2633) 2020-05-23 07:16:49 +02:00
Daniel Marjamäki 43b58dbc9e Fixed #9729 (AST: lambda with noexcept) 2020-05-22 11:29:10 +02:00
Daniel Marjamäki ac1ceb85b6 AST: improved AST when expression starts with %char% or %str% 2020-05-22 09:35:55 +02:00
Daniel Marjamäki ffdf13fcdb AST: A little code cleanup 2020-05-22 08:48:06 +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
Daniel Marjamäki 259724d6e3 astyle formatting
[ci skip]
2020-05-18 19:53:35 +02:00
shaneasd 7bfd686f04
Fix #9700 duplicateBranch false positive from missing scope operator :: in ast (#2646) 2020-05-18 19:31: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
Zorgovskiy 08fc956990
Fixes issue #9664 (#2614) 2020-04-20 08:59:35 +02:00
Daniel Marjamäki 3c56ccc33f Fixed #9531 (Syntax Error: AST broken, 'for' doesn't have two operands.) 2020-04-19 17:00:22 +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 e0c8118c02 Fixed crash in AST 2020-04-09 17:42:51 +02:00
Paul Fultz II 40e1e82a65
Fix issue 9644: Token::astOperand1() cyclic dependency on valid C++ code (#2590)
* Remove check for lambda

* Add test case
2020-04-04 10:55:31 +02:00
Paul Fultz II 58e3f19ed8
Fix issue 9662: AST broken, ternary operator missing operand(s) on valid C++ code (#2589)
* Fix issue 9662: AST broken, ternary operator missing operand(s) on valid C++ code

* Add test for issue 9537
2020-04-03 10:04:10 +02:00
Daniel Marjamäki 1008868506 AST: Better handling of '(type){..}' 2020-03-08 16:46:06 +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 5376ba1701 AST: Throw validation exception if ternary operator is missing operands 2020-03-07 21:46:38 +01:00
Daniel Marjamäki baa4cee70c Travis: Fixed Cppcheck warning 2020-02-27 10:51:34 +01:00
Daniel Marjamäki 38b570138f AST: Try to handle c++17 for properly 'for (auto [a,b]:c)' 2020-02-27 09:58:53 +01:00
Daniel Marjamäki e4937ed621 AST: Fixed wrong AST for cast '(std::vector<int>&&)s->second' 2020-02-25 21:05:49 +01:00
Daniel Marjamäki ef26b55737 AST: Fix wrong handling for '{scope} (expr)' 2020-02-23 15:01:06 +01:00
Daniel Marjamäki f07a71e3e1 Report unknown macros for pattern '%name% %num%' 2020-02-22 11:57:36 +01:00
Daniel Marjamäki cf10b1a220 fix ast for expression that starts with number 2020-02-21 21:11:32 +01:00
Daniel Marjamäki 388b5118df Fixed bad ast (wrong result from iscast()) 2020-02-21 17:15:33 +01:00
Rikard Falkeborn f6e7fb4bd9
Bugfix valuetype for some integer constants (#2545) 2020-02-19 07:51:39 +01:00
Daniel Marjamäki 89cb0187d0 Travis: Use simpleMatch for simple pattern 2020-02-16 21:47:46 +01:00
Paul Fultz II 921887a281
Use valueFlowGeneric for valueFlowForwardExpression (#2537) 2020-02-16 16:02:22 +01:00
Daniel Marjamäki a350ed9bc2 Fixed #9023 (AST: wrong lhs for a = b + foo(A::Hash{}(""))) 2020-02-16 13:58:43 +01:00
Paul Fultz II e55ddacd18
Fix issue 9597: False positive: Reference to temporary returned if explicitly casted to base class (#2531) 2020-02-11 11:41:41 +01:00
Daniel Marjamäki b03bdfaf72 Import Clang ast dump (experimental) 2020-01-05 15:12:53 +01:00
Paul Fultz II e07801a891 Fix issue 9563: new daca crash: findLambdaEndToken not finding end token (#2472) 2020-01-04 10:45:24 +01:00
Paul Fultz II ad352daa08 Fix issue 9535: Syntax Error: AST broken, 'if' doesn't have two operands. (#2450) 2019-12-16 12:17:01 +01:00
orbitcowboy f89adef1c1 Running astyle [ci skip] 2019-12-11 15:01:21 +01:00
Paul Fultz II ad2f71338c Fix issue 9525: Syntax Error: AST broken, 'if' doesn't have two operands inside lambda (#2433)
* Fix issue 9525: Syntax Error: AST broken, 'if' doesn't have two operands inside lambda

* Fix incorrect matchers
2019-12-10 21:21:07 +01:00
Paul Fultz II ea2916a3e4 Fix issue 9514: Syntax Error: AST broken, 'for' doesn't have two operands. (#2429)
* Fix issue 9514: Syntax Error: AST broken, 'for' doesn't have two operands.

* Fix typo
2019-12-07 21:16:25 +01:00
Paul Fultz II 56e17fb228 Fix issue 9524: Syntax Error: AST broken, 'if' doesn't have two operands. (#2432) 2019-12-07 21:06:45 +01:00
Paul Fultz II 2978c67e6f Fix issue 9511: Syntax Error: AST broken, 'if' doesn't have two operands. (#2428) 2019-12-06 04:19:46 +01:00
amai2012 0e8a145d6c Run astyle 2019-12-02 22:04:22 +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 937c82efbe AST: initializer list with lambda 2019-11-27 06:44:58 +01:00
Daniel Marjamäki ab2274b8ad AST: lambdas and scopes in expressions 2019-11-23 21:36:36 +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
Paul Fultz II 479fbb85a2 Fix issue 9443: Internal error: Token::astOperand2() cyclic dependency. (#2376)
* Improve nested init lists

* Fix issue 9443: Internal error: Token::astOperand2() cyclic dependency.
2019-11-19 11:38:03 +01:00
Daniel Marjamäki 03ae0ccef3 AST: Do not hang for code 'foo({ for (a;b;c) {} });' 2019-11-03 11:02:59 +01:00
Daniel Marjamäki 35d04cd2d3 AST: non-standard handling of ; in argument list for unknown macro 2019-11-01 09:05:45 +01:00
Daniel Marjamäki 277c59e5f3 AST: Fixed AST for lambda that returns template type 2019-10-30 16:05:34 +01:00
Daniel Marjamäki 2c1905cc2b AST: Somewhat better handling of '{x}' function parameters 2019-10-27 12:00:08 +01:00
Daniel Marjamäki f03945a9e2 AST: better handling when returning list of lambdas 2019-10-26 19:19:20 +02:00
Daniel Marjamäki cf1dd2e6f6 AST: Fix AST when returning list of lambda functions 2019-10-22 18:39:59 +02:00
Daniel Marjamäki b97436e8f8 Fixed #9382 (Hang: CheckLeakAutoVar pellepl/spiffs/src/spiffs_hydrogen.c) 2019-10-06 09:52:05 +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
Oliver Stöneberg de9f489b08 use range loops / constness (#2181)
* use range loops / constness

* platform.cpp: avoid shadowed variable
2019-09-19 20:29:33 +02:00
Paul Fultz II 9753e18ebd Fix issue 9340: AST broken: endless recursion from '{' (#2161) 2019-09-09 21:35:49 +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
Daniel Marjamäki af449779f0 astyle formatting
[ci skip]
2019-09-03 06:43:08 +02:00
Ken-Patrick Lehrmann 5c172bb55a Fix issue 8897: Huge array initializations (#2135)
* Fix issue 8897: Huge array initializations

iscpp11init would take a lot of time when parsing huge arrays.
This patch add memoization to keeps track that we are parsing an array,
and allows to propagate the result without re-parsing the array for each
of its members.

* Use enum class instead of enum
2019-09-02 20:31:01 +02:00
Daniel Marjamäki 6815e38879 TokenList::insertTokens: copy column also 2019-08-20 20:53:44 +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
IOBYTE 04bb6c0d1f template simplifier: fix new daca crashes (#2093) 2019-08-17 07:38:07 +02:00
Daniel Marjamäki e9b12b1fe0 Replace 'unsigned' with 'nonneg' 2019-07-17 10:14:25 +02:00