Skip to content

Commit 53955b4

Browse files
committed
missingReturn; Fixed false negative for goto-label
1 parent 8f1cb23 commit 53955b4

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

lib/checkfunctions.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ static const Token *checkMissingReturnScope(const Token *tok)
314314
}
315315
if (tok->isKeyword() && Token::Match(tok, "return|throw"))
316316
return nullptr;
317+
if (Token::Match(tok, "[;{}] %name% :"))
318+
return tok;
317319
if (Token::Match(tok, "; !!}") && !lastStatement)
318320
lastStatement = tok->next();
319321
}

test/testfunctions.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,13 @@ class TestFunctions : public TestFixture {
13861386
"}");
13871387
ASSERT_EQUALS("", errout.str());
13881388

1389+
check("int foo(int x) {\n"
1390+
" if (x) goto out;\n"
1391+
" return 1;\n"
1392+
"out:\n"
1393+
"}");
1394+
ASSERT_EQUALS("[test.cpp:3]: (error) Found a exit path from function with non-void return type that has missing return statement\n", errout.str());
1395+
13891396
// switch
13901397
check("int f() {\n"
13911398
" switch (x) {\n"

0 commit comments

Comments
 (0)