Check if `clang_Type_getNumTemplateArguments` is loaded before use
@@ -911,6 +911,13 @@ impl Type {
/// Get the number of template arguments this type has, or `None` if it is
/// not some kind of template.
pub fn num_template_args(&self) -> Option<u32> {
+ // If an old libclang is loaded, we have no hope of answering this
+ // question correctly. However, that's no reason to panic when
+ // generating bindings for simple C headers with an old libclang.
+ if !clang_Type_getNumTemplateArguments::is_loaded() {
+ return None
+ }
+
let n = unsafe { clang_Type_getNumTemplateArguments(self.x) };
if n >= 0 {
Some(n as u32)
@@ -1639,8 +1646,11 @@ pub fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult {
depth,
format!(" {}spelling = \"{}\"", prefix, ty.spelling()),
);
- let num_template_args =
- unsafe { clang_Type_getNumTemplateArguments(ty.x) };
+ let num_template_args = if clang_Type_getNumTemplateArguments::is_loaded() {
+ unsafe { clang_Type_getNumTemplateArguments(ty.x) }
+ } else {
+ -1
+ };
if num_template_args >= 0 {
print_indent(
depth,
