Commit 8ff225d9 authored by Nikolai Kosjar's avatar Nikolai Kosjar

C++: Fix (Find)LocalSymbols for lambda parameters

Change-Id: I5cb69749b4f15e4f70dea410aa6f943c4189c502
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent 995d1f77
......@@ -4455,6 +4455,9 @@ public:
ExceptionSpecificationAST *exception_specification;
TrailingReturnTypeAST *trailing_return_type;
public: // annotations
Function *symbol;
public:
LambdaDeclaratorAST()
: lparen_token(0)
......
......@@ -1098,6 +1098,7 @@ Function *Bind::lambdaDeclarator(LambdaDeclaratorAST *ast)
if (ast->trailing_return_type)
_type = this->trailingReturnType(ast->trailing_return_type, _type);
fun->setReturnType(_type);
ast->symbol = fun;
// unsigned lparen_token = ast->lparen_token;
FullySpecifiedType type;
......
......@@ -175,6 +175,19 @@ protected:
_scopeStack.removeLast();
}
virtual bool visit(LambdaExpressionAST *ast)
{
if (ast->lambda_declarator && ast->lambda_declarator->symbol)
enterScope(ast->lambda_declarator->symbol);
return true;
}
virtual void endVisit(LambdaExpressionAST *ast)
{
if (ast->lambda_declarator && ast->lambda_declarator->symbol)
_scopeStack.removeLast();
}
virtual bool visit(CompoundStatementAST *ast)
{
if (ast->symbol)
......
......@@ -157,6 +157,18 @@ void CppToolsPlugin::test_cpplocalsymbols_data()
<< Result(_("local"), 3, 8, 5)
<< Result(_("local"), 4, 12, 5)
<< Result(_("arg"), 4, 20, 3));
QTest::newRow("lambda")
<< _("void f()\n"
"{\n"
" auto func = [](int arg) { return arg; };\n"
" func(1);\n"
"}\n")
<< (QList<Result>()
<< Result(_("func"), 2, 10, 4)
<< Result(_("arg"), 2, 24, 3)
<< Result(_("arg"), 2, 38, 3)
<< Result(_("func"), 3, 5, 4));
}
void CppToolsPlugin::test_cpplocalsymbols()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment