cppcheck/lib
gerboengels 6a01fa9b70
#11134 Fix broken AST with (designated) initializers (#4550)
* Make control flow a bit easier, and more similar to previous code

Made similar to around line 790

* In a cpp11init, always parse only the corresponding } (#11134)

- _always_, because in some cases this was omitted (around line 790) or too strict (around line 860)
- _only_, and not following tokens which happen to be } as well (around line 1030)

* Fix unit tests: AST was incorrect, now is fixed

auto var{ {{},{}}, {} };

Old AST:
```
{
|-var
`-{
  `-,
    |-,
    | |-{
    | `-{
    `-{
```
New AST:
```
{
|-var
`-,
  |-{
  | `-,
  | | |-{
  | | `-{
  `-{
```
Compare the same example, but with `X{}` instead of just `{}`:
`auto var{ a{b{},c{}}, d{} };`
```
{
|-var
`-,
  |-{
  | |-a
  | `-,
  | | |-{
  | | | `-b
  | | `-{
  | | | `-c
  `-{
    `-d
```
This structure is similar to that of the new AST, not the old AST

* Fix unit tests: another AST was incorrect, now is fixed

Code: `auto var{{1,a::b{2,3}}, {4,a::b{5,6}}};`

Old AST:
```
{
|-var
`-{
  `-,
    |-,
    | |-1 'signed int'
    | `-{
    | | |-::
    | | | |-a
    | | | `-b
    | | `-,
    | | | |-2 'signed int'
    | | | `-3 'signed int'
    `-{
      `-,
        |-4 'signed int'
        `-{
          |-::
          | |-a
          | `-b
          `-,
            |-5 'signed int'
            `-6 'signed int'
```
New AST:
```
{
|-var
`-,
  |-{
  | `-,
  | | |-1 'signed int'
  | | `-{
  | | | |-::
  | | | | |-a
  | | | | `-b
  | | | `-,
  | | | | |-2 'signed int'
  | | | | `-3 'signed int'
  `-{
    `-,
      |-4 'signed int'
      `-{
        |-::
        | |-a
        | `-b
        `-,
          |-5 'signed int'
          `-6 'signed int'
```

* Fix unit tests: missing ; after class, resulting in incorrectly being marked as cpp11init

Because of the missing `;` after the class declaration, it was marked as a cpp11init block.
Which it isn't, and which now throws an exception

* Fix cpp11init to let unit tests pass again

The following unit tests failed on the newly introduced throws, because the code for these tests incorrectly marked some tokens as cpp11init:
TestVarID::varid_cpp11initialization
TestTokenizer::checkRefQualifiers

* Fix typo

* Improve check for void trailing return type

Observation: the only function body _not_ containing a semicolon, is a void function: something like
   auto make_zero(ini& i) -> void {
     while(--i > 0) {}
   }
Non-void function? Then it must return a value, and thus contain a semicolon, which is checked for a few lines later.

* Fix cpp11init with templated trailing return type

In the following example, vector was marked as cpp11init due to the mismatch of `%any% {`
auto f() -> std::vector<int> { return {}; }

I made the assumption that whenever "%any% {" matches, endtok must be set too.
If this assumtion doesn't hold (so "%any% {" matches, but endtok == nullptr), then the for-loop would search all the way to the end of stream. Which I guess was not the intention.

* Remove comments

Co-authored-by: Gerbo Engels <gerbo.engels@ortec-finance.com>
2022-10-19 07:25:15 +02:00
..
CMakeLists.txt some small cleanups and refactorings (#4488) 2022-09-24 11:59:13 +02:00
analyzer.h include all (internal non-generated) headers in clang-tidy checks (#4100) 2022-10-16 13:51:17 +02:00
analyzerinfo.cpp Fix sense of test (.analyzerinfo files get placed in wrong directory) (#4486) 2022-09-21 17:38:23 +02:00
analyzerinfo.h Update Copyrights 2022-08-28 14:22:12 +02:00
astutils.cpp various optimizations (#4535) 2022-10-06 20:12:07 +02:00
astutils.h applied clang-tidy `misc-const-correctness` fixes for POD types, iterators and references (#4529) 2022-10-02 07:12:40 +02:00
calculate.h
check.cpp Fix #10412 FN useStlAlgorithm with iterators (#4157) 2022-10-16 13:46:26 +02:00
check.h mitigated some clang-tidy warnings in headers (#4472) 2022-09-16 18:59:15 +02:00
check64bit.cpp
check64bit.h
checkassert.cpp Fixed #9926 (False positive assertWithSideEffects, calling method that has no side effects) 2022-10-12 07:51:50 +02:00
checkassert.h
checkautovariables.cpp Fix #10412 FN useStlAlgorithm with iterators (#4157) 2022-10-16 13:46:26 +02:00
checkautovariables.h Fix #10993 danglingTemporaryLifetime reported in two different locati… (#4462) 2022-09-14 07:28:04 +02:00
checkbool.cpp applied clang-tidy `misc-const-correctness` fixes for POD types, iterators and references (#4529) 2022-10-02 07:12:40 +02:00
checkbool.h Fix #4233 FN: Bitwise operation with bool and int (#4266) 2022-07-11 22:58:37 +02:00
checkboost.cpp
checkboost.h
checkbufferoverrun.cpp applied clang-tidy `misc-const-correctness` fixes for POD types, iterators and references (#4529) 2022-10-02 07:12:40 +02:00
checkbufferoverrun.h Fix #11145 FP negativeMemoryAllocationSize with possible value (#4387) 2022-08-20 07:56:31 +02:00
checkclass.cpp Fix #10412 FN useStlAlgorithm with iterators (#4157) 2022-10-16 13:46:26 +02:00
checkclass.h Fix #1655 wrong usage of std::string in memcpy (#4460) 2022-09-13 15:14:25 +02:00
checkcondition.cpp Fix #10412 FN useStlAlgorithm with iterators (#4157) 2022-10-16 13:46:26 +02:00
checkcondition.h Use return instead of condition for alwaysTrueFalse check (#4446) 2022-10-09 21:03:48 +02:00
checkexceptionsafety.cpp Typos fix (#4509) 2022-09-27 06:48:06 +02:00
checkexceptionsafety.h
checkfunctions.cpp Fix #9653 FP leakReturnValNotUsed although (void) is specified (#4431) 2022-09-27 20:09:04 +02:00
checkfunctions.h New check: use memcpy/memset instead of loop (#4257) 2022-09-03 23:29:06 +02:00
checkinternal.cpp applied clang-tidy `misc-const-correctness` fixes for POD types, iterators and references (#4529) 2022-10-02 07:12:40 +02:00
checkinternal.h cleaned up includes based on include-what-you-use (#4502) 2022-09-25 09:20:34 +02:00
checkio.cpp applied clang-tidy `misc-const-correctness` fixes for POD types, iterators and references (#4529) 2022-10-02 07:12:40 +02:00
checkio.h fixed `modernize-use-equals-delete` warnings in headers (#4177) 2022-06-07 21:25:23 +02:00
checkleakautovar.cpp Fix #10412 FN useStlAlgorithm with iterators (#4157) 2022-10-16 13:46:26 +02:00
checkleakautovar.h Fix #11126 FN: noExplicitConstructor with single default parameter (#4174) 2022-06-07 21:15:13 +02:00
checkmemoryleak.cpp Fix defaulted and deleted functions (#4540) 2022-10-10 20:17:33 +02:00
checkmemoryleak.h Fix #9653 FP leakReturnValNotUsed although (void) is specified (#4431) 2022-09-27 20:09:04 +02:00
checknullpointer.cpp some small cleanups and refactorings (#4488) 2022-09-24 11:59:13 +02:00
checknullpointer.h use `emptyString` more consistently (#4034) 2022-07-10 10:57:29 +02:00
checkother.cpp Fix #10412 FN useStlAlgorithm with iterators (#4157) 2022-10-16 13:46:26 +02:00
checkother.h Fix 9755: false negative: access of moved variable in conditional code (#4459) 2022-09-11 12:32:01 +02:00
checkpostfixoperator.cpp
checkpostfixoperator.h
checksizeof.cpp Fix #10412 FN useStlAlgorithm with iterators (#4157) 2022-10-16 13:46:26 +02:00
checksizeof.h
checkstl.cpp Fix #10412 FN useStlAlgorithm with iterators (#4157) 2022-10-16 13:46:26 +02:00
checkstl.h Fix #7515 New check: Not needed c_str() operation (#4371) 2022-08-20 20:52:10 +02:00
checkstring.cpp Fix #11166 inefficient way to remove last character from std::string (#4267) 2022-07-11 23:07:37 +02:00
checkstring.h
checktype.cpp iwyu.yml: use `debian:unstable` to always get latest include-what-you-use / cleaned up includes (#4466) 2022-09-16 07:15:49 +02:00
checktype.h
checkuninitvar.cpp applied clang-tidy `misc-const-correctness` fixes for POD types, iterators and references (#4529) 2022-10-02 07:12:40 +02:00
checkuninitvar.h
checkunusedfunctions.cpp various optimizations (#4535) 2022-10-06 20:12:07 +02:00
checkunusedfunctions.h various optimizations (#4535) 2022-10-06 20:12:07 +02:00
checkunusedvar.cpp Fix #10412 FN useStlAlgorithm with iterators (#4157) 2022-10-16 13:46:26 +02:00
checkunusedvar.h
checkvaarg.cpp iwyu.yml: use `debian:unstable` to always get latest include-what-you-use / cleaned up includes (#4466) 2022-09-16 07:15:49 +02:00
checkvaarg.h
clangimport.cpp Fix #10412 FN useStlAlgorithm with iterators (#4157) 2022-10-16 13:46:26 +02:00
clangimport.h LCppC backports: Refactorizations/Optimizations (#4204) 2022-08-21 17:21:02 +02:00
color.cpp
color.h
config.h some `--exception-handling` related improvements (#4368) 2022-08-20 20:54:31 +02:00
cppcheck.cpp added environment variable `UNUSEDFUNCTION_ONLY` to make sure only the `unusedFunction` check is being executed (#4362) 2022-10-06 20:54:24 +02:00
cppcheck.h cleaned up includes based on include-what-you-use (#4502) 2022-09-25 09:20:34 +02:00
cppcheck.natvis
cppcheck.vcxproj LCppC backports: Refactorizations/Optimizations (#4204) 2022-08-21 17:21:02 +02:00
cppcheck.vcxproj.filters LCppC backports: Refactorizations/Optimizations (#4204) 2022-08-21 17:21:02 +02:00
ctu.cpp applied clang-tidy `misc-const-correctness` fixes for POD types, iterators and references (#4529) 2022-10-02 07:12:40 +02:00
ctu.h mitigated some clang-tidy warnings in headers (#4472) 2022-09-16 18:59:15 +02:00
errorlogger.cpp applied clang-tidy `misc-const-correctness` fixes for POD types, iterators and references (#4529) 2022-10-02 07:12:40 +02:00
errorlogger.h avoid some unnecessary object creations and copies (#4493) 2022-09-29 21:47:17 +02:00
errortypes.cpp enabled and fixed `modernize-pass-by-value` clang-tidy warnings (#4169) 2022-07-28 22:51:45 +02:00
errortypes.h enabled and fixed `modernize-pass-by-value` clang-tidy warnings (#4169) 2022-07-28 22:51:45 +02:00
forwardanalyzer.cpp applied clang-tidy `misc-const-correctness` fixes for POD types, iterators and references (#4529) 2022-10-02 07:12:40 +02:00
forwardanalyzer.h
importproject.cpp Fix #10412 FN useStlAlgorithm with iterators (#4157) 2022-10-16 13:46:26 +02:00
importproject.h fixed and enabled some Clang compiler warnings (#4517) 2022-09-29 21:59:02 +02:00
infer.cpp avoid unnecessary copies with `push_back()` and `push_front()` (#4451) 2022-09-08 09:21:35 +02:00
infer.h
lib.pri
library.cpp Fix #10412 FN useStlAlgorithm with iterators (#4157) 2022-10-16 13:46:26 +02:00
library.h various optimizations (#4535) 2022-10-06 20:12:07 +02:00
matchcompiler.h
mathlib.cpp Fix #10412 FN useStlAlgorithm with iterators (#4157) 2022-10-16 13:46:26 +02:00
mathlib.h mathlib.h: replaced slow `std::ostringstream` with `std::to_string()` in `MathLib::toString()` (#4382) 2022-08-19 20:44:24 +02:00
path.cpp various optimizations (#4535) 2022-10-06 20:12:07 +02:00
path.h various optimizations (#4535) 2022-10-06 20:12:07 +02:00
pathanalysis.cpp applied clang-tidy `misc-const-correctness` fixes for POD types, iterators and references (#4529) 2022-10-02 07:12:40 +02:00
pathanalysis.h
pathmatch.cpp cleaned up includes based on include-what-you-use (#4358) 2022-08-14 12:44:19 +02:00
pathmatch.h enabled and fixed `modernize-pass-by-value` clang-tidy warnings (#4169) 2022-07-28 22:51:45 +02:00
pcrerules.pri
platform.cpp cleaned up includes based on include-what-you-use (#4358) 2022-08-14 12:44:19 +02:00
platform.h applied clang-tidy `misc-const-correctness` fixes for POD types, iterators and references (#4529) 2022-10-02 07:12:40 +02:00
precompiled.h
preprocessor.cpp Fix #10412 FN useStlAlgorithm with iterators (#4157) 2022-10-16 13:46:26 +02:00
preprocessor.h cleaned up includes based on include-what-you-use (#4358) 2022-08-14 12:44:19 +02:00
programmemory.cpp applied clang-tidy `misc-const-correctness` fixes for POD types, iterators and references (#4529) 2022-10-02 07:12:40 +02:00
programmemory.h include all (internal non-generated) headers in clang-tidy checks (#4100) 2022-10-16 13:51:17 +02:00
reverseanalyzer.cpp applied clang-tidy `misc-const-correctness` fixes for POD types, iterators and references (#4529) 2022-10-02 07:12:40 +02:00
reverseanalyzer.h
settings.cpp Add experimental option --performance-valueflow-max-time=T 2022-10-04 14:02:55 +02:00
settings.h Add experimental option --performance-valueflow-max-time=T 2022-10-04 14:02:55 +02:00
smallvector.h include all (internal non-generated) headers in clang-tidy checks (#4100) 2022-10-16 13:51:17 +02:00
sourcelocation.h lib/sourcelocation.h: add missing <cstdint> include (#4474) 2022-09-16 21:36:37 +02:00
standards.h
summaries.cpp applied clang-tidy `misc-const-correctness` fixes for POD types, iterators and references (#4529) 2022-10-02 07:12:40 +02:00
summaries.h
suppressions.cpp iwyu.yml: use `debian:unstable` to always get latest include-what-you-use / cleaned up includes (#4466) 2022-09-16 07:15:49 +02:00
suppressions.h mitigated some clang-tidy warnings in headers (#4472) 2022-09-16 18:59:15 +02:00
symboldatabase.cpp Fix #10412 FN useStlAlgorithm with iterators (#4157) 2022-10-16 13:46:26 +02:00
symboldatabase.h Fix #10412 FN useStlAlgorithm with iterators (#4157) 2022-10-16 13:46:26 +02:00
templatesimplifier.cpp Fix #11351 Assert failure in templatesimplifier.cpp (#4552) 2022-10-16 19:34:25 +02:00
templatesimplifier.h Update Copyrights 2022-08-28 14:22:12 +02:00
timer.cpp Update Copyrights 2022-08-28 14:22:12 +02:00
timer.h fixed #11249 (potential hang with -j and --showtime= when using threads) - synchronized access to `TimerResults::mResults` / added TSAN to CI (#4355) 2022-08-23 20:30:45 +02:00
token.cpp #11134 Fix broken AST with (designated) initializers (#4550) 2022-10-19 07:25:15 +02:00
token.h include all (internal non-generated) headers in clang-tidy checks (#4100) 2022-10-16 13:51:17 +02:00
tokenize.cpp Fix #11355 FN: arrayIndexOutOfBounds (#4555) 2022-10-18 07:24:24 +02:00
tokenize.h cleaned up includes based on include-what-you-use (#4358) 2022-08-14 12:44:19 +02:00
tokenlist.cpp #11134 Fix broken AST with (designated) initializers (#4550) 2022-10-19 07:25:15 +02:00
tokenlist.h mitigated some clang-tidy warnings in headers (#4472) 2022-09-16 18:59:15 +02:00
tokenrange.h cleaned up includes based on include-what-you-use (#4502) 2022-09-25 09:20:34 +02:00
utils.cpp applied clang-tidy `misc-const-correctness` fixes for POD types, iterators and references (#4529) 2022-10-02 07:12:40 +02:00
utils.h Fix #10412 FN useStlAlgorithm with iterators (#4157) 2022-10-16 13:46:26 +02:00
valueflow.cpp Fix #10412 FN useStlAlgorithm with iterators (#4157) 2022-10-16 13:46:26 +02:00
valueflow.h cleaned up includes based on include-what-you-use (#4502) 2022-09-25 09:20:34 +02:00
valueptr.h include all (internal non-generated) headers in clang-tidy checks (#4100) 2022-10-16 13:51:17 +02:00
version.h added missing version bumps to 2.10 (#4420) 2022-09-09 21:02:04 +02:00
version.rc