Fix FP in lifetime anlaysis: Dont decay std array
This will fix FP with: ```cpp std::array<char, 1> f() { std::array<char, 1> x; return x; } ```
This commit is contained in:
parent
229c45e7f8
commit
67dd822910
|
@ -2840,7 +2840,7 @@ static void valueFlowLifetime(TokenList *tokenlist, SymbolDatabase*, ErrorLogger
|
||||||
const Variable * var = getLifetimeVariable(tok, errorPath);
|
const Variable * var = getLifetimeVariable(tok, errorPath);
|
||||||
if (!var)
|
if (!var)
|
||||||
continue;
|
continue;
|
||||||
if (var->isArray() && !var->isArgument() && tok->astParent() &&
|
if (var->isArray() && !var->isStlType() && !var->isArgument() && tok->astParent() &&
|
||||||
(astIsPointer(tok->astParent()) || Token::Match(tok->astParent(), "%assign%|return"))) {
|
(astIsPointer(tok->astParent()) || Token::Match(tok->astParent(), "%assign%|return"))) {
|
||||||
errorPath.emplace_back(tok, "Array decayed to pointer here.");
|
errorPath.emplace_back(tok, "Array decayed to pointer here.");
|
||||||
|
|
||||||
|
|
|
@ -1510,29 +1510,36 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" struct b {\n"
|
" struct b {\n"
|
||||||
" uint32_t f[6];\n"
|
" uint32_t f[6];\n"
|
||||||
" } d;\n"
|
" } d;\n"
|
||||||
" uint32_t *a = d.f;\n"
|
" uint32_t *a = d.f;\n"
|
||||||
"}\n");
|
=======
|
||||||
ASSERT_EQUALS("", errout.str());
|
// Dont decay std::array
|
||||||
|
check("std::array<char, 1> f() {\n"
|
||||||
|
" std::array<char, 1> x;\n"
|
||||||
|
" return x;\n"
|
||||||
|
>>>>>>> 52f00b8c88aecaa064f1acbebbe59331f08f09fc
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// Make sure we dont hang
|
// Make sure we dont hang
|
||||||
check("struct A;\n"
|
check("struct A;\n"
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
" using T = A[3];\n"
|
" using T = A[3];\n"
|
||||||
" A &&a = T{1, 2, 3}[1];\n"
|
" A &&a = T{1, 2, 3}[1];\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// Make sure we dont hang
|
// Make sure we dont hang
|
||||||
check("struct A;\n"
|
check("struct A;\n"
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
" using T = A[3];\n"
|
" using T = A[3];\n"
|
||||||
" A &&a = T{1, 2, 3}[1]();\n"
|
" A &&a = T{1, 2, 3}[1]();\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void danglingLifetimeFunction() {
|
void danglingLifetimeFunction() {
|
||||||
|
|
Loading…
Reference in New Issue