forked from qt-creator/qt-creator
C++: Fix (Find)LocalSymbols for lambda parameters
Change-Id: I5cb69749b4f15e4f70dea410aa6f943c4189c502 Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
3
src/libs/3rdparty/cplusplus/AST.h
vendored
3
src/libs/3rdparty/cplusplus/AST.h
vendored
@@ -4455,6 +4455,9 @@ public:
|
||||
ExceptionSpecificationAST *exception_specification;
|
||||
TrailingReturnTypeAST *trailing_return_type;
|
||||
|
||||
public: // annotations
|
||||
Function *symbol;
|
||||
|
||||
public:
|
||||
LambdaDeclaratorAST()
|
||||
: lparen_token(0)
|
||||
|
||||
1
src/libs/3rdparty/cplusplus/Bind.cpp
vendored
1
src/libs/3rdparty/cplusplus/Bind.cpp
vendored
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user