Fix 11666: FP returnDanglingLifetime with specializations and ptr to member (#5003)
* Fix 11666: FP returnDanglingLifetime with specializations and ptr to member * Format
This commit is contained in:
parent
c5310fe8a2
commit
1b9369b78b
|
@ -4519,10 +4519,15 @@ static void valueFlowLifetimeClassConstructor(Token* tok,
|
||||||
std::vector<const Token*> args = getArguments(tok);
|
std::vector<const Token*> args = getArguments(tok);
|
||||||
if (scope->numConstructors == 0) {
|
if (scope->numConstructors == 0) {
|
||||||
auto it = scope->varlist.cbegin();
|
auto it = scope->varlist.cbegin();
|
||||||
LifetimeStore::forEach(args,
|
LifetimeStore::forEach(
|
||||||
"Passed to constructor of '" + t->name() + "'.",
|
args,
|
||||||
ValueFlow::Value::LifetimeKind::SubObject,
|
"Passed to constructor of '" + t->name() + "'.",
|
||||||
[&](const LifetimeStore& ls) {
|
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())
|
if (it == scope->varlist.cend())
|
||||||
return;
|
return;
|
||||||
const Variable& var = *it;
|
const Variable& var = *it;
|
||||||
|
|
|
@ -3235,6 +3235,28 @@ private:
|
||||||
" return &a[0].x;\n"
|
" return &a[0].x;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
// #11666
|
||||||
|
check("template <class T, int M, int N>\n"
|
||||||
|
"struct Matrix;\n"
|
||||||
|
"template <class T, int N>\n"
|
||||||
|
"struct Matrix<T, 1, N> {\n"
|
||||||
|
" std::array<T, N> x;\n"
|
||||||
|
"private:\n"
|
||||||
|
" static constexpr decltype(&Matrix::x) members[] = {&Matrix::x};\n"
|
||||||
|
"};\n"
|
||||||
|
"template <class T, int N>\n"
|
||||||
|
"struct Matrix<T, 2, N> {\n"
|
||||||
|
" std::array<T, N> x;\n"
|
||||||
|
" std::array<T, N> y;\n"
|
||||||
|
"private:\n"
|
||||||
|
" static constexpr decltype(&Matrix::x) members[] = {&Matrix::x, &Matrix::y};\n"
|
||||||
|
"};\n"
|
||||||
|
"template <class T>\n"
|
||||||
|
"Matrix<T, 2, 2> O() {\n"
|
||||||
|
" return { {}, {} };\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void danglingLifetimeFunction() {
|
void danglingLifetimeFunction() {
|
||||||
|
|
Loading…
Reference in New Issue