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
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
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
f7f26ffe90
Tokenizer: Better handling of c alternative tokens in const method
2020-05-25 15:07:23 +02:00
Ken-Patrick Lehrmann
084529575f
Skip ast validation inside template ( #2661 )
2020-05-23 21:11:08 +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
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
f5f7cb7ff7
test: Removed AstStyle::Verbose
2020-05-19 18:27:44 +02:00
shaneasd
44a3501f1b
cleanup after #9700 ( #2648 )
2020-05-19 18:15:05 +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
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
06cb0e99d1
Tokenizer: Fix syntax error when operator* is called
2020-05-04 21:33:30 +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
3c56ccc33f
Fixed #9531 (Syntax Error: AST broken, 'for' doesn't have two operands.)
2020-04-19 17:00:22 +02:00
Daniel Marjamäki
98be091d80
Fixed typedef simplification for array of function pointers
2020-04-13 16:28:01 +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
0725c2290c
Tokenizer: Do not simplify function pointers to normal pointers as we loose important information
2020-04-10 11:53:32 +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
Daniel Marjamäki
e0acd1abf8
Tokenizer: Report unknown macro that contains '.x=..' argument
2020-04-04 10:32:56 +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
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
5376ba1701
AST: Throw validation exception if ternary operator is missing operands
2020-03-07 21:46:38 +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
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
ec8c733afb
Improved Qt simplification
2020-02-21 19:04:21 +01:00
Daniel Marjamäki
388b5118df
Fixed bad ast (wrong result from iscast())
2020-02-21 17:15:33 +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
ae0a73a538
Fixed #9618 (isCast flag not set for c++ casts)
2020-02-16 16:46:40 +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
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
Paul Fultz II
e07801a891
Fix issue 9563: new daca crash: findLambdaEndToken not finding end token ( #2472 )
2020-01-04 10:45:24 +01:00
Daniel Marjamäki
c84ba10b37
Fixed #8774 (Wrong handling of function with name 'or')
2019-12-19 19:22:39 +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
Daniel Marjamäki
f614d32d6a
Fixed #9519 (Syntax error on valid C++ 'enum {} (a)')
2019-12-15 08:40:04 +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
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
IOBYTE
f637d97080
Fix 9509 (Syntax error on empty attribute list) ( #2423 )
2019-12-06 05:17:19 +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
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
ab2274b8ad
AST: lambdas and scopes in expressions
2019-11-23 21:36:36 +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
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
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
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
IOBYTE
2eb575d990
Fix #9468 (Syntax error on valid C++) ( #2358 )
2019-11-14 09:26: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
03ae0ccef3
AST: Do not hang for code 'foo({ for (a;b;c) {} });'
2019-11-03 11:02:59 +01:00
Daniel Marjamäki
791242ea78
Fixed #6975 and #9376 (Tokenizer: unknown macro without semicolon)
2019-11-02 19:34:19 +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
b96a347914
Tokenizer: Report unknown macro when argument list contains if/for/while/switch
2019-10-30 19:36:19 +01:00
Daniel Marjamäki
8c591308cb
astyle formatting
...
[ci skip]
2019-10-30 18:19: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
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
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
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
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
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
ef47d3d304
Fixed #9286 (FP: syntax error: { .abc.a = 1)
2019-08-20 13:56:38 +02:00
Daniel Marjamäki
cdc602e1be
Fixed #9137 (Tokenizer: Wrong handling of volatile pointer)
2019-08-03 12:28:50 +02:00
Daniel Marjamäki
64ef879ebf
Fix syntaxError for struct initialization
2019-07-17 15:21:17 +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
af051a3787
astyle formatting
...
[ci skip]
2019-07-15 09:29:47 +02:00
Denis
68e6a440ff
Fix adding unescaped slash token when splitting gcc case range. ( #1987 )
...
* Fix adding unescaped slash token when splitting gcc case range.
Construction like case '!'...'~' converted to a list of separate case
tokens. When slas '\' symbol appears as a part of this list it was added
"as is", but it should be escaped like '\\' to be valid c++ code.
* Add test for switch-case range with slash
2019-07-15 09:29:31 +02:00
Paul Fultz II
65af02f0cf
Fix crash with lambda capture ( #1960 )
2019-07-06 10:46:17 +02:00
Paul Fultz II
5801fb26f0
Fix syntax error with lambda captures ( #1954 )
...
* Fix syntax error with lambda captures
* Fix issue when using initializer in lambdas
2019-07-05 12:26:01 +02:00
Scott Furry
a195477470
Correct Zero/Null as pointer constant ( #1938 )
...
Building with enhanced clang warnings indicated a large number of
instances with the warning:
`warning: zero as null pointer constant`
Recommended practice in C++11 is to use `nullptr` as value for
a NULL or empty pointer value. All instances where this warning
was encountered were corrected in this commit.
Where warning was encountered in dependency code (i.e. external library)
no chnages were made. Patching will be offered upstream.
2019-06-30 21:39:22 +02:00
IOBYTE
c0d8990e8b
Fix up a few more cases where templates ending in ">>" should be changed to end in "> >". ( #1883 )
2019-06-13 13:37:55 +02:00
IOBYTE
2a4b28c267
Fixed #9155 (Syntax error on valid C++ code) ( #1880 )
...
Refactored simplifyTemplateAliases to iterate over template type aliases
rather than instantiations. This fixed template type aliases that were
not templates.
Don't instantiate templates in template type aliases. They will get
instantiated once the type alias is instantiated. This required
increasing the template simplifier pass count to 3 so one of the
existing tests continued to work.
2019-06-12 07:44:48 +02:00
Paul Fultz II
b863c18e1d
Fix crash in issue 9007 ( #1878 )
2019-06-10 08:24:09 +02:00
Paul Fultz II
169510bd3a
Fix issue 9171: Endless recursion ( #1877 )
2019-06-10 08:22:48 +02:00