Skip to content

Fix #121: Cursor::num_template_args(...) returns Option<u32> instead of c_int #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 1, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,14 @@ impl Cursor {
/// Return the number of template arguments used by this cursor's referent,
/// if the referent is either a template specialization or
/// declaration. Returns -1 otherwise.
pub fn num_template_args(&self) -> c_int {
unsafe {
clang_Cursor_getNumTemplateArguments(self.x)
pub fn num_template_args(&self) -> Option<u32> {
let n : c_int = unsafe { clang_Cursor_getNumTemplateArguments(self.x) };

if n >= 0 {
Some(n as u32)
} else {
debug_assert_eq!(n, -1);
None
}
}

Expand Down Expand Up @@ -192,7 +197,7 @@ impl Cursor {
/// Is the referent a fully specialized template specialization without any
/// remaining free template arguments?
pub fn is_fully_specialized_template(&self) -> bool {
self.is_template() && self.num_template_args() > 0
self.is_template() && self.num_template_args().unwrap() > 0
}

/// Is the referent a template specialization that still has remaining free
Expand Down