Commit f93758b8 authored by Przemyslaw Gorszkowski's avatar Przemyslaw Gorszkowski Committed by Erik Verbruggen

C++: fix used template function parameters

It was missing colorizing and follow symbol template function parameters in case of:
* returning value
* use it as qualified name

Task-number: QTCREATORBUG-6861

Change-Id: I4226199e1f296cfe5a373783ebbc633e32fc9bcd
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent feff3382
......@@ -175,6 +175,14 @@ protected:
virtual bool visit(Block *symbol)
{ return process(symbol); }
virtual bool visit(Template *symbol)
{
if (symbol->declaration() && symbol->declaration()->isFunction())
return process(symbol);
else
return true;
}
// Objective-C
virtual bool visit(ObjCBaseClass *) { return false; }
virtual bool visit(ObjCBaseProtocol *) { return false; }
......
......@@ -408,6 +408,14 @@ Scope *CheckSymbols::enclosingScope() const
if (funDef->symbol)
return funDef->symbol;
} else if (TemplateDeclarationAST *templateDeclaration = ast->asTemplateDeclaration()) {
if (DeclarationAST *decl = templateDeclaration->declaration) {
if (FunctionDefinitionAST *funDef = decl->asFunctionDefinition()) {
if (funDef->symbol)
return funDef->symbol;
}
}
} else if (CompoundStatementAST *blockStmt = ast->asCompoundStatement()) {
if (blockStmt->symbol)
return blockStmt->symbol;
......@@ -869,7 +877,12 @@ ClassOrNamespace *CheckSymbols::checkNestedName(QualifiedNameAST *ast)
const Name *name = class_or_namespace_name->name;
binding = _context.lookupType(name, enclosingScope());
addType(binding, class_or_namespace_name);
if (binding)
addType(binding, class_or_namespace_name);
else
// for the case when we use template parameter as qualifier
// e.g.: template <typename T> void fun() { T::type type; }
accept(nested_name_specifier->class_or_namespace_name);
for (it = it->next; it; it = it->next) {
NestedNameSpecifierAST *nested_name_specifier = it->value;
......
......@@ -1908,7 +1908,6 @@ void CppToolsPlugin::test_completion_typedef_using_templates1()
QVERIFY(completions.contains(QLatin1String("bar")));
}
void CppToolsPlugin::test_completion_typedef_using_templates2()
{
TestData data;
......
......@@ -195,6 +195,7 @@ private slots:
void test_checksymbols_highlightingTypeWhenUsingNamespaceClass_QTCREATORBUG7903_namespace();
void test_checksymbols_highlightingTypeWhenUsingNamespaceClass_QTCREATORBUG7903_insideFunction();
void test_checksymbols_crashWhenUsingNamespaceClass_QTCREATORBUG9323_globalNamespace();
void test_checksymbols_highlightingUsedTemplateFunctionParameter_QTCREATORBUG6861();
void test_checksymbols_crashWhenUsingNamespaceClass_QTCREATORBUG9323_namespace();
void test_checksymbols_crashWhenUsingNamespaceClass_QTCREATORBUG9323_insideFunction();
};
......@@ -1702,6 +1703,7 @@ void tst_CheckSymbols::test_checksymbols_crashWhenUsingNamespaceClass_QTCREATORB
TestData::check(source, expectedUses);
}
void tst_CheckSymbols::test_checksymbols_crashWhenUsingNamespaceClass_QTCREATORBUG9323_insideFunction()
{
const QByteArray source =
......@@ -1725,5 +1727,30 @@ void tst_CheckSymbols::test_checksymbols_crashWhenUsingNamespaceClass_QTCREATORB
TestData::check(source, expectedUses);
}
void tst_CheckSymbols::test_checksymbols_highlightingUsedTemplateFunctionParameter_QTCREATORBUG6861()
{
const QByteArray source =
"template<class TEMP>\n"
"TEMP \n"
"foo(TEMP in)\n"
"{\n"
" typename TEMP::type type;\n"
"}\n"
;
const QList<Use> expectedUses = QList<Use>()
<< Use(1, 16, 4, CppHighlightingSupport::TypeUse)
<< Use(2, 1, 4, CppHighlightingSupport::TypeUse)
<< Use(3, 1, 3, CppHighlightingSupport::FunctionUse)
<< Use(3, 5, 4, CppHighlightingSupport::TypeUse)
<< Use(3, 10, 2, CppHighlightingSupport::LocalUse)
<< Use(5, 14, 4, CppHighlightingSupport::TypeUse)
<< Use(5, 20, 4, CppHighlightingSupport::TypeUse)
<< Use(5, 25, 4, CppHighlightingSupport::LocalUse)
;
TestData::check(source, expectedUses);
}
QTEST_APPLESS_MAIN(tst_CheckSymbols)
#include "tst_checksymbols.moc"
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