Fix #11726 "this->" confuses non void return check (#5073)

This commit is contained in:
chrchr-github 2023-05-22 20:23:09 +02:00 committed by GitHub
parent 78182d4773
commit 00733893e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -395,11 +395,7 @@ static const Token *checkMissingReturnScope(const Token *tok, const Library &lib
if (tok->str() == "goto" && !isForwardJump(tok)) if (tok->str() == "goto" && !isForwardJump(tok))
return nullptr; return nullptr;
if (Token::Match(tok, "%name% (") && !library.isnotnoreturn(tok)) { if (Token::Match(tok, "%name% (") && !library.isnotnoreturn(tok)) {
const Token *start = tok; return nullptr;
while (Token::Match(start->tokAt(-2), "%name% :: %name%"))
start = start->tokAt(-2);
if (Token::Match(start->previous(), "[;{}] %name% ::|("))
return nullptr;
} }
if (Token::Match(tok, "[;{}] %name% :")) if (Token::Match(tok, "[;{}] %name% :"))
return tok; return tok;

View File

@ -1741,6 +1741,16 @@ private:
check("template<class T> typename std::enable_if<std::is_same<T, int>{}>::type f(T) {}"); check("template<class T> typename std::enable_if<std::is_same<T, int>{}>::type f(T) {}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("struct S {\n"
" [[noreturn]] void f();\n"
" int g() { this->f(); }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
check("struct S { [[noreturn]] void f(); };\n"
"int g(S& s) { s.f(); }\n");
ASSERT_EQUALS("", errout.str());
} }
// NRVO check // NRVO check