Skip to content

Commit 0b5aa87

Browse files
Fix #13471 FP: unreachableCode (return statement in lambda expression) (danmar#7165)
1 parent 3216458 commit 0b5aa87

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/tokenlist.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,8 @@ static Token * createAstAtToken(Token *tok)
17501750
(cpp && Token::Match(tok, "%name% {") && iscpp11init(tok->next())) ||
17511751
Token::Match(tok->previous(), "[;{}] %cop%|++|--|( !!{") ||
17521752
Token::Match(tok->previous(), "[;{}] %num%|%str%|%char%") ||
1753-
Token::Match(tok->previous(), "[;{}] delete new")) {
1753+
Token::Match(tok->previous(), "[;{}] delete new") ||
1754+
(cpp && Token::Match(tok->previous(), "[;{}] ["))) {
17541755
if (cpp && (Token::Match(tok->tokAt(-2), "[;{}] new|delete %name%") || Token::Match(tok->tokAt(-3), "[;{}] :: new|delete %name%")))
17551756
tok = tok->previous();
17561757

test/testtokenize.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6475,7 +6475,7 @@ class TestTokenizer : public TestFixture {
64756475
// (cast){data}[index]
64766476
ASSERT_EQUALS("a&{(0[1[5[0=", testAst("(int (**)[i]){&a}[0][1][5] = 0;"));
64776477
ASSERT_EQUALS("ab12,{(0[,(", testAst("a(b, (int []){1,2}[0]);"));
6478-
ASSERT_EQUALS("n0=", testAst("TrivialDefCtor{[2][2]}[1][1].n = 0;"));
6478+
ASSERT_EQUALS("TrivialDefCtora2[2[{1[1[n.0=", testAst("TrivialDefCtor{a[2][2]}[1][1].n = 0;"));
64796479
ASSERT_EQUALS("aT12,3,{1[=", testAst("a = T{1, 2, 3}[1];"));
64806480

64816481
// Type{data}()
@@ -6877,7 +6877,7 @@ class TestTokenizer : public TestFixture {
68776877

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

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

69666966
ASSERT_EQUALS("sf.{(i[{={", testAst("void g(int i) { S s{ .f = { [i]() {} } }; }"));
6967+
6968+
ASSERT_EQUALS("{([", testAst("void f() { []() {}; }")); // #13471
69676969
}
69686970

69696971
void astcase() {

0 commit comments

Comments
 (0)