Fixed false positive #6787: Skip over lambdas in CheckAutoVariables::returnReference()
This commit is contained in:
parent
b0bf69bae7
commit
a297a03b64
|
@ -399,6 +399,10 @@ void CheckAutoVariables::returnReference()
|
||||||
// have we reached a function that returns a reference?
|
// have we reached a function that returns a reference?
|
||||||
if (tok->previous() && tok->previous()->str() == "&") {
|
if (tok->previous() && tok->previous()->str() == "&") {
|
||||||
for (const Token *tok2 = scope->classStart->next(); tok2 && tok2 != scope->classEnd; tok2 = tok2->next()) {
|
for (const Token *tok2 = scope->classStart->next(); tok2 && tok2 != scope->classEnd; tok2 = tok2->next()) {
|
||||||
|
// Skip over lambdas
|
||||||
|
if (tok2->str() == "[" && tok2->link()->strAt(1) == "(" && tok2->link()->linkAt(1)->strAt(1) == "{")
|
||||||
|
tok2 = tok2->link()->linkAt(1)->linkAt(1);
|
||||||
|
|
||||||
if (tok2->str() != "return")
|
if (tok2->str() != "return")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
@ -98,6 +98,7 @@ private:
|
||||||
TEST_CASE(returnReference7);
|
TEST_CASE(returnReference7);
|
||||||
TEST_CASE(returnReferenceLiteral);
|
TEST_CASE(returnReferenceLiteral);
|
||||||
TEST_CASE(returnReferenceCalculation);
|
TEST_CASE(returnReferenceCalculation);
|
||||||
|
TEST_CASE(returnReferenceLambda);
|
||||||
|
|
||||||
// global namespace
|
// global namespace
|
||||||
TEST_CASE(testglobalnamespace);
|
TEST_CASE(testglobalnamespace);
|
||||||
|
@ -954,6 +955,16 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void returnReferenceLambda() {
|
||||||
|
// #6787
|
||||||
|
check("const Item& foo(const Container& items) const {\n"
|
||||||
|
" return bar(items.begin(), items.end(),\n"
|
||||||
|
" [](const Item& lhs, const Item& rhs) {\n"
|
||||||
|
" return false;\n"
|
||||||
|
" });\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void testglobalnamespace() {
|
void testglobalnamespace() {
|
||||||
check("class SharedPtrHolder\n"
|
check("class SharedPtrHolder\n"
|
||||||
|
|
Loading…
Reference in New Issue