Commit f8544bbc authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh

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: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent 1faf2bd1
......@@ -154,6 +154,13 @@ QList<LookupItem> TypeResolver::typedefsFromScopeUpToFunctionScope(const Name *n
}
}
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;
}
......
......@@ -2547,6 +2547,21 @@ void CppToolsPlugin::test_completion_data()
) << _("ar") << (QStringList()
<< 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") << _(
"struct Foo { int foo; };\n"
"template <typename T = Foo>\n"
......
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