Commit d70a33c0 authored by Erik Verbruggen's avatar Erik Verbruggen Committed by Nikolai Kosjar

C++: fix scope matching for templates in FindUsages

When the cursor is on the name of declaration of a templated function,
then since f93758b8 the scope returned
by Document::findScopeAt is the scope of the template declaration.
Before it was the parent scope of the template declaration.

The check in FindUsages::checkCandidates did not check all combinations
of template(-child symbol) scopes for the searched symbol and its

Task-number: QTCREATORBUG-9749

Change-Id: Idc84a2ba718721ce54683a67635a93352784ddd1
Reviewed-by: default avatarNikolai Kosjar <>
parent 07c0a834
......@@ -208,8 +208,16 @@ bool FindUsages::checkCandidates(const QList<LookupItem> &candidates) const
if (isLocalScope(_declSymbol->enclosingScope()) || isLocalScope(s->enclosingScope())) {
if (s->enclosingScope()->isTemplate()) {
if (_declSymbol->enclosingScope()->isTemplate()) {
if (s->enclosingScope()->enclosingScope() != _declSymbol->enclosingScope()->enclosingScope())
return false;
} else {
if (s->enclosingScope()->enclosingScope() != _declSymbol->enclosingScope())
return false;
} else if (_declSymbol->enclosingScope()->isTemplate() && s->isTemplate()) {
if (_declSymbol->enclosingScope()->enclosingScope() != s->enclosingScope())
return false;
} else if (! s->isUsingDeclaration() && s->enclosingScope() != _declSymbol->enclosingScope()) {
return false;
......@@ -100,7 +100,7 @@ private Q_SLOTS:
void using_insideGlobalNamespace();
void using_insideNamespace();
void using_insideFunction();
void templatedFunction_QTCREATORBUG9749();
void tst_FindUsages::inlineMethod()
......@@ -706,5 +706,35 @@ void tst_FindUsages::operatorArrowOfNestedClassOfTemplateClass_QTCREATORBUG9005(
QCOMPARE(findUsages.usages().size(), 2);
void tst_FindUsages::templatedFunction_QTCREATORBUG9749()
const QByteArray src = "\n"
"template <class IntType> char *reformatInteger(IntType value, int format) {}\n"
"void func(int code, int format) {\n"
" reformatInteger(code, format);"
Document::Ptr doc = Document::create("templatedFunction_QTCREATORBUG9749");
QCOMPARE(doc->globalSymbolCount(), 2U);
Snapshot snapshot;
Template *funcTempl = doc->globalSymbolAt(0)->asTemplate();
QCOMPARE(funcTempl->memberCount(), 2U);
Function *func = funcTempl->memberAt(1)->asFunction();
FindUsages findUsages(src, doc, snapshot);
QCOMPARE(findUsages.usages().size(), 2);
#include "tst_findusages.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