Skip to content

Commit 33d475d

Browse files
author
bors-servo
authored
Auto merge of #194 - emilio:template-args, r=fitzgen
clang: Some partially specialized templates return no template argument count. Trying to construct a test case, meanwhile: r? @fitzgen
2 parents 33534e5 + ef59d9e commit 33d475d

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

src/clang.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ impl Cursor {
131131
/// Return the number of template arguments used by this cursor's referent,
132132
/// if the referent is either a template specialization or
133133
/// declaration. Returns -1 otherwise.
134+
///
135+
/// NOTE: This may not return `Some` for some non-fully specialized
136+
/// templates, see #193 and #194.
134137
pub fn num_template_args(&self) -> Option<u32> {
135138
let n: c_int = unsafe { clang_Cursor_getNumTemplateArguments(self.x) };
136139

@@ -193,7 +196,7 @@ impl Cursor {
193196
/// Is the referent a fully specialized template specialization without any
194197
/// remaining free template arguments?
195198
pub fn is_fully_specialized_template(&self) -> bool {
196-
self.is_template() && self.num_template_args().unwrap() > 0
199+
self.is_template() && self.num_template_args().unwrap_or(0) > 0
197200
}
198201

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

tests/expectations/base-to-derived.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(non_snake_case)]
5+
6+
7+
#[repr(C)]
8+
#[derive(Debug, Copy)]
9+
pub struct false_type {
10+
pub _address: u8,
11+
}
12+
#[test]
13+
fn bindgen_test_layout_false_type() {
14+
assert_eq!(::std::mem::size_of::<false_type>() , 1usize);
15+
assert_eq!(::std::mem::align_of::<false_type>() , 1usize);
16+
}
17+
impl Clone for false_type {
18+
fn clone(&self) -> Self { *self }
19+
}

tests/headers/base-to-derived.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// bindgen-flags: -- -std=c++11
2+
3+
struct false_type {};
4+
5+
template<typename _From, typename _To, bool>
6+
struct __is_base_to_derived_ref;
7+
8+
template<typename _From, typename _To>
9+
struct __is_base_to_derived_ref<_From, _To, true>
10+
{
11+
typedef _To type;
12+
13+
static constexpr bool value = type::value;
14+
};
15+
16+
template<typename _From, typename _To>
17+
struct __is_base_to_derived_ref<_From, _To, false>
18+
: public false_type
19+
{ };

0 commit comments

Comments
 (0)