Commit 93f57a99 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh

C++: Fix nested type resolving in member functions

Task-number: QTCREATORBUG-13976
Task-number: QTCREATORBUG-13978
Change-Id: I598f9cb99ffd044abfc6ed9aa16d4a3045985008
Reviewed-by: default avatarPrzemyslaw Gorszkowski <pgorszkowski@gmail.com>
parent 0b996210
......@@ -1705,11 +1705,14 @@ bool CreateBindings::visit(Declaration *decl)
bool CreateBindings::visit(Function *function)
{
ClassOrNamespace *previous = _currentClassOrNamespace;
_currentClassOrNamespace = lookupType(function, previous);
for (unsigned i = 0, count = function->memberCount(); i < count; ++i) {
Symbol *s = function->memberAt(i);
if (Block *b = s->asBlock())
visit(b);
}
_currentClassOrNamespace = previous;
return false;
}
......
......@@ -1482,7 +1482,7 @@ void CppToolsPlugin::test_completion_data()
<< QLatin1String("A")
<< QLatin1String("a"));
QTest::newRow("nested_class_declaration_with_object_name_inside_function") << _(
QTest::newRow("nested_named_class_declaration_inside_function") << _(
"int foo()\n"
"{\n"
" struct Nested\n"
......@@ -1495,6 +1495,39 @@ void CppToolsPlugin::test_completion_data()
<< QLatin1String("Nested")
<< QLatin1String("i"));
QTest::newRow("nested_class_inside_member_function") << _(
"struct User { void use(); };\n"
"void User::use()\n"
"{\n"
" struct Foo { int bar; };\n"
" Foo foo;\n"
" @\n"
"}\n"
) << _("foo.") << (QStringList()
<< QLatin1String("Foo")
<< QLatin1String("bar"));
QTest::newRow("nested_typedef_inside_member_function") << _(
"struct User { void use(); };\n"
"template<class T>\n"
"struct Pointer { T *operator->(); };\n"
"struct Foo\n"
"{\n"
" typedef Pointer<Foo> Ptr;\n"
" int bar;\n"
"};\n"
"\n"
"void User::use()\n"
"{\n"
" typedef Foo MyFoo;\n"
" MyFoo::Ptr myfoo;\n"
" @\n"
"}\n"
) << _("myfoo->") << (QStringList()
<< QLatin1String("Foo")
<< QLatin1String("Ptr")
<< QLatin1String("bar"));
QTest::newRow("nested_anonymous_class_QTCREATORBUG10876_1") << _(
"struct EnclosingStruct\n"
"{\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