Skip inner classes in CheckAutoVariables::returnReference() (#6951)
This commit is contained in:
parent
37aec52399
commit
7bb79562e9
|
@ -407,6 +407,11 @@ 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()) {
|
||||||
|
if (!tok2->scope()->isExecutable()) {
|
||||||
|
tok2 = tok2->scope()->classEnd;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Skip over lambdas
|
// Skip over lambdas
|
||||||
if (tok2->str() == "[" && tok2->link()->strAt(1) == "(" && tok2->link()->linkAt(1)->strAt(1) == "{")
|
if (tok2->str() == "[" && tok2->link()->strAt(1) == "(" && tok2->link()->linkAt(1)->strAt(1) == "{")
|
||||||
tok2 = tok2->link()->linkAt(1)->linkAt(1);
|
tok2 = tok2->link()->linkAt(1)->linkAt(1);
|
||||||
|
|
|
@ -99,6 +99,7 @@ private:
|
||||||
TEST_CASE(returnReferenceLiteral);
|
TEST_CASE(returnReferenceLiteral);
|
||||||
TEST_CASE(returnReferenceCalculation);
|
TEST_CASE(returnReferenceCalculation);
|
||||||
TEST_CASE(returnReferenceLambda);
|
TEST_CASE(returnReferenceLambda);
|
||||||
|
TEST_CASE(returnReferenceInnerScope);
|
||||||
|
|
||||||
// global namespace
|
// global namespace
|
||||||
TEST_CASE(testglobalnamespace);
|
TEST_CASE(testglobalnamespace);
|
||||||
|
@ -966,6 +967,19 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void returnReferenceInnerScope() {
|
||||||
|
// #6951
|
||||||
|
check("const Callback& make() {\n"
|
||||||
|
" struct _Wrapper {\n"
|
||||||
|
" static ulong call(void* o, const void* f, const void*[]) {\n"
|
||||||
|
" return 1;\n"
|
||||||
|
" }\n"
|
||||||
|
" };\n"
|
||||||
|
" return _make(_Wrapper::call, pmf);\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void testglobalnamespace() {
|
void testglobalnamespace() {
|
||||||
check("class SharedPtrHolder\n"
|
check("class SharedPtrHolder\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
Loading…
Reference in New Issue