Skip to content

Commit

Permalink
Partial fix for #12302 internalAstError using lambda (#5816)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Jan 2, 2024
1 parent 0c8ee78 commit d9d23d9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,12 @@ static bool iscpp11init_impl(const Token * const tok)
}

auto isCaseStmt = [](const Token* colonTok) {
if (!Token::Match(colonTok->tokAt(-1), "%name%|%num%|%char% :"))
if (!Token::Match(colonTok->tokAt(-1), "%name%|%num%|%char%|) :"))
return false;
if (const Token* castTok = colonTok->linkAt(-1)) {
if (Token::simpleMatch(castTok->astParent(), "case"))
return true;
}
const Token* caseTok = colonTok->tokAt(-2);
while (caseTok && Token::Match(caseTok->tokAt(-1), "::|%name%"))
caseTok = caseTok->tokAt(-1);
Expand Down
4 changes: 2 additions & 2 deletions test/testcppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ class TestCppcheck : public TestFixture {
ASSERT_EQUALS(1, cppcheck.check(test_file_a.path()));
ASSERT_EQUALS(1, cppcheck.check(test_file_b.path()));
// TODO: how to properly disable these warnings?
errorLogger.errmsgs.erase(std::remove_if(errorLogger.errmsgs.begin(), errorLogger.errmsgs.end(), [](const ErrorMessage& errmsg) {
return errmsg.id == "logChecker";
errorLogger.errmsgs.erase(std::remove_if(errorLogger.errmsgs.begin(), errorLogger.errmsgs.end(), [](const ErrorMessage& msg) {
return msg.id == "logChecker";
}), errorLogger.errmsgs.end());
// the internal errorlist is cleared after each check() call
ASSERT_EQUALS(2, errorLogger.errmsgs.size());
Expand Down
13 changes: 13 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6788,6 +6788,19 @@ class TestTokenizer : public TestFixture {
" });\n"
"}\n"));

ASSERT_NO_THROW(tokenizeAndStringify("struct A { A(int) {} };\n"
"void g(void (*)(int));\n"
"void f() {\n"
" g([](int i) {\n"
" switch (i) {\n"
" case static_cast<int>(1): {\n"
" A a(i);\n"
" if (1) {}\n"
" }\n"
" }\n"
" });\n"
"}\n"));

// #11378
ASSERT_EQUALS("gT{(&[{= 0return", testAst("auto g = T{ [&]() noexcept -> int { return 0; } };"));

Expand Down
18 changes: 17 additions & 1 deletion test/testuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3735,7 +3735,7 @@ class TestUninitVar : public TestFixture {
"}\n");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:8]: (warning) Uninitialized variable: x\n", errout.str());

valueFlowUninit("int do_something();\n"
valueFlowUninit("int do_something();\n" // #11983
"int set_st(int *x);\n"
"int bar();\n"
"void foo() {\n"
Expand All @@ -3755,6 +3755,22 @@ class TestUninitVar : public TestFixture {
" if(status == 1 && x > 0){}\n"
"}\n");
ASSERT_EQUALS("", errout.str());

valueFlowUninit("int h(bool, bool*);\n" // #11760
"int f(bool t) {\n"
" int i = 0;\n"
" bool b;\n"
" if (t)\n"
" g();\n"
" if (i == 0)\n"
" i = h(t, &b);\n"
" if (i == 0 && b)\n"
" i = h(t, &b);\n"
" if (i == 0 && b)\n"
" i = h(t, &b);\n"
" return i;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}

void valueFlowUninit_uninitvar2()
Expand Down

0 comments on commit d9d23d9

Please sign in to comment.