parent
163fb79de1
commit
ac41b45a5f
|
@ -614,7 +614,7 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
|
||||||
const Token* nextTok = nextAfterAstRightmostLeaf(tok->astTop());
|
const Token* nextTok = nextAfterAstRightmostLeaf(tok->astTop());
|
||||||
if (!nextTok)
|
if (!nextTok)
|
||||||
nextTok = tok->next();
|
nextTok = tok->next();
|
||||||
if (var && !var->isLocal() && !var->isArgument() &&
|
if (var && !var->isLocal() && !var->isArgument() && !(val.tokvalue && val.tokvalue->variable() && val.tokvalue->variable()->isStatic()) &&
|
||||||
!isVariableChanged(nextTok,
|
!isVariableChanged(nextTok,
|
||||||
tok->scope()->bodyEnd,
|
tok->scope()->bodyEnd,
|
||||||
var->declarationId(),
|
var->declarationId(),
|
||||||
|
|
|
@ -3273,6 +3273,19 @@ private:
|
||||||
" return { {}, {} };\n"
|
" return { {}, {} };\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
// #11729
|
||||||
|
check("struct T {\n"
|
||||||
|
" void add(int* i) {\n"
|
||||||
|
" v.push_back(i);\n"
|
||||||
|
" }\n"
|
||||||
|
" void f() {\n"
|
||||||
|
" static int val = 1;\n"
|
||||||
|
" add(&val);\n"
|
||||||
|
" }\n"
|
||||||
|
" std::vector<int*> v;\n"
|
||||||
|
"};\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void danglingLifetimeFunction() {
|
void danglingLifetimeFunction() {
|
||||||
|
|
Loading…
Reference in New Issue