Skip to content

clang::Type::num_elements should return Option<usize> #139

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

Closed
fitzgen opened this issue Oct 25, 2016 · 2 comments
Closed

clang::Type::num_elements should return Option<usize> #139

fitzgen opened this issue Oct 25, 2016 · 2 comments

Comments

@fitzgen
Copy link
Member

fitzgen commented Oct 25, 2016

We make an FFI call to clang_getNumElements but don't check the return value. We should check for failure and return None if we find it, only casting to usize and returning Some after we've verified a successful result.

http://clang.llvm.org/doxygen/group__CINDEX__TYPES.html#gac5f636020c388126bec572cb1fb13007

If a type is passed in that is not an array or vector type, -1 is returned.

This will be one less foot gun for callers that currently need to remember to check (for std::usize::MAX == -1 as usize? I doubt any do...).

I can mentor whoever wants to work on this.

@highfive
Copy link

Please make a comment here if you intend to work on this issue. Thank you!

@catdesk
Copy link
Contributor

catdesk commented Oct 29, 2016

I'm working on it!

bors-servo pushed a commit that referenced this issue Oct 30, 2016
Change clang::Type::num_elements to return Option

Fixes #139.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants