Skip to content

ir: Fix is_in_non_fully_specialized_template check. #466

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 1 commit into from
Feb 2, 2017
Merged
Show file tree
Hide file tree
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
16 changes: 12 additions & 4 deletions src/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,14 @@ impl Cursor {
}

/// Is the referent a template specialization?
pub fn is_template(&self) -> bool {
pub fn is_template_specialization(&self) -> bool {
self.specialized().is_some()
}

/// 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().unwrap_or(0) > 0
self.is_template_specialization() && self.num_template_args().unwrap_or(0) > 0
}

/// Is the referent a template specialization that still has remaining free
Expand All @@ -217,9 +217,17 @@ impl Cursor {
if self.is_toplevel() {
return false;
}

let parent = self.semantic_parent();
(parent.is_template() && !parent.is_fully_specialized_template()) ||
parent.is_in_non_fully_specialized_template()
if parent.is_fully_specialized_template() {
return false;
}

if !parent.is_template_like() {
return parent.is_in_non_fully_specialized_template();
}

return true;
}

/// Is this cursor pointing a valid referent?
Expand Down
2 changes: 1 addition & 1 deletion src/ir/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn get_abi(cc: CXCallingConv) -> abi::Abi {
pub fn cursor_mangling(cursor: &clang::Cursor) -> Option<String> {
// We early return here because libclang may crash in some case
// if we pass in a variable inside a partial specialized template.
// See servo/rust-bindgen#67.
// See servo/rust-bindgen#67, and servo/rust-bindgen#462.
if cursor.is_in_non_fully_specialized_template() {
return None;
}
Expand Down
24 changes: 24 additions & 0 deletions tests/expectations/tests/constant-non-specialized-tp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* automatically generated by rust-bindgen */


#![allow(non_snake_case)]


#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Test<Args> {
pub _address: u8,
pub _phantom_0: ::std::marker::PhantomData<Args>,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Outer<T> {
pub _address: u8,
pub _phantom_0: ::std::marker::PhantomData<T>,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Outer_Inner<T> {
pub _address: u8,
pub _phantom_0: ::std::marker::PhantomData<T>,
}
15 changes: 15 additions & 0 deletions tests/headers/constant-non-specialized-tp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// bindgen-flags: -- -std=c++11

// This test ensure we protect ourselves from an LLVM crash.

template <class... Args>
struct Test {
static constexpr bool x[] = {Args::x...};
};

template<typename... T>
struct Outer {
struct Inner {
static constexpr int value[] = { T::value... };
};
};