From aa2f143ea64a41e877567c357b5a5010a00ef414 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Fri, 19 Feb 2021 08:21:26 +0100 Subject: [PATCH] Fixed false positive: Parameter can be declared with const in constructors did handle noexcept Merged from LCppC. --- lib/symboldatabase.cpp | 8 +++++--- test/testother.cpp | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 1fbc22135..f1e3f33e4 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -2678,10 +2678,12 @@ std::vector Function::findReturns(const Function* f) const Token * Function::constructorMemberInitialization() const { - if (!isConstructor() || !functionScope || !functionScope->bodyStart) + if (!isConstructor() || !arg) return nullptr; - if (Token::Match(token, "%name% (") && Token::simpleMatch(token->linkAt(1), ") :")) - return token->linkAt(1)->next(); + if (Token::simpleMatch(arg->link(), ") :")) + return arg->link()->next(); + if (Token::simpleMatch(arg->link(), ") noexcept (") && arg->link()->linkAt(2)->strAt(1) == ":") + return arg->link()->linkAt(2)->next(); return nullptr; } diff --git a/test/testother.cpp b/test/testother.cpp index df04b78b6..84f420cb8 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2499,6 +2499,26 @@ private: "}\n"); 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" "{\n" "public:\n"