Skip to content

Commit a523b9a

Browse files
committed
Find template definitions that don't want to be found
1 parent 677b8fd commit a523b9a

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

src/ir/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl<'ctx> BindgenContext<'ctx> {
184184
&options.clang_args,
185185
&[],
186186
parse_options)
187-
.expect("TranslationUnit::parse");
187+
.expect("TranslationUnit::parse failed");
188188

189189
let root_module = Self::build_root_module(ItemId(0));
190190
let mut me = BindgenContext {

src/ir/template.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,13 @@ impl TemplateInstantiation {
9191
-> TemplateInstantiation {
9292
use clang_sys::*;
9393

94-
let template_args: Vec<_> = ty.template_args()
95-
.expect("If there weren't template args, then you shouldn't have \
96-
tried to instantiate a template!")
97-
.filter(|t| t.kind() != CXType_Invalid)
98-
.map(|t| Item::from_ty_or_ref(t, t.declaration(), None, ctx))
99-
.collect();
94+
let template_args = ty.template_args()
95+
.map(|args| {
96+
args.filter(|t| t.kind() != CXType_Invalid)
97+
.map(|t| Item::from_ty_or_ref(t, t.declaration(), None, ctx))
98+
.collect()
99+
})
100+
.unwrap_or(vec![]);
100101

101102
let definition = ty.declaration()
102103
.specialized()
@@ -108,7 +109,11 @@ impl TemplateInstantiation {
108109
return CXVisit_Break;
109110
}
110111

111-
CXVisit_Continue
112+
// Instantiations of template aliases might have the
113+
// TemplateRef to the template alias definition arbitrarily
114+
// deep, so we need to recurse here and not only visit
115+
// direct children.
116+
CXChildVisit_Recurse
112117
});
113118

114119
template_ref.and_then(|cur| cur.referenced())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// bindgen-flags: -- -std=c++14
2+
3+
template <typename T>
4+
struct Foo {
5+
template <typename> using FirstAlias = typename T::Associated;
6+
template <typename U> using SecondAlias = Foo<FirstAlias<U>>;
7+
SecondAlias<int> member;
8+
};

0 commit comments

Comments
 (0)