C++: Fix nested type resolving in member functions

Task-number: QTCREATORBUG-13976
Task-number: QTCREATORBUG-13978
Change-Id: I598f9cb99ffd044abfc6ed9aa16d4a3045985008
Reviewed-by: Przemyslaw Gorszkowski <pgorszkowski@gmail.com>
This commit is contained in:
Orgad Shaneh
2015-03-04 10:59:19 +02:00
committed by Orgad Shaneh
parent 0b996210f6
commit 93f57a99a1
2 changed files with 37 additions and 1 deletions

View File

@@ -1705,11 +1705,14 @@ bool CreateBindings::visit(Declaration *decl)
bool CreateBindings::visit(Function *function) bool CreateBindings::visit(Function *function)
{ {
ClassOrNamespace *previous = _currentClassOrNamespace;
_currentClassOrNamespace = lookupType(function, previous);
for (unsigned i = 0, count = function->memberCount(); i < count; ++i) { for (unsigned i = 0, count = function->memberCount(); i < count; ++i) {
Symbol *s = function->memberAt(i); Symbol *s = function->memberAt(i);
if (Block *b = s->asBlock()) if (Block *b = s->asBlock())
visit(b); visit(b);
} }
_currentClassOrNamespace = previous;
return false; return false;
} }

View File

@@ -1482,7 +1482,7 @@ void CppToolsPlugin::test_completion_data()
<< QLatin1String("A") << QLatin1String("A")
<< 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" "int foo()\n"
"{\n" "{\n"
" struct Nested\n" " struct Nested\n"
@@ -1495,6 +1495,39 @@ void CppToolsPlugin::test_completion_data()
<< QLatin1String("Nested") << QLatin1String("Nested")
<< QLatin1String("i")); << 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") << _( QTest::newRow("nested_anonymous_class_QTCREATORBUG10876_1") << _(
"struct EnclosingStruct\n" "struct EnclosingStruct\n"
"{\n" "{\n"