From e5fa6b7eface43f3d1a6a58bc1fb8ad6435d18da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Sun, 6 Nov 2022 19:17:50 +0100 Subject: [PATCH] Fix entity id for elaborated type referencing using declaration Fixes #149. --- src/libclang/type_parser.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/libclang/type_parser.cpp b/src/libclang/type_parser.cpp index add7e99..aabccce 100644 --- a/src/libclang/type_parser.cpp +++ b/src/libclang/type_parser.cpp @@ -673,10 +673,21 @@ std::unique_ptr parse_type_impl(const detail::parse_context& context, case CXType_Typedef: return make_leave_type(cur, type, [&](std::string&& spelling) { auto decl = clang_getTypeDeclaration(type); - if (detail::cxstring(clang_getCursorSpelling(decl)).empty()) - spelling = ""; // anonymous type - return cpp_user_defined_type::build( - cpp_type_ref(detail::get_entity_id(decl), std::move(spelling))); + if (clang_isInvalid(clang_getCursorKind(decl))) + { + // We can reach this point if we have an elaborated type referencing a using + // declaration. Give it an invalid id, since we have no way of retrieving it, but + // keep the spelling. + return cpp_user_defined_type::build( + cpp_type_ref(cpp_entity_id(""), std::move(spelling))); + } + else + { + if (detail::cxstring(clang_getCursorSpelling(decl)).empty()) + spelling = ""; // anonymous type + return cpp_user_defined_type::build( + cpp_type_ref(detail::get_entity_id(decl), std::move(spelling))); + } }); case CXType_Pointer: {