From c07e7ee9cff02dc1a40eed46ca99f3d29f03b26f Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 3 Apr 2024 15:18:01 +0200 Subject: [PATCH 1/4] Update tokenlist.cpp --- lib/tokenlist.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index d5122ab6a9d..aa5a49fabfb 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1762,7 +1762,7 @@ static Token * createAstAtToken(Token *tok) if (cpp && ((!tok->previous() && tok->str() == "::") || Token::Match(tok->previous(), "[;{}] ::"))) { AST_state state(cpp); - compileExpression(tok, state); + compileUnaryOp(tok, state, nullptr); } return tok; From de03c8b6d2ea251b52d35a7dd86309e013a36725 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 3 Apr 2024 15:19:21 +0200 Subject: [PATCH 2/4] Update testtokenize.cpp --- test/testtokenize.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index a8c5e62a02e..faa75ca6af6 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6218,6 +6218,13 @@ class TestTokenizer : public TestFixture { " (kInput & (uint64_t(1) << 63)) ? 63 : 64;\n" "};\n"; ASSERT_NO_THROW(tokenizeAndStringify(code)); + + code = "void f(const std::vector& v) {\n" // #12569 + " ::std::for_each(v.begin(), v.end(), [](int i) {\n" + " int j(i ? i : 5);\n" + " });\n" + "}\n"; + ASSERT_NO_THROW(tokenizeAndStringify(code)); } void astnewdelete() const { From 0f8d2d52389ecc71d4ed15cc46e2df17c7445240 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 3 Apr 2024 19:04:40 +0200 Subject: [PATCH 3/4] Update tokenlist.cpp --- lib/tokenlist.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index aa5a49fabfb..b7cf9858363 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1738,6 +1738,8 @@ static Token * createAstAtToken(Token *tok) AST_state state(cpp); if (Token::Match(tok, "%name% (")) state.functionCallEndPar = tok->linkAt(1); + if (Token::simpleMatch(tok->tokAt(-1), "::") && (!tok->tokAt(-2) || !tok->tokAt(-2)->isName())) + tok = tok->tokAt(-1); compileExpression(tok, state); Token * const endToken = tok; if (endToken == tok1 || !endToken) @@ -1760,11 +1762,6 @@ static Token * createAstAtToken(Token *tok) return endToken->previous(); } - if (cpp && ((!tok->previous() && tok->str() == "::") || Token::Match(tok->previous(), "[;{}] ::"))) { - AST_state state(cpp); - compileUnaryOp(tok, state, nullptr); - } - return tok; } From 691eca929efb5051bdd5e69a7b82ca5334fa87cb Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Wed, 3 Apr 2024 22:07:29 +0200 Subject: [PATCH 4/4] Add test --- test/testleakautovar.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index f8f89534341..135dd70517d 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -2480,6 +2480,14 @@ class TestLeakAutoVar : public TestFixture { " std::shared_ptr a{c, [](C* x) { delete x; }};\n" "}", true); ASSERT_EQUALS("", errout_str()); + + check("struct DirDeleter {\n" // #12544 + " void operator()(DIR* d) { ::closedir(d); }\n" + "};\n" + "void openDir(DIR* dir) {\n" + " std::shared_ptr dp(dir, DirDeleter());\n" + "}\n", true); + ASSERT_EQUALS("[test.cpp:2]: (information) --check-library: Function closedir() should have configuration\n", errout_str()); // don't crash } void smartPointerRelease() { check("void f() {\n"