diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index c2180ad9e..31223e7c0 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -4519,10 +4519,15 @@ static void valueFlowLifetimeClassConstructor(Token* tok, std::vector args = getArguments(tok); if (scope->numConstructors == 0) { auto it = scope->varlist.cbegin(); - LifetimeStore::forEach(args, - "Passed to constructor of '" + t->name() + "'.", - ValueFlow::Value::LifetimeKind::SubObject, - [&](const LifetimeStore& ls) { + LifetimeStore::forEach( + args, + "Passed to constructor of '" + t->name() + "'.", + ValueFlow::Value::LifetimeKind::SubObject, + [&](const LifetimeStore& ls) { + // Skip static variable + it = std::find_if(it, scope->varlist.cend(), [](const Variable& var) { + return !var.isStatic(); + }); if (it == scope->varlist.cend()) return; const Variable& var = *it; diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 69495e517..fadc184f5 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -3235,6 +3235,28 @@ private: " return &a[0].x;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // #11666 + check("template \n" + "struct Matrix;\n" + "template \n" + "struct Matrix {\n" + " std::array x;\n" + "private:\n" + " static constexpr decltype(&Matrix::x) members[] = {&Matrix::x};\n" + "};\n" + "template \n" + "struct Matrix {\n" + " std::array x;\n" + " std::array y;\n" + "private:\n" + " static constexpr decltype(&Matrix::x) members[] = {&Matrix::x, &Matrix::y};\n" + "};\n" + "template \n" + "Matrix O() {\n" + " return { {}, {} };\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void danglingLifetimeFunction() {