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 1 commit
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
14 changes: 10 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,8 @@ 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()
.expect("Not a class template specialization") > 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you call unwrap directly? It's clear from the backtrace what the failure is.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok will do the change, thanks for the feedback

}

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