diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index bf2ff16613c..9442d44cebf 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1226,6 +1226,10 @@ void CheckClass::initializationListUsage() allowed = false; return ChildrenToVisit::done; } + if (var2->isLocal() && isVariableChanged(var2->nameToken(), previousBeforeAstLeftmostLeaf(tok), var2->declarationId(), /*globalvar*/ false, *mSettings)) { + allowed = false; + return ChildrenToVisit::done; + } } else if (tok2->str() == "this") { // 'this' instance is not completely constructed in initialization list allowed = false; return ChildrenToVisit::done; diff --git a/test/testclass.cpp b/test/testclass.cpp index 6ae06b3907e..7494fe9edc2 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -8119,6 +8119,21 @@ class TestClass : public TestFixture { " std::string st;\n" "};"); ASSERT_EQUALS("", errout_str()); + + checkInitializationListUsage("struct S {\n" // #14189 + " S() {}\n" + " int i{};\n" + "};\n" + "struct T { explicit T(const S&); };\n" + "class C {\n" + " C() {\n" + " S s;\n" + " s.i = 1;\n" + " p = std::make_unique(s);\n" + " }\n" + " std::unique_ptr p;\n" + "};"); + ASSERT_EQUALS("", errout_str()); }