Fix issue 9196: Lambda confuses check (#2415)

This commit is contained in:
Paul Fultz II 2019-12-03 11:30:52 -06:00 committed by Daniel Marjamäki
parent 0e8a145d6c
commit 36977becba
2 changed files with 16 additions and 1 deletions

View File

@ -2586,7 +2586,12 @@ static bool valueFlowForwardVariable(Token* const startToken,
}
}
else if (tok2->str() == "}" && indentlevel == varusagelevel) {
// TODO: Check for eFunction
else if (tok2->str() == "}" && indentlevel <= 0 && tok2->scope() && tok2->scope()->type == Scope::eLambda) {
return true;
}
else if (tok2->str() == "}" && indentlevel == varusagelevel) {
++number_of_if;
// Set "conditional" flag for all values

View File

@ -87,6 +87,7 @@ private:
TEST_CASE(nullpointer45);
TEST_CASE(nullpointer46); // #9441
TEST_CASE(nullpointer47); // #6850
TEST_CASE(nullpointer48); // #9196
TEST_CASE(nullpointer_addressOf); // address of
TEST_CASE(nullpointerSwitch); // #2626
TEST_CASE(nullpointer_cast); // #4692
@ -1632,6 +1633,15 @@ private:
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (warning) Either the condition '!a' is redundant or there is possible null pointer dereference: p.\n", errout.str());
}
void nullpointer48() {
check("template<class T>\n"
"auto f(T& x) -> decltype(x);\n"
"int& g(int* x) {\n"
" return f(*x);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void nullpointer_addressOf() { // address of
check("void f() {\n"
" struct X *x = 0;\n"