CppTools: Fix highlighting and follow for template using argument

Use-case:
template<class T>
using Foo = Bar<T>; // T not highlighted

Task-number: QTCREATORBUG-9944
Change-Id: I04cb62ea6a21f158f7fb4fb7ac79ccd6eb1bbfbb
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
Orgad Shaneh
2015-06-07 13:15:34 +03:00
committed by Nikolai Kosjar
parent 7389f46959
commit 3fe1b92566
4 changed files with 10 additions and 8 deletions

View File

@@ -177,7 +177,7 @@ protected:
virtual bool visit(Template *symbol) virtual bool visit(Template *symbol)
{ {
if (Symbol *decl = symbol->declaration()) { if (Symbol *decl = symbol->declaration()) {
if (decl->isFunction() || decl->isClass()) if (decl->isFunction() || decl->isClass() || decl->isDeclaration())
return process(symbol); return process(symbol);
} }
return true; return true;

View File

@@ -967,6 +967,11 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_data()
"struct $Foo {};\n" "struct $Foo {};\n"
"auto foo() -> @Foo {}\n" "auto foo() -> @Foo {}\n"
); );
QTest::newRow("template_alias") << _(
"template<class $T>\n"
"using Foo = Bar<@T>;\n"
);
} }
void CppEditorPlugin::test_FollowSymbolUnderCursor() void CppEditorPlugin::test_FollowSymbolUnderCursor()

View File

@@ -423,12 +423,8 @@ Scope *CheckSymbols::enclosingScope() const
return funDef->symbol; return funDef->symbol;
} else if (TemplateDeclarationAST *templateDeclaration = ast->asTemplateDeclaration()) { } else if (TemplateDeclarationAST *templateDeclaration = ast->asTemplateDeclaration()) {
if (DeclarationAST *decl = templateDeclaration->declaration) { if (templateDeclaration->symbol)
if (FunctionDefinitionAST *funDef = decl->asFunctionDefinition()) { return templateDeclaration->symbol;
if (funDef->symbol)
return funDef->symbol;
}
}
} else if (CompoundStatementAST *blockStmt = ast->asCompoundStatement()) { } else if (CompoundStatementAST *blockStmt = ast->asCompoundStatement()) {
if (blockStmt->symbol) if (blockStmt->symbol)

View File

@@ -996,10 +996,11 @@ void tst_CheckSymbols::test_checksymbols_data()
QTest::newRow("template_alias") QTest::newRow("template_alias")
<< _("template<class T>\n" << _("template<class T>\n"
"using Foo = Bar;\n") "using Foo = Bar<T>;\n")
<< (QList<Use>() << (QList<Use>()
<< Use(1, 16, 1, Highlighting::TypeUse) << Use(1, 16, 1, Highlighting::TypeUse)
<< Use(2, 7, 3, Highlighting::TypeUse) << Use(2, 7, 3, Highlighting::TypeUse)
<< Use(2, 17, 1, Highlighting::TypeUse)
); );
QTest::newRow("using_inside_different_namespace_QTCREATORBUG7978") QTest::newRow("using_inside_different_namespace_QTCREATORBUG7978")