Fixed false positive: Parameter can be declared with const in constructors did handle noexcept

Merged from LCppC.
This commit is contained in:
PKEuS 2021-02-19 08:21:26 +01:00 committed by Daniel Marjamäki
parent a8657ac599
commit aa2f143ea6
2 changed files with 25 additions and 3 deletions

View File

@ -2678,10 +2678,12 @@ std::vector<const Token*> Function::findReturns(const Function* f)
const Token * Function::constructorMemberInitialization() const const Token * Function::constructorMemberInitialization() const
{ {
if (!isConstructor() || !functionScope || !functionScope->bodyStart) if (!isConstructor() || !arg)
return nullptr; return nullptr;
if (Token::Match(token, "%name% (") && Token::simpleMatch(token->linkAt(1), ") :")) if (Token::simpleMatch(arg->link(), ") :"))
return token->linkAt(1)->next(); return arg->link()->next();
if (Token::simpleMatch(arg->link(), ") noexcept (") && arg->link()->linkAt(2)->strAt(1) == ":")
return arg->link()->linkAt(2)->next();
return nullptr; return nullptr;
} }

View File

@ -2499,6 +2499,26 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("class C\n"
"{\n"
"public:\n"
" explicit C(int&);\n"
"};\n"
"\n"
"class D\n"
"{\n"
"public:\n"
" explicit D(int&) noexcept;\n"
"\n"
"private:\n"
" C c;\n"
"};\n"
"\n"
"D::D(int& i) noexcept\n"
" : c(i)\n"
"{}");
ASSERT_EQUALS("", errout.str());
check("class C\n" check("class C\n"
"{\n" "{\n"
"public:\n" "public:\n"