diff --git a/src/clang.rs b/src/clang.rs index 0bfd78ef0e..a11e2924ed 100755 --- a/src/clang.rs +++ b/src/clang.rs @@ -362,11 +362,15 @@ impl Cursor { /// Get the unsigned constant value for this cursor's enum variant referent. /// - /// Returns `ULLONG_MAX` if the cursor's referent is not an enum variant, - /// which is also a valid enum value, so callers should check the cursor - /// kind before calling this method (see issue #128). - pub fn enum_val_unsigned(&self) -> u64 { - unsafe { clang_getEnumConstantDeclUnsignedValue(self.x) as u64 } + /// Returns None if the cursor's referent is not an enum variant. + pub fn enum_val_unsigned(&self) -> Option { + unsafe { + if self.kind() == CXCursor_EnumConstantDecl { + Some(clang_getEnumConstantDeclUnsignedValue(self.x) as u64) + } else { + None + } + } } /// Given that this cursor's referent is a `typedef`, get the `Type` that is diff --git a/src/ir/enum_ty.rs b/src/ir/enum_ty.rs index 1bcd5b149c..8efd9e3be1 100644 --- a/src/ir/enum_ty.rs +++ b/src/ir/enum_ty.rs @@ -75,7 +75,7 @@ impl Enum { let value = if is_signed { cursor.enum_val_signed().map(EnumVariantValue::Signed) } else { - Some(EnumVariantValue::Unsigned(cursor.enum_val_unsigned())) + cursor.enum_val_unsigned().map(EnumVariantValue::Unsigned) }; if let Some(val) = value { let name = cursor.spelling();