diff --git a/src/libs/cplusplus/FindUsages.cpp b/src/libs/cplusplus/FindUsages.cpp index 07a912b8faf98cafb8c633cc2f44576208f5fcc7..7fe56b90e4edd25f8b6626ba73b3931eba4d9103 100644 --- a/src/libs/cplusplus/FindUsages.cpp +++ b/src/libs/cplusplus/FindUsages.cpp @@ -208,7 +208,15 @@ bool FindUsages::checkCandidates(const QList &candidates) const if (isLocalScope(_declSymbol->enclosingScope()) || isLocalScope(s->enclosingScope())) { if (s->enclosingScope()->isTemplate()) { - if (s->enclosingScope()->enclosingScope() != _declSymbol->enclosingScope()) + 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; diff --git a/tests/auto/cplusplus/findusages/tst_findusages.cpp b/tests/auto/cplusplus/findusages/tst_findusages.cpp index 18f94ce0b25dabd2159462998487873250dcb372..fd06f54537967cd66f0051ce5be9bf78d5279c21 100644 --- a/tests/auto/cplusplus/findusages/tst_findusages.cpp +++ b/tests/auto/cplusplus/findusages/tst_findusages.cpp @@ -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 char *reformatInteger(IntType value, int format) {}\n" + "void func(int code, int format) {\n" + " reformatInteger(code, format);" + "}\n" + ; + + Document::Ptr doc = Document::create("templatedFunction_QTCREATORBUG9749"); + doc->setUtf8Source(src); + doc->parse(); + doc->check(); + + QVERIFY(doc->diagnosticMessages().isEmpty()); + QCOMPARE(doc->globalSymbolCount(), 2U); + + Snapshot snapshot; + snapshot.insert(doc); + + Template *funcTempl = doc->globalSymbolAt(0)->asTemplate(); + QVERIFY(funcTempl); + QCOMPARE(funcTempl->memberCount(), 2U); + Function *func = funcTempl->memberAt(1)->asFunction(); + + FindUsages findUsages(src, doc, snapshot); + findUsages(func); + QCOMPARE(findUsages.usages().size(), 2); +} + QTEST_APPLESS_MAIN(tst_FindUsages) #include "tst_findusages.moc"