Skip to content

Commit

Permalink
Fix #13471 FP: unreachableCode (return statement in lambda expression) (
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Jan 3, 2025
1 parent 3216458 commit 0b5aa87
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1750,7 +1750,8 @@ static Token * createAstAtToken(Token *tok)
(cpp && Token::Match(tok, "%name% {") && iscpp11init(tok->next())) ||
Token::Match(tok->previous(), "[;{}] %cop%|++|--|( !!{") ||
Token::Match(tok->previous(), "[;{}] %num%|%str%|%char%") ||
Token::Match(tok->previous(), "[;{}] delete new")) {
Token::Match(tok->previous(), "[;{}] delete new") ||
(cpp && Token::Match(tok->previous(), "[;{}] ["))) {
if (cpp && (Token::Match(tok->tokAt(-2), "[;{}] new|delete %name%") || Token::Match(tok->tokAt(-3), "[;{}] :: new|delete %name%")))
tok = tok->previous();

Expand Down
6 changes: 4 additions & 2 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6475,7 +6475,7 @@ class TestTokenizer : public TestFixture {
// (cast){data}[index]
ASSERT_EQUALS("a&{(0[1[5[0=", testAst("(int (**)[i]){&a}[0][1][5] = 0;"));
ASSERT_EQUALS("ab12,{(0[,(", testAst("a(b, (int []){1,2}[0]);"));
ASSERT_EQUALS("n0=", testAst("TrivialDefCtor{[2][2]}[1][1].n = 0;"));
ASSERT_EQUALS("TrivialDefCtora2[2[{1[1[n.0=", testAst("TrivialDefCtor{a[2][2]}[1][1].n = 0;"));
ASSERT_EQUALS("aT12,3,{1[=", testAst("a = T{1, 2, 3}[1];"));

// Type{data}()
Expand Down Expand Up @@ -6877,7 +6877,7 @@ class TestTokenizer : public TestFixture {

// #9662
ASSERT_EQUALS("b{[{ stdunique_ptr::0nullptrnullptr:?{", testAst("auto b{[] { std::unique_ptr<void *>{0 ? nullptr : nullptr}; }};"));
ASSERT_EQUALS("b{[=", testAst("void a() { [b = [] { ; }] {}; }"));
ASSERT_EQUALS("{b{[=[", testAst("void a() { [b = [] { ; }] {}; }"));

// Lambda capture expression (C++14)
ASSERT_EQUALS("a{b1=[= c2=", testAst("a = [b=1]{c=2;};"));
Expand Down Expand Up @@ -6964,6 +6964,8 @@ class TestTokenizer : public TestFixture {
ASSERT_EQUALS("gT{(&[{= 0return", testAst("auto g = T{ [&]() noexcept -> int { return 0; } };"));

ASSERT_EQUALS("sf.{(i[{={", testAst("void g(int i) { S s{ .f = { [i]() {} } }; }"));

ASSERT_EQUALS("{([", testAst("void f() { []() {}; }")); // #13471
}

void astcase() {
Expand Down

0 comments on commit 0b5aa87

Please sign in to comment.