indexer: fix getAdjustedDecl for explicit instantiations; fix incorrect short_offset_size=1 when name is empty

Fix #516
This commit is contained in:
Fangrui Song 2019-11-09 13:27:09 -08:00
parent 7e795e9b9e
commit 0a1e08a8ca

View File

@ -358,7 +358,7 @@ const Decl *getAdjustedDecl(const Decl *d) {
while (d) { while (d) {
if (auto *r = dyn_cast<CXXRecordDecl>(d)) { if (auto *r = dyn_cast<CXXRecordDecl>(d)) {
if (auto *s = dyn_cast<ClassTemplateSpecializationDecl>(r)) { if (auto *s = dyn_cast<ClassTemplateSpecializationDecl>(r)) {
if (!s->getTypeAsWritten()) { if (!s->isExplicitSpecialization()) {
llvm::PointerUnion<ClassTemplateDecl *, llvm::PointerUnion<ClassTemplateDecl *,
ClassTemplatePartialSpecializationDecl *> ClassTemplatePartialSpecializationDecl *>
result = s->getSpecializedTemplateOrPartial(); result = s->getSpecializedTemplateOrPartial();
@ -534,7 +534,8 @@ public:
name.replace(i, short_name.size(), qualified); name.replace(i, short_name.size(), qualified);
def.short_name_offset = i + qualified.size() - short_name.size(); def.short_name_offset = i + qualified.size() - short_name.size();
} }
def.short_name_size = short_name.size(); // name may be empty while short_name is not.
def.short_name_size = name.empty() ? 0 : short_name.size();
for (int paren = 0; i; i--) { for (int paren = 0; i; i--) {
// Skip parentheses in "(anon struct)::name" // Skip parentheses in "(anon struct)::name"
if (name[i - 1] == ')') if (name[i - 1] == ')')