Commit e3f59773 authored by Przemyslaw Gorszkowski's avatar Przemyslaw Gorszkowski Committed by Nikolai Kosjar

C++: nested class in function

Case when nested class declaration contains object name for this class.
Example:
void fun()
{
    struct S
    {
        int i;
    } s;
    s.i;
}

Fixes:
* highlighting
* completion
* tests

Task-number: QTCREATORBUG-11710
Change-Id: I32e234f57655c388a87a199edc8be750d7bf823f
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarPrzemyslaw Gorszkowski <pgorszkowski@gmail.com>
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 46c083c2
......@@ -866,8 +866,12 @@ ClassOrNamespace *ResolveExpression::findClass(const FullySpecifiedType &origina
FullySpecifiedType ty = originalTy.simplified();
ClassOrNamespace *binding = 0;
if (Class *klass = ty->asClassType())
if (Class *klass = ty->asClassType()) {
if (scope->isBlock())
binding = _context.lookupType(klass->name(), scope, enclosingTemplateInstantiation);
if (!binding)
binding = _context.lookupType(klass, enclosingTemplateInstantiation);
}
else if (NamedType *namedTy = ty->asNamedType())
binding = _context.lookupType(namedTy->name(), scope, enclosingTemplateInstantiation);
......
......@@ -1441,6 +1441,19 @@ void CppToolsPlugin::test_completion_data()
<< QLatin1String("A")
<< QLatin1String("a"));
QTest::newRow("nested_class_declaration_with_object_name_inside_function") << _(
"int foo()\n"
"{\n"
" struct Nested\n"
" {\n"
" int i;\n"
" } n;\n"
" @;\n"
"}\n"
) << _("n.") << (QStringList()
<< QLatin1String("Nested")
<< QLatin1String("i"));
QTest::newRow("nested_anonymous_class_QTCREATORBUG10876_1") << _(
"struct EnclosingStruct\n"
"{\n"
......
......@@ -194,6 +194,7 @@ private slots:
void test_checksymbols_AnonymousClass();
void test_checksymbols_AnonymousClass_insideNamespace();
void test_checksymbols_AnonymousClass_QTCREATORBUG8963();
void test_checksymbols_class_declaration_with_object_name_nested_in_function();
void test_checksymbols_highlightingTypeWhenUsingNamespaceClass_QTCREATORBUG7903_globalNamespace();
void test_checksymbols_highlightingTypeWhenUsingNamespaceClass_QTCREATORBUG7903_namespace();
void test_checksymbols_highlightingTypeWhenUsingNamespaceClass_QTCREATORBUG7903_insideFunction();
......@@ -1585,6 +1586,31 @@ void tst_CheckSymbols::test_checksymbols_AnonymousClass_QTCREATORBUG8963()
TestData::check(source, expectedUses);
}
void tst_CheckSymbols::test_checksymbols_class_declaration_with_object_name_nested_in_function()
{
const QByteArray source =
"int foo()\n"
"{\n"
" struct Nested\n"
" {\n"
" int i;\n"
" } n;\n"
" n.i = 42;\n"
"}\n"
;
const QList<Use> expectedUses = QList<Use>()
<< Use(1, 5, 3, CppHighlightingSupport::FunctionUse)
<< Use(3, 12, 6, CppHighlightingSupport::TypeUse)
<< Use(5, 13, 1, CppHighlightingSupport::FieldUse)
<< Use(6, 7, 1, CppHighlightingSupport::LocalUse)
<< Use(7, 5, 1, CppHighlightingSupport::LocalUse)
<< Use(7, 7, 1, CppHighlightingSupport::FieldUse)
;
TestData::check(source, expectedUses);
}
void tst_CheckSymbols::test_checksymbols_highlightingTypeWhenUsingNamespaceClass_QTCREATORBUG7903_globalNamespace()
{
const QByteArray source =
......
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