Commit Graph

1422 Commits

Author SHA1 Message Date
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
Paul Fultz II 1f24aa778b Fix issue 9156: Analysis failed because square brackets arent linked correctly (#1871) 2019-06-09 08:10:57 +02:00
IOBYTE f02e45bf3d fix syntax error for std::literals::complex_literals::operator""if (#1870) 2019-06-05 10:15:22 +02:00
Paul Fultz II 676a241137 Add regression tests for syntax errors (#1866) 2019-06-02 10:23:27 +02:00
IOBYTE bee248b2de token simplifier: fix namespace, token link and syntax error support for template type aliases (#1863) 2019-06-01 10:52:29 +02:00
Paul Fultz II 33130bdff6 Fix issue 9145: Syntax error on valid C++14 code (#1860) 2019-05-31 08:05:01 +02:00
IOBYTE 1e7f5010eb template simplifier: fix expansion of template arguments in default parameter instantiation (#1857) 2019-05-28 21:32:37 +02:00
Paul Fultz II 312fdf157b Fix issue 9144: Syntax error with type intrinsics (#1852)
* Fix issue 9144: Syntax error with type intrinsics

* Only run when using cpp
2019-05-27 06:54:21 +02:00
Paul Fultz II 61935802d1 Fix issue 9141: Syntax error (#1853) 2019-05-27 06:50:43 +02:00
Paul Fultz II cb7f925f5e Fix issue 9109: Syntax error for valid C++ code 2019-05-24 10:44:08 +02:00
Daniel Marjamäki de4a33167d astyle formatting
[ci skip]
2019-05-21 10:43:33 +02:00
Paul Fultz II 9055682fdc Fix synax error in issue 9057 and 9138 (#1843) 2019-05-21 08:47:10 +02:00
Paul Fultz II ce96ec2773 Fix issue 9136: Syntax error on valid C++14 code: createLinks2() failed 2019-05-19 19:06:12 +02:00
Paul Fultz II 8cbd9b03aa Fix issue 8890: AST broken calling member function from templated base class (#1836)
* Fix issue 8890: AST broken calling member function from templated base class

* Format

* Check for double bracket

* Add test to createLinks2

* Remove extra test

* Reduce test case for links
2019-05-19 10:05:34 +02:00
Daniel Marjamäki 57c6628732 Revert 'Cleaning up unsimplified templates'. This fix caused problems. 2019-05-16 21:11:04 +02:00
Daniel Marjamäki 0144db2490 Fixed 'Syntax Error' when < link is not set properly 2019-05-15 21:34:56 +02:00
Daniel Marjamäki 79bb22f038 Fixed #9131 (Tokenizer::createLinks2; using std::list; list<config_option*> stack;) 2019-05-14 20:30:02 +02:00
Daniel Marjamäki 9f00149674 Fixed #9127 (ast: wrong ast after using and template instantiation) 2019-05-12 17:24:42 +02:00
Daniel Marjamäki 4d9b1e6c3d Fixed #9094 (Tokenizer::createLinks2 problem with 'x%x<--a==x>x') 2019-05-11 19:11:40 +02:00
Daniel Marjamäki 1e2f1bac1f Fixed #8921 (Broken AST - mem = (void*)(new char)) 2019-05-11 15:50:30 +02:00
Daniel Marjamäki d58d4273f9 Cleaning up unsimplified templates 2019-05-11 13:00:03 +02:00
IOBYTE eade2bb2c2 Add support for simplifying user defined literal operator. (#1827) 2019-05-09 09:52:18 +02:00
Daniel Marjamäki 45a343ac2d Fixed #8795 (Syntax Error: AST broken, binary operator '||' doesn't have two operands) 2019-05-04 19:05:03 +02:00
Daniel Marjamäki 5e9b7a6749 Cleanup AST tests. The best would be if 'operators' in declarations was not included at all in the AST. 2019-05-04 07:31:59 +02:00
Rikard Falkeborn c7d7f8738c Optimize astStringVerbose() for large arrays (#1815)
Change the astStringVerbose() recursion to extend a string instead of
returning one. This has the benefit that for tokens where the recursion
runs deep (typically large arrays), the time savings can be substantial
(see comments on benchmarks further down).

The reason is that previously, for each token, the astString of its
operands was constructed, and then appended to this tokens astString.
This led to a lot of unnecessary string copying (and with that
allocations). Instead, by passing the string by reference, the number
of temporary strings is greatly reduced.

Another way of seeing it is that previously, the string was constructed
from end to beginning, but now it is constructed from the beginning to
end. There was no notable speedup by preallocating the entire string
using string::reserve() (at least not on Linux).

To benchmark, the changes and master were tested on Linux using the
commands:

	make
	time cppcheck --debug --verbose $file >/dev/null

i.e., the cppcheck binary was compiled with the settings in the
Makefile. Printing the output to screen or file will of course take
longer time.

In Trac ticket #8355 which triggered this change, an example file from the
Wine repository was attached. Running the above cppcheck on master took
24 minutes and with the changes in this commmit, took 22 seconds.

Another test made was on lib/tokenlist.cpp in the cppcheck repo, which is
more "normal" file. On that file there was no measurable time difference.

A synthetic benchmark was generated to illustrate the effects on dumping
the ast for arrays of different sizes. The generate code looked as
follows:

	const int array[] = {...};

with different number of elements. The results are as follows (times are
in seconds):

	N	master optimized
	10	0.1    0.1
	100	0.1    0.1
	1000	2.8    0.7
	2000	19     1.8
	3000	53     3.8
	5000	350    10
	10000	3215   38

As we can see, for small arrays, there is no time difference, but for
large arrays the time savings are substantial.
2019-04-30 13:35:48 +02:00
IOBYTE 505b7f7ebd Fixed #9110 (Syntax error on valid C++ code) (#1813) 2019-04-29 15:17:37 +02:00
Paul Fultz II ae8a3aae8d Fix FP with unused variable (#1814) 2019-04-29 11:50:19 +02:00
amai2012 361fc44005 Adjust more test results for invalid code 2019-04-19 20:53:07 +02:00
Paul Fultz II a90caa7e5a Fix issue 9006: False positive: Return value of function std::move() is not used.
This is trying to fix the issue by fixing the ast and symbol database. First, the ast nodes will be created for the init list and the symbol database will not mark it as a scope. I am not sure if this is the correct approach as I dont really understand how the AST part works.

It did change the AST for `try {} catch (...) {}` but that is because it incorrectly treats `try {}` as an initializer list.
2019-04-15 06:37:27 +02:00
Daniel Marjamäki 1393c1c3a0 AST: Try to handle C++17 syntax 'if (init;expr)' 2019-04-12 17:35:06 +02:00
Daniel Marjamäki 292b679aba Fixed build error. Renamed variable 2019-04-10 19:17:24 +02:00
Daniel Marjamäki 7610513c49 Fixed #9090 (Do not simplify standard functions) 2019-04-08 19:00:46 +02:00
Daniel Marjamäki 83106d5827 Unused templates: Remove unused template function with variadic arguments 2019-04-07 08:37:04 +02:00
Frank Zingsheim 574b77cf1f Fixed: FP return reference to thread_local variable (#1758) 2019-03-27 12:22:53 +01:00
Paul Fultz II 91138578cc Fix 9052: Crash: SIGSEGV in Token::previous (this=0x0) while checking mariadb-10.0 2019-03-22 01:56:09 +01:00
Rikard Falkeborn 6a3dd9a185 Handle concatenated string and char literals
This handles concatenated strings and characters from simplecpp.
Previously, L'c' would be preprocessed to the tokens  "L" and "'c'".
cppcheck would then remove the "L" token and set "'c'" to be a wide
character literal. Now, it needs to remove the prefix instead.

When doing this, add handling of utf32 encoded literals (U) and UTF-8
encoded literals (u8).
2019-03-10 10:38:50 +01:00
Daniel Marjamäki e17ddfd964 Changed AST for variable declarations with initializations 2019-03-09 19:09:15 +01:00
Daniel Marjamäki 75ce67f4b8 Fixed #9027 (cppcheck on Centos 7 - segmentation fault below CheckCondition::multiCondition2) 2019-03-08 19:27:20 +01:00
IOBYTE 5ee6c2138c Fixed #9016 (tokenizer: wrong simplification for operator ^ (){}) (#1724) 2019-03-05 11:35:45 +01:00
Daniel Marjamäki bd7790fd8c Update copyright year 2019-02-09 07:24:06 +01:00
IOBYTE 05a3e6807b Fixed #8950 and #8952 (improve type alias support) (#1633)
* Fixed #8950 and #8952 (improve type alias support)

* fix travis build
2019-01-31 16:53:51 +01:00
Daniel Marjamäki 8dd641b8be Use OVERRIDE in test 2019-01-12 15:45:25 +01:00
practicalswift 0a1b3a9d6f Fix typos (#1568) 2019-01-06 17:15:57 +01:00
Daniel Marjamäki 04d3672bde Fixed #7203 (Better syntax error, handle array declaration with @) 2019-01-01 09:45:41 +01:00
IOBYTE 0f83aff3b8 Improve trailing return type support. (#1520)
* Improve trailing return type support.

* Partial fix for #8889 (varid on function when using trailing return type)

* Handle operators in templates.
2018-12-13 06:34:10 +01:00
Daniel Marjamäki e0b64ec7a9 Fixed #8884 (AST: handle xs... template argument) 2018-12-12 19:00:14 +01:00
Daniel Marjamäki 01d0199ecf Fix testrunner 2018-12-04 19:56:22 +01:00
Daniel Marjamäki bd0a935d8a Tokenizer: Improved handling of compiler extensions that use @ (see https://sourceforge.net/p/cppcheck/discussion/general/thread/8f618cb0a3) 2018-12-04 19:33:39 +01:00
Daniel Marjamäki 49413b7d4c Tokenizer: Add simplifyAt to handle some nonstandard code with @ 2018-12-04 16:52:41 +01:00
Colomban Wendling cad4e4ab20 Fix handling of `sizeof &var` (#1498)
Fixes https://trac.cppcheck.net/ticket/8870
2018-11-30 13:53:58 +01:00
IOBYTE 358f0c473d Modify template simplifier to add forward declarations of some templa… (#1489)
* Modify template simplifier to add forward declarations of some template functions so symbol database can make sense of the expanded templates.

* Fix travis.
2018-11-23 11:36:09 +01:00
Daniel Marjamäki 9ef3c79bc6 Fixed #8851 (Crash in valueFlowContainerForward (daca@home: pbbam)) 2018-11-18 20:18:55 +01:00
Daniel Marjamäki 5d086d60ad Fixed #8844 (snd: Wrong varid and ast) 2018-11-14 21:05:09 +01:00
Daniel Marjamäki e6a5e0f752 Warn when there is a unknown macro 2018-11-13 16:49:15 +01:00
Daniel Marjamäki 8327aab127 Fixed #8628 (Wrong AST in case) 2018-11-10 21:32:06 +01:00
IOBYTE 17a8a4898d Fix another template simplifier namespace bug. (#1467)
* Fix another template simplifier namespace bug.

* Add missing forward declarations caused by token bug.
2018-11-07 21:25:42 +01:00
rikardfalkeborn 88008fedb1 findLambdaEndToken handle explicit type (#1458)
* findLambdaEndToken: Add tests

* Add handling of explicit return in findLambdaEndToken()

* Use AST in findLambdaEndToken()

* Fix ast when lambda is mutable
2018-10-31 12:36:08 +01:00
Daniel Marjamäki 8beb42cc90 astyle formatting
[ci skip]
2018-10-28 17:37:19 +01:00
Paul Fultz II 2b6cc33dc6 Fix issue 8757: Throw syntax error on invalid code (#1378)
* Fix issue 8757: Throw syntax error on invalid code

* Fix FP with lambda returns

* Remove double percent

* Check more keywords

* Skip preprocessor directives

* Check for valid PP directive

* Fix preprocessor check

* Dont check for preprocessor directives
2018-10-28 17:17:53 +01:00
Paul Fultz II f5811c6818 Fix issue 8732: Syntax error when using enable_if (#1453)
* Fix issue 8732: Syntax error when using enable_if

* Fix FPs

* Use simpleMatch
2018-10-28 17:16:31 +01:00
Daniel Marjamäki 15160f1691 Fixed #8788 (AST Broken error from assigning lambda to variable) 2018-10-22 17:25:01 +02:00
Daniel Marjamäki dc38681a56 Remove FIXME in AST validation. Ticket #8749 2018-10-22 11:37:24 +02:00
Daniel Marjamäki 29feaa5a51 Tokenizer: Avoid constant folding 2018-10-20 10:51:50 +02:00
Daniel Marjamäki 465db2dff7 Fixed #8786 (internalAstError on valid code with C style cast) 2018-10-18 20:17:23 +02:00
Daniel Marjamäki 7eb5ebe17e Fixed #7887 (User function 'search' is wrongly mixed with std function) 2018-10-10 17:35:53 +02:00
Daniel Marjamäki c048bd45f6 Refactor test code 2018-10-10 14:35:58 +02:00
Daniel Marjamäki 25cbfe27cf Partial fix for #7887, Improved tokenizer simplification of 'using namespace std;' - do not simplify user functions 2018-10-10 14:28:53 +02:00
Daniel Marjamäki 9dccc4037b Fixed #8747 (Syntax error, AST broken (a = --*b)) 2018-09-27 19:26:08 +02:00
Simon Martin 6bde2445a6 Ticket #8632: Parenthesize ternary operator operands containing < to avoid wrongly thinking a template instantiation is met. (#1389) 2018-09-23 10:27:38 +02:00
IOBYTE e9a44f70b2 Remove out of line member functions of instantiated template classes. (#1377)
* Remove out of line member functions of instantiated template classes.
2018-09-14 14:16:34 +02:00
Daniel Marjamäki 523a9c1c4a Fixed #8746 (Syntax error, AST broken (using a::operator=)) 2018-09-09 21:11:45 +02:00