Skip to content

Commit 3fb7c24

Browse files
committed
Workaround broken libclang version numbers
Closes #164.
1 parent a2de89b commit 3fb7c24

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

src/libclang/concept_parser.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ using namespace cppast;
1313
std::unique_ptr<cpp_entity> detail::try_parse_cpp_concept(const detail::parse_context& context,
1414
const CXCursor& cur)
1515
{
16-
#if CINDEX_VERSION_MINOR >= 62
17-
if (cur.kind != CXCursor_ConceptDecl)
16+
DEBUG_ASSERT(cur.kind == CXCursor_UnexposedDecl || cur.kind == CXCursor_ConceptDecl,
17+
detail::assert_handler{});
18+
if (libclang_definitely_has_concept_support && cur.kind != CXCursor_ConceptDecl)
1819
return nullptr;
19-
#else
20-
DEBUG_ASSERT(cur.kind == CXCursor_UnexposedDecl, detail::assert_handler{});
21-
#endif
2220

2321
detail::cxtokenizer tokenizer(context.tu, context.file, cur);
2422
detail::cxtoken_stream stream(tokenizer, cur);

src/libclang/parse_functions.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ try
119119
}
120120

121121
auto kind = clang_getCursorKind(cur);
122-
switch (kind)
122+
switch (int(kind))
123123
{
124124
case CXCursor_UnexposedDecl:
125125
// go through all the try_parse_XXX functions
@@ -198,13 +198,10 @@ try
198198
case CXCursor_ClassTemplatePartialSpecialization:
199199
return parse_cpp_class_template_specialization(context, cur);
200200

201-
#if CINDEX_VERSION_MINOR >= 62
202-
case CXCursor_ConceptDecl:
203-
return try_parse_cpp_concept(context, cur);
204-
#endif
205-
206201
case CXCursor_StaticAssert:
207202
return parse_cpp_static_assert(context, cur);
203+
case CXCursor_ConceptDecl:
204+
return try_parse_cpp_concept(context, cur);
208205

209206
default:
210207
break;

src/libclang/parse_functions.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,18 @@ namespace detail
9494
std::unique_ptr<cpp_entity> try_parse_cpp_language_linkage(const parse_context& context,
9595
const CXCursor& cur);
9696

97-
// unexposed
97+
// If the version is < 62, CXCursor_ConceptDecl does not exist.
98+
// If the version is > 62, CXCursor_ConceptDecl does exist.
99+
// If the version == 62, it may or may not exist. :(
100+
// As such, manually define it to the corresponding number.
101+
constexpr auto libclang_definitely_has_concept_support = CINDEX_VERSION_MINOR > 62;
102+
#if CINDEX_VERSION_MINOR > 62
103+
constexpr auto CXCursor_ConceptDecl = ::CXCursor_ConceptDecl;
104+
#else
105+
constexpr auto CXCursor_ConceptDecl = CXCursorKind(604);
106+
#endif
107+
108+
// unexposed, ConceptDecl
98109
std::unique_ptr<cpp_entity> try_parse_cpp_concept(const parse_context& context,
99110
const CXCursor& cur);
100111

0 commit comments

Comments
 (0)