diff --git a/lib/checkother.cpp b/lib/checkother.cpp index fb384ab5d..f2ea621ec 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1244,7 +1244,13 @@ static bool canBeConst(const Variable *var, const Settings* settings) const Function* func_scope = var->scope()->function; if (func_scope && func_scope->type == Function::Type::eConstructor) { //could be initialized in initializer list - if (func_scope->arg->link()->next()->str() == ":") { + const Token* init = func_scope->arg->link()->next(); + if (init->str() == "noexcept") { + init = init->next(); + if (init->link()) + init = init->link()->next(); + } + if (init->str() == ":") { for (const Token* tok2 = func_scope->arg->link()->next()->next(); tok2 != var->scope()->bodyStart; tok2 = tok2->next()) { if (tok2->varId() != var->declarationId()) continue; diff --git a/test/testother.cpp b/test/testother.cpp index 0df3b2324..4c807e298 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2150,6 +2150,18 @@ private: "[test.cpp:18]: (performance) Function parameter 'v' should be passed by const reference.\n", errout.str()); + check("struct S {\n" // #11995 + " explicit S(std::string s) noexcept;\n" + " std::string m;\n" + "};\n" + "S::S(std::string s) noexcept : m(std::move(s)) {}\n" + "struct T {\n" + " explicit S(std::string s) noexcept(true);\n" + " std::string m;\n" + "};\n" + "T::T(std::string s) noexcept(true) : m(std::move(s)) {}\n"); + ASSERT_EQUALS("", errout.str()); + Settings settings1 = settingsBuilder().platform(cppcheck::Platform::Type::Win64).build(); check("using ui64 = unsigned __int64;\n" "ui64 Test(ui64 one, ui64 two) { return one + two; }\n",