diff --git a/src/libs/cplusplus/FindUsages.cpp b/src/libs/cplusplus/FindUsages.cpp index 5443a810f38..6e1731ca118 100644 --- a/src/libs/cplusplus/FindUsages.cpp +++ b/src/libs/cplusplus/FindUsages.cpp @@ -274,6 +274,10 @@ public: } } } + for (auto it2 = it; it2 != m_astPath.rend(); ++it2) { + if ((*it2)->asTemplateDeclaration()) + return tags |= Usage::Tag::Template; + } return tags; } if (const auto retStmt = (*it)->asReturnStatement()) { diff --git a/src/libs/cplusplus/FindUsages.h b/src/libs/cplusplus/FindUsages.h index 297bac0ca7e..7430eeb0f1d 100644 --- a/src/libs/cplusplus/FindUsages.h +++ b/src/libs/cplusplus/FindUsages.h @@ -24,6 +24,7 @@ public: WritableRef = 1 << 3, Override = 1 << 4, MocInvokable = 1 << 5, + Template = 1 << 6, }; using Tags = QFlags; diff --git a/src/plugins/clangcodemodel/clangdfindreferences.cpp b/src/plugins/clangcodemodel/clangdfindreferences.cpp index 25529723ba3..00c9f813d43 100644 --- a/src/plugins/clangcodemodel/clangdfindreferences.cpp +++ b/src/plugins/clangcodemodel/clangdfindreferences.cpp @@ -360,6 +360,22 @@ static Usage::Tags getUsageType(const ClangdAstPath &path, const QString &search if (path.last().role() == "expression" && path.last().kind() == "CXXConstruct") invokedConstructor = path.last().detail().value_or(QString()); const auto isPotentialWrite = [&] { return potentialWrite && !isFunction; }; + const auto isSomeSortOfTemplate = [&](auto declPathIt) { + if (declPathIt->kind() == "Function") { + const auto children = declPathIt->children().value_or(QList()); + for (const ClangdAstNode &child : children) { + if (child.role() == "template argument") + return true; + } + } + for (; declPathIt != path.rend(); ++declPathIt) { + if (declPathIt->kind() == "FunctionTemplate" || declPathIt->kind() == "ClassTemplate" + || declPathIt->kind() == "ClassTemplatePartialSpecialization") { + return true; + } + } + return false; + }; for (auto pathIt = path.rbegin(); pathIt != path.rend(); ++pathIt) { if (pathIt->arcanaContains("non_odr_use_unevaluated")) return {}; @@ -414,6 +430,8 @@ static Usage::Tags getUsageType(const ClangdAstPath &path, const QString &search tags |= Usage::Tag::MocInvokable; } } + if (isSomeSortOfTemplate(pathIt)) + tags |= Usage::Tag::Template; return tags; } if (pathIt->kind() == "MemberInitializer") diff --git a/tests/auto/cplusplus/findusages/tst_findusages.cpp b/tests/auto/cplusplus/findusages/tst_findusages.cpp index 5eea5d1d474..82dd5564379 100644 --- a/tests/auto/cplusplus/findusages/tst_findusages.cpp +++ b/tests/auto/cplusplus/findusages/tst_findusages.cpp @@ -1134,7 +1134,7 @@ void tst_FindUsages::templateClassParameters() findUsages(templArgument); QCOMPARE(findUsages.usages().size(), 5); QCOMPARE(findUsages.usages().at(0).tags, Usage::Tag::Declaration); - QCOMPARE(findUsages.usages().at(1).tags, Usage::Tags()); + QCOMPARE(findUsages.usages().at(1).tags, Usage::Tag::Template); QCOMPARE(findUsages.usages().at(2).tags, Usage::Tags()); QCOMPARE(findUsages.usages().at(3).tags, Usage::Tags()); QCOMPARE(findUsages.usages().at(4).tags, Usage::Tags()); @@ -1221,7 +1221,7 @@ void tst_FindUsages::templateFunctionParameters() QCOMPARE(findUsages.usages().size(), 4); QCOMPARE(findUsages.usages().at(0).tags, Usage::Tag::Declaration); QCOMPARE(findUsages.usages().at(1).tags, Usage::Tags()); - QCOMPARE(findUsages.usages().at(2).tags, Usage::Tags()); + QCOMPARE(findUsages.usages().at(2).tags, Usage::Tag::Template); QCOMPARE(findUsages.usages().at(3).tags, Usage::Tags()); } @@ -1253,7 +1253,8 @@ void tst_FindUsages::templatedFunction_QTCREATORBUG9749() FindUsages findUsages(src, doc, snapshot, true); findUsages(func); QCOMPARE(findUsages.usages().size(), 2); - QCOMPARE(findUsages.usages().at(0).tags, Usage::Tag::Declaration); + QCOMPARE(findUsages.usages().at(0).tags, + (Usage::Tags{Usage::Tag::Declaration, Usage::Tag::Template})); QCOMPARE(findUsages.usages().at(1).tags, Usage::Tags()); } @@ -1458,7 +1459,8 @@ void tst_FindUsages::memberAccessAsTemplate() FindUsages find(src, doc, snapshot, true); find(f); QCOMPARE(find.usages().size(), 2); - QCOMPARE(find.usages()[0].tags, Usage::Tag::Declaration); + QCOMPARE(find.usages()[0].tags, + (Usage::Tags{Usage::Tag::Declaration, Usage::Tag::Template})); QCOMPARE(find.usages()[0].line, 4); QCOMPARE(find.usages()[0].col, 7); QCOMPARE(find.usages()[1].tags, Usage::Tags());