// * enum constants in unscoped enum decl (e.g. "red" in "enum {red};")
auto InTopLevelScope = hasDeclContext(
anyOf(namespaceDecl(), translationUnitDecl(), linkageSpecDecl()));
+ // Don't index template specializations.
+ auto IsSpecialization =
+ anyOf(functionDecl(isExplicitTemplateSpecialization()),
+ cxxRecordDecl(isExplicitTemplateSpecialization()),
+ varDecl(isExplicitTemplateSpecialization()));
if (match(decl(allOf(unless(isExpansionInMainFile()),
anyOf(InTopLevelScope,
hasDeclContext(enumDecl(InTopLevelScope,
- unless(isScoped())))))),
+ unless(isScoped())))),
+ unless(IsSpecialization))),
*ND, *ASTCtx)
.empty())
return true;
QName("foo::bar::v2"), QName("foo::baz")}));
}
+TEST_F(SymbolCollectorTest, Template) {
+ Annotations Header(R"(
+ // Template is indexed, specialization and instantiation is not.
+ template <class T> struct [[Tmpl]] {T x = 0};
+ template <> struct Tmpl<int> {};
+ extern template struct Tmpl<float>;
+ template struct Tmpl<double>;
+ )");
+ runSymbolCollector(Header.code(), /*Main=*/"");
+ EXPECT_THAT(Symbols, UnorderedElementsAreArray({AllOf(
+ QName("Tmpl"), DeclRange(Header.offsetRange()))}));
+}
+
TEST_F(SymbolCollectorTest, Locations) {
Annotations Header(R"cpp(
// Declared in header, defined in main.