Skip to content
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
6 changes: 6 additions & 0 deletions bindgen-tests/tests/expectations/tests/const_array.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions bindgen-tests/tests/headers/const_array.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
extern const int foo[1];
extern int bar[1];
extern const int baz[1][1];
extern const int qux[][1];
1 change: 1 addition & 0 deletions bindgen-tests/tests/headers/const_multidim_array_fn_arg.h
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
void f(const int a[1][1]);
void g(const int a[1][1][1]);
10 changes: 9 additions & 1 deletion bindgen/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,15 @@ impl Type {

/// Is this type const qualified?
pub(crate) fn is_const(&self) -> bool {
unsafe { clang_isConstQualifiedType(self.x) != 0 }
let mut ty = *self;
while matches!(ty.kind(), CXType_ConstantArray | CXType_IncompleteArray)
{
match ty.elem_type() {
Some(elem) => ty = elem,
None => return false,
}
}
unsafe { clang_isConstQualifiedType(ty.x) != 0 }
}

#[inline]
Expand Down
4 changes: 1 addition & 3 deletions bindgen/ir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1254,9 +1254,7 @@ impl Type {

name = name.filter(|n| !n.is_empty());

let is_const = ty.is_const() ||
(ty.kind() == CXType_ConstantArray &&
ty.elem_type().is_some_and(|element| element.is_const()));
let is_const = ty.is_const();

let ty = Type::new(name, layout, kind, is_const);
// TODO: maybe declaration.canonical()?
Expand Down
8 changes: 1 addition & 7 deletions bindgen/ir/var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,7 @@ impl ClangSubItemParser for Var {

let ty = cursor.cur_type();

// TODO(emilio): do we have to special-case constant arrays in
// some other places?
let is_const = ty.is_const() ||
([CXType_ConstantArray, CXType_IncompleteArray]
.contains(&ty.kind()) &&
ty.elem_type()
.is_some_and(|element| element.is_const()));
let is_const = ty.is_const();

let ty = match Item::from_ty(&ty, cursor, None, ctx) {
Ok(ty) => ty,
Expand Down
Loading