Skip to content

Commit

Permalink
Fix #12569 internalAstError with scope operator (#6226)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Apr 4, 2024
1 parent 57f9e04 commit 35a7eb9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
7 changes: 2 additions & 5 deletions lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
compileExpression(tok, state);
}

return tok;
}

Expand Down
8 changes: 8 additions & 0 deletions test/testleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2480,6 +2480,14 @@ class TestLeakAutoVar : public TestFixture {
" std::shared_ptr<C> 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<DIR> dp(dir, DirDeleter());\n"
"}\n", true);
ASSERT_EQUALS("[test.cpp:2]: (information) --check-library: Function closedir() should have <noreturn> configuration\n", errout_str()); // don't crash
}
void smartPointerRelease() {
check("void f() {\n"
Expand Down
7 changes: 7 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>& 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 {
Expand Down

0 comments on commit 35a7eb9

Please sign in to comment.