Skip to content

Commit

Permalink
fix(cxx_indexer): properly handle dependent using decl names (#5808)
Browse files Browse the repository at this point in the history
* fix(cxx_indexer): properly handle dependent using decl names

* chore: fix RE digit class in test
  • Loading branch information
shahms committed Aug 23, 2023
1 parent 26ce9e0 commit 7864f66
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion kythe/cxx/indexer/cxx/decl_printer.cc
Expand Up @@ -192,7 +192,9 @@ bool DeclPrinter::PrintDeclarationName(const clang::DeclarationName& name,
[[fallthrough]];
case DeclarationName::CXXConstructorName:
if (const auto type = name.getCXXNameType(); !type.isNull()) {
return PrintNamedDecl(*type->getAsCXXRecordDecl(), out);
// UnresolvedUsingValueDecl (and potentially others) result in a
// non-null QualType, but a null CXXRecordDecl.
return PrintName(type->getAsCXXRecordDecl(), out);
}
break;
// These will be given parent-relative identifiers.
Expand Down
20 changes: 20 additions & 0 deletions kythe/cxx/indexer/cxx/decl_printer_test.cc
Expand Up @@ -291,5 +291,25 @@ TEST(DeclPrinterTest, AnonymousNamespace) {
EXPECT_THAT(decl, Pointee(HasQualifiedId(printer, "foo:@#anon")));
}

TEST(DeclPrinterTest, UnresolvedUsingValueDecl) {
using ::clang::ast_matchers::unresolvedUsingValueDecl;
constexpr std::string_view code = R"c++(
template <typename>
struct Base {};
template <typename T>
struct Child : Base<T> {
using Base<T>::Base;
};
)c++";

ParsedUnit unit(buildASTFromCode(code, "input.cc"));
DeclPrinter printer = unit.CreateDeclPrinter();
const auto* decl = FindSingleDeclOrDie<clang::UnresolvedUsingValueDecl>(
unresolvedUsingValueDecl(), unit.ast_context());

EXPECT_THAT(decl,
Pointee(HasQualifiedId(printer, MatchesRegex(R"([0-9]:Child)"))));
}

} // namespace
} // namespace kythe

0 comments on commit 7864f66

Please sign in to comment.