Skip inner classes in CheckAutoVariables::returnReference() (#6951)

This commit is contained in:
PKEuS 2015-08-26 13:31:51 +02:00
parent 37aec52399
commit 7bb79562e9
2 changed files with 19 additions and 0 deletions

View File

@ -407,6 +407,11 @@ void CheckAutoVariables::returnReference()
// have we reached a function that returns a reference?
if (tok->previous() && tok->previous()->str() == "&") {
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
if (tok2->str() == "[" && tok2->link()->strAt(1) == "(" && tok2->link()->linkAt(1)->strAt(1) == "{")
tok2 = tok2->link()->linkAt(1)->linkAt(1);

View File

@ -99,6 +99,7 @@ private:
TEST_CASE(returnReferenceLiteral);
TEST_CASE(returnReferenceCalculation);
TEST_CASE(returnReferenceLambda);
TEST_CASE(returnReferenceInnerScope);
// global namespace
TEST_CASE(testglobalnamespace);
@ -966,6 +967,19 @@ private:
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() {
check("class SharedPtrHolder\n"
"{\n"