Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repr(align(0)) for std::basic_string causing build error #1565

Closed
bengl opened this issue May 20, 2019 · 5 comments · Fixed by #1593 or #1595
Closed

repr(align(0)) for std::basic_string causing build error #1565

bengl opened this issue May 20, 2019 · 5 comments · Fixed by #1593 or #1595

Comments

@bengl
Copy link

bengl commented May 20, 2019

Input C/C++ Header

#include <string>
using namespace std;
basic_string<char> simple(basic_string<char> str);

Bindgen Invocation

bindgen::Builder::default()
    .header("simple.hpp")
    .clang_arg("-x")
    .clang_arg("c++")
    .opaque_type("std::.*")
    .whitelist_function("simple")
    .generate()
    .unwrap()

Actual Results

Generating the binding.rs works fine, but when compiling....

cargo build
  Compiling simple-bindgen v0.1.0 (simple-bindgen)
error[E0589]: invalid `repr(align)` attribute: not a power of two
 --> simple-bindgen/target/debug/build/simple-bindgen-0af4d98c1d10abb2/out/bindings.rs:73:8
  |
73 | #[repr(align(0))]
  |        ^^^^^^^^

error[E0589]: invalid `repr(align)` attribute: not a power of two
 --> simple-bindgen/target/debug/build/simple-bindgen-0af4d98c1d10abb2/out/bindings.rs:90:8
  |
90 | #[repr(align(0))]
  |        ^^^^^^^^

The offending lines in the binding.rs look like:

#[repr(C)]
#[repr(align(0))]
pub union std_basic_string___ulx {
    pub _bindgen_opaque_blob: [u8; 0usize],
}

and

#[repr(C)]
#[repr(align(0))]
pub union std_basic_string___rep__bindgen_ty_1 {
    pub _bindgen_opaque_blob: [u8; 0usize],
}

Expected Results

While this works just fine on our linux machines, on our Macs, we get the error provided. Here's a sample uname -a from one of our Macs:

Darwin computer.local 18.5.0 Darwin Kernel Version 18.5.0: Mon Mar 11 20:40:32 PDT 2019; root:xnu-4903.251.3~3/RELEASE_X86_64 x86_64
@emilio
Copy link
Contributor

emilio commented May 21, 2019

Is there any chance to provide a test-case? Presumably we should be just min(align, 1) or such, but I'd rather land the fix with a test that reproduces the issue.

@bengl
Copy link
Author

bengl commented May 21, 2019

Here's a __bindgen.ii file (zipped to appease github).
__bindgen.ii.zip

@pmarks
Copy link
Contributor

pmarks commented Jul 12, 2019

Bump. I'm also hitting this on Mac for a library that refers to std::string. Would a smaller test case help?

@emilio
Copy link
Contributor

emilio commented Jul 12, 2019

Yes, for sure. creducing this would be awesome.

@emilio
Copy link
Contributor

emilio commented Jul 15, 2019

This is not fixed per #1593, which has a more complex test-case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants