forked from qt-creator/qt-creator
C++: Resolve function-scope typedef inside lambda
Use-case:
struct Foo { int bar; };
void func()
{
typedef Foo F;
[]() {
F f;
f.bar; // bar not highlighted
};
}
Change-Id: Ifaee2d125931d993acad69f03031a675c6180858
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
1faf2bd1ef
commit
f8544bbc42
@@ -154,6 +154,13 @@ QList<LookupItem> TypeResolver::typedefsFromScopeUpToFunctionScope(const Name *n
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
enclosingBlockScope = block->enclosingScope();
|
enclosingBlockScope = block->enclosingScope();
|
||||||
|
if (enclosingBlockScope) {
|
||||||
|
// For lambda, step beyond the function to its enclosing block
|
||||||
|
if (Function *enclosingFunction = enclosingBlockScope->asFunction()) {
|
||||||
|
if (!enclosingFunction->name())
|
||||||
|
enclosingBlockScope = enclosingBlockScope->enclosingScope();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2547,6 +2547,21 @@ void CppToolsPlugin::test_completion_data()
|
|||||||
) << _("ar") << (QStringList()
|
) << _("ar") << (QStringList()
|
||||||
<< QLatin1String("arg1"));
|
<< QLatin1String("arg1"));
|
||||||
|
|
||||||
|
QTest::newRow("local_typedef_access_in_lambda") << _(
|
||||||
|
"struct Foo { int bar; };\n"
|
||||||
|
"\n"
|
||||||
|
"void func()\n"
|
||||||
|
"{\n"
|
||||||
|
" typedef Foo F;\n"
|
||||||
|
" []() {\n"
|
||||||
|
" F f;\n"
|
||||||
|
" @\n"
|
||||||
|
" };\n"
|
||||||
|
"}\n"
|
||||||
|
) << _("f.") << (QStringList()
|
||||||
|
<< QLatin1String("Foo")
|
||||||
|
<< QLatin1String("bar"));
|
||||||
|
|
||||||
QTest::newRow("default_arguments_for_class_templates_and_base_class_QTCREATORBUG-12605") << _(
|
QTest::newRow("default_arguments_for_class_templates_and_base_class_QTCREATORBUG-12605") << _(
|
||||||
"struct Foo { int foo; };\n"
|
"struct Foo { int foo; };\n"
|
||||||
"template <typename T = Foo>\n"
|
"template <typename T = Foo>\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user