summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-11-02 18:41:04 -0500
committerGitHub <noreply@github.com>2016-11-02 18:41:04 -0500
commit33d475dd56b8c0513771139da2f04e7542eaadb3 (patch)
tree9fffb34077fe29b1731a00fc19372d12f2e593a4
parent33534e576003aec13d0d7f59d75c2980aae35273 (diff)
parentef59d9ed1eeb45494a183c6363069ec492969b34 (diff)
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
-rwxr-xr-xsrc/clang.rs5
-rw-r--r--tests/expectations/base-to-derived.rs19
-rw-r--r--tests/headers/base-to-derived.hpp19
3 files changed, 42 insertions, 1 deletions
diff --git a/src/clang.rs b/src/clang.rs
index bc3d511f..b58cf017 100755
--- a/src/clang.rs
+++ b/src/clang.rs
@@ -131,6 +131,9 @@ 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.
+ ///
+ /// NOTE: This may not return `Some` for some non-fully specialized
+ /// templates, see #193 and #194.
pub fn num_template_args(&self) -> Option<u32> {
let n: c_int = unsafe { clang_Cursor_getNumTemplateArguments(self.x) };
@@ -193,7 +196,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().unwrap() > 0
+ self.is_template() && self.num_template_args().unwrap_or(0) > 0
}
/// Is the referent a template specialization that still has remaining free
diff --git a/tests/expectations/base-to-derived.rs b/tests/expectations/base-to-derived.rs
new file mode 100644
index 00000000..c2af2c43
--- /dev/null
+++ b/tests/expectations/base-to-derived.rs
@@ -0,0 +1,19 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(non_snake_case)]
+
+
+#[repr(C)]
+#[derive(Debug, Copy)]
+pub struct false_type {
+ pub _address: u8,
+}
+#[test]
+fn bindgen_test_layout_false_type() {
+ assert_eq!(::std::mem::size_of::<false_type>() , 1usize);
+ assert_eq!(::std::mem::align_of::<false_type>() , 1usize);
+}
+impl Clone for false_type {
+ fn clone(&self) -> Self { *self }
+}
diff --git a/tests/headers/base-to-derived.hpp b/tests/headers/base-to-derived.hpp
new file mode 100644
index 00000000..ea31e0f2
--- /dev/null
+++ b/tests/headers/base-to-derived.hpp
@@ -0,0 +1,19 @@
+// bindgen-flags: -- -std=c++11
+
+struct false_type {};
+
+template<typename _From, typename _To, bool>
+struct __is_base_to_derived_ref;
+
+template<typename _From, typename _To>
+struct __is_base_to_derived_ref<_From, _To, true>
+{
+ typedef _To type;
+
+ static constexpr bool value = type::value;
+};
+
+template<typename _From, typename _To>
+struct __is_base_to_derived_ref<_From, _To, false>
+: public false_type
+{ };