Skip to content

Commit 1ea12aa

Browse files
committed
ir: Ignore constructors with bogus spellings.
1 parent 892e2ec commit 1ea12aa

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

src/ir/function.rs

+17-7
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ impl FunctionSig {
337337
debug!("FunctionSig::from_ty {:?} {:?}", ty, cursor);
338338

339339
// Skip function templates
340-
if cursor.kind() == CXCursor_FunctionTemplate {
340+
let kind = cursor.kind();
341+
if kind == CXCursor_FunctionTemplate {
341342
return Err(ParseError::Continue);
342343
}
343344

@@ -347,13 +348,22 @@ impl FunctionSig {
347348
return Err(ParseError::Continue);
348349
}
349350

351+
// Constructors of non-type template parameter classes for some reason
352+
// include the template parameter in their name. Just skip them, since
353+
// we don't handle well non-type template parameters anyway.
354+
if (kind == CXCursor_Constructor || kind == CXCursor_Destructor) &&
355+
spelling.contains('<')
356+
{
357+
return Err(ParseError::Continue);
358+
}
359+
350360
let cursor = if cursor.is_valid() {
351361
*cursor
352362
} else {
353363
ty.declaration()
354364
};
355365

356-
let mut args: Vec<_> = match cursor.kind() {
366+
let mut args: Vec<_> = match kind {
357367
CXCursor_FunctionDecl |
358368
CXCursor_Constructor |
359369
CXCursor_CXXMethod |
@@ -397,9 +407,9 @@ impl FunctionSig {
397407
let must_use =
398408
ctx.options().enable_function_attribute_detection &&
399409
cursor.has_simple_attr("warn_unused_result");
400-
let is_method = cursor.kind() == CXCursor_CXXMethod;
401-
let is_constructor = cursor.kind() == CXCursor_Constructor;
402-
let is_destructor = cursor.kind() == CXCursor_Destructor;
410+
let is_method = kind == CXCursor_CXXMethod;
411+
let is_constructor = kind == CXCursor_Constructor;
412+
let is_destructor = kind == CXCursor_Destructor;
403413
if (is_constructor || is_destructor || is_method) &&
404414
cursor.lexical_parent() != cursor.semantic_parent()
405415
{
@@ -442,8 +452,8 @@ impl FunctionSig {
442452
}
443453
}
444454

445-
let ty_ret_type = if cursor.kind() == CXCursor_ObjCInstanceMethodDecl ||
446-
cursor.kind() == CXCursor_ObjCClassMethodDecl
455+
let ty_ret_type = if kind == CXCursor_ObjCInstanceMethodDecl ||
456+
kind == CXCursor_ObjCClassMethodDecl
447457
{
448458
ty.ret_type().or_else(|| cursor.ret_type()).ok_or(
449459
ParseError::Continue,
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
#![allow(
4+
dead_code,
5+
non_snake_case,
6+
non_camel_case_types,
7+
non_upper_case_globals
8+
)]

tests/headers/issue-1464.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
// Should not crash.
3+
template <int Foo> class Bar {
4+
public:
5+
Bar();
6+
~Bar();
7+
};

tests/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ fn compare_generated_header(
207207
expectation_file.write_all(actual.as_bytes())?;
208208
}
209209

210-
Err(Error::new(ErrorKind::Other, "Header and binding differ!"))
210+
Err(Error::new(ErrorKind::Other, "Header and binding differ! Run with BINDGEN_OVERWRITE_EXPECTED=1 in the environment to automatically overwrite the expectation."))
211211
}
212212

213213
fn create_bindgen_builder(header: &PathBuf) -> Result<Option<Builder>, Error> {

0 commit comments

Comments
 (0)