Fixes https://github.com/clangd/clangd/issues/878.
Differential Revision: https://reviews.llvm.org/D111260
[[f^oo]](s);
}
)cpp",
+
+ // Enum base
+ R"cpp(
+ typedef int $def[[MyTypeD^ef]];
+ enum MyEnum : [[MyTy^peDef]] { };
+ )cpp",
+ R"cpp(
+ typedef int $def[[MyType^Def]];
+ enum MyEnum : [[MyTypeD^ef]];
+ )cpp",
+ R"cpp(
+ using $def[[MyTypeD^ef]] = int;
+ enum MyEnum : [[MyTy^peDef]] { };
+ )cpp",
};
for (const char *Test : Tests)
checkFindRefs(Test);
#include "IndexingContext.h"
#include "clang/AST/Attr.h"
+#include "clang/AST/Decl.h"
#include "clang/AST/DeclVisitor.h"
#include "clang/Index/IndexDataConsumer.h"
return true;
}
+ bool VisitEnumDecl(const EnumDecl *ED) {
+ TRY_TO(VisitTagDecl(ED));
+ // Indexing for enumdecl itself is handled inside TagDecl, we just want to
+ // visit integer-base here, which is different than other TagDecl bases.
+ if (auto *TSI = ED->getIntegerTypeSourceInfo())
+ IndexCtx.indexTypeSourceInfo(TSI, ED, ED, /*isBase=*/true);
+ return true;
+ }
+
bool handleReferencedProtocols(const ObjCProtocolList &ProtList,
const ObjCContainerDecl *ContD,
SourceLocation SuperLoc) {
Not(HasRole(SymbolRole::RelationBaseOf)))));
}
+TEST(IndexTest, EnumBase) {
+ std::string Code = R"cpp(
+ typedef int MyTypedef;
+ enum Foo : MyTypedef;
+ enum Foo : MyTypedef {};
+ )cpp";
+ auto Index = std::make_shared<Indexer>();
+ tooling::runToolOnCode(std::make_unique<IndexAction>(Index), Code);
+ EXPECT_THAT(
+ Index->Symbols,
+ AllOf(Contains(AllOf(QName("MyTypedef"), HasRole(SymbolRole::Reference),
+ WrittenAt(Position(3, 16)))),
+ Contains(AllOf(QName("MyTypedef"), HasRole(SymbolRole::Reference),
+ WrittenAt(Position(4, 16))))));
+}
} // namespace
} // namespace index
} // namespace clang