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

Incorrect __cxx11 part in symbol names in generated rust code #789

Closed
cbourjau opened this issue Jul 5, 2017 · 8 comments
Closed

Incorrect __cxx11 part in symbol names in generated rust code #789

cbourjau opened this issue Jul 5, 2017 · 8 comments

Comments

@cbourjau
Copy link

cbourjau commented Jul 5, 2017

If I try to wrap a c++ header with bindgen, the compilation of my project fails due to incorrect naming in the generated rust file. The header is taken from issue #598, where a generated binding seems to suffer of the same issue.

Input C/C++ Header

#include<string>

class Test {
private:
  std::string m_value;
public:
  Test();
  const char* get_value();
};

Test::Test() {
  m_value = "test";
};

const char* Test::get_value() {
  return m_value.c_str();
}

Bindgen Invocation

bindgen::Builder::default()
        .clang_arg("-x")
        .clang_arg("c++")
        .clang_arg("-std=c++11")
        .whitelisted_type("Test")
    // Do not generate unstable Rust code that requires a nightly
    // rustc and enabling unstable features.
        .unstable_rust(false)
    // The input header we would like to generate
    // bindings for.
        .header("src/test.h")
    // Finish the builder and generate the bindings.
        .generate()
    // Unwrap the Result and panic on failure.
        .expect("Unable to generate bindings");

Actual Results

The generated rust file has undefined symbols:

error[E0412]: cannot find type `std_basic_string__Alloc_hider` in this scope
  --> /home/christian/repos/rust/bindgen_mvnp/target/debug/build/alice-sys-350880093f241c3d/out/bindings.rs:30:22
   |
30 |     pub _M_dataplus: std_basic_string__Alloc_hider,
   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ did you mean `std___cxx11_basic_string__Alloc_hider`?

here are the generated bindings:

/* automatically generated by rust-bindgen */

#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
impl <T> __BindgenUnionField<T> {
    #[inline]
    pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) }
    #[inline]
    pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) }
    #[inline]
    pub unsafe fn as_mut(&mut self) -> &mut T { ::std::mem::transmute(self) }
}
impl <T> ::std::default::Default for __BindgenUnionField<T> {
    #[inline]
    fn default() -> Self { Self::new() }
}
impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
    #[inline]
    fn clone(&self) -> Self { Self::new() }
}
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
    fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
        fmt.write_str("__BindgenUnionField")
    }
}
#[repr(C)]
#[derive(Debug)]
pub struct std___cxx11_basic_string<_CharT> {
    pub _M_dataplus: std_basic_string__Alloc_hider,
    pub _M_string_length: std_basic_string_size_type,
    pub __bindgen_anon_1: std_basic_string__bindgen_ty_2<_CharT>,
    pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<_CharT>>,
}
pub type std___cxx11_basic_string__Char_alloc_type = __gnu_cxx___alloc_traits;
pub type std___cxx11_basic_string__Alloc_traits = __gnu_cxx___alloc_traits;
pub type std___cxx11_basic_string_traits_type<_Traits> = _Traits;
pub type std___cxx11_basic_string_value_type = [u8; 0usize];
pub type std___cxx11_basic_string_allocator_type =
    std_basic_string__Char_alloc_type;
pub type std___cxx11_basic_string_size_type = std_basic_string__Alloc_traits;
pub type std___cxx11_basic_string_difference_type =
    std_basic_string__Alloc_traits;
pub type std___cxx11_basic_string_reference = std_basic_string__Alloc_traits;
pub type std___cxx11_basic_string_const_reference =
    std_basic_string__Alloc_traits;
pub type std___cxx11_basic_string_pointer = std_basic_string__Alloc_traits;
pub type std___cxx11_basic_string_const_pointer =
    std_basic_string__Alloc_traits;
pub type std___cxx11_basic_string_iterator =
    __gnu_cxx___normal_iterator<std_basic_string_pointer>;
pub type std___cxx11_basic_string_const_iterator =
    __gnu_cxx___normal_iterator<std_basic_string_const_pointer>;
pub type std___cxx11_basic_string_const_reverse_iterator =
    std_reverse_iterator<std_basic_string_const_iterator>;
pub type std___cxx11_basic_string_reverse_iterator =
    std_reverse_iterator<std_basic_string_iterator>;
pub type std___cxx11_basic_string___const_iterator =
    std_basic_string_const_iterator;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct std___cxx11_basic_string__Alloc_hider {
    pub _M_p: std_basic_string_pointer,
}
pub const std___cxx11_basic_string__S_local_capacity:
          std_basic_string__bindgen_ty_1 =
    std___cxx11_basic_string__bindgen_ty_1::_S_local_capacity;
#[repr(i32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum std___cxx11_basic_string__bindgen_ty_1 { _S_local_capacity = 0, }
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct std___cxx11_basic_string__bindgen_ty_2<_CharT> {
    pub _M_local_buf: __BindgenUnionField<*mut _CharT>,
    pub _M_allocated_capacity: __BindgenUnionField<std_basic_string_size_type>,
    pub bindgen_union_field: u64,
    pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<_CharT>>,
}
pub type std___cxx11_string = std_basic_string<::std::os::raw::c_char>;
#[repr(C)]
#[derive(Debug)]
pub struct std_allocator {
    pub _address: u8,
}
pub type std_allocator_size_type = usize;
pub type std_allocator_difference_type = isize;
pub type std_allocator_pointer<_Tp> = *mut _Tp;
pub type std_allocator_const_pointer<_Tp> = *mut _Tp;
pub type std_allocator_reference<_Tp> = *mut _Tp;
pub type std_allocator_const_reference<_Tp> = *mut _Tp;
pub type std_allocator_value_type<_Tp> = _Tp;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct std_allocator_rebind {
    pub _address: u8,
}
pub type std_allocator_rebind_other = std_allocator;
pub type std_allocator_propagate_on_container_move_assignment = std_true_type;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct std_char_traits {
    pub _address: u8,
}
pub type std_integral_constant_value_type<_Tp> = _Tp;
pub type std_integral_constant_type = u8;
pub type std_true_type = u8;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct std___and_ {
    pub _address: u8,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct std_iterator {
    pub _address: u8,
}
pub type std_iterator_iterator_category<_Category> = _Category;
pub type std_iterator_value_type<_Tp> = _Tp;
pub type std_iterator_difference_type<_Distance> = _Distance;
pub type std_iterator_pointer<_Pointer> = _Pointer;
pub type std_iterator_reference<_Reference> = _Reference;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct std___iterator_traits {
    pub _address: u8,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct std_iterator_traits {
    pub _address: u8,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct std_reverse_iterator<_Iterator> {
    pub current: _Iterator,
    pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<_Iterator>>,
}
pub type std_reverse_iterator___traits_type = std_iterator_traits;
pub type std_reverse_iterator_iterator_type<_Iterator> = _Iterator;
pub type std_reverse_iterator_difference_type =
    std_reverse_iterator___traits_type;
pub type std_reverse_iterator_pointer = std_reverse_iterator___traits_type;
pub type std_reverse_iterator_reference = std_reverse_iterator___traits_type;
pub type std_streamoff = ::std::os::raw::c_long;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct std_fpos<_StateT> {
    pub _M_off: std_streamoff,
    pub _M_state: _StateT,
    pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<_StateT>>,
}
pub type std_streampos = std_fpos<__mbstate_t>;
pub type std___allocator_base = __gnu_cxx_new_allocator;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct std_allocator_traits {
    pub _address: u8,
}
pub type std_allocator_traits_allocator_type<_Alloc> = _Alloc;
pub type std_allocator_traits_value_type = [u8; 0usize];
pub type std_allocator_traits___pointer<_Alloc> = _Alloc;
pub type std_allocator_traits_pointer<_Alloc> =
    std_allocator_traits___pointer<_Alloc>;
pub type std_allocator_traits___const_pointer<_Alloc> = _Alloc;
pub type std_allocator_traits_const_pointer<_Alloc> =
    std_allocator_traits___const_pointer<_Alloc>;
pub type std_allocator_traits___void_pointer<_Alloc> = _Alloc;
pub type std_allocator_traits_void_pointer<_Alloc> =
    std_allocator_traits___void_pointer<_Alloc>;
pub type std_allocator_traits___const_void_pointer<_Alloc> = _Alloc;
pub type std_allocator_traits_const_void_pointer<_Alloc> =
    std_allocator_traits___const_void_pointer<_Alloc>;
pub type std_allocator_traits___difference_type<_Alloc> = _Alloc;
pub type std_allocator_traits_difference_type<_Alloc> =
    std_allocator_traits___difference_type<_Alloc>;
pub type std_allocator_traits___size_type<_Alloc> = _Alloc;
pub type std_allocator_traits_size_type<_Alloc> =
    std_allocator_traits___size_type<_Alloc>;
pub type std_allocator_traits___propagate_on_container_copy_assignment<_Alloc>
    = _Alloc;
pub type std_allocator_traits_propagate_on_container_copy_assignment<_Alloc> =
    std_allocator_traits___propagate_on_container_copy_assignment<_Alloc>;
pub type std_allocator_traits___propagate_on_container_move_assignment<_Alloc>
    = _Alloc;
pub type std_allocator_traits_propagate_on_container_move_assignment<_Alloc> =
    std_allocator_traits___propagate_on_container_move_assignment<_Alloc>;
pub type std_allocator_traits___propagate_on_container_swap<_Alloc> = _Alloc;
pub type std_allocator_traits_propagate_on_container_swap<_Alloc> =
    std_allocator_traits___propagate_on_container_swap<_Alloc>;
pub type std_allocator_traits_rebind_alloc = u8;
pub type std_allocator_traits_rebind_traits = std_allocator_traits;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct std_allocator_traits___allocate_helper {
    pub _address: u8,
}
pub type std_allocator_traits___allocate_helper_type<_Alloc> = _Alloc;
pub type std_allocator_traits___has_allocate =
    std_allocator_traits___allocate_helper;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct std_allocator_traits___construct_helper {
    pub _address: u8,
}
pub type std_allocator_traits___construct_helper_type<_Alloc> = _Alloc;
pub type std_allocator_traits___has_construct =
    std_allocator_traits___construct_helper;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct std_allocator_traits___destroy_helper {
    pub _address: u8,
}
pub type std_allocator_traits___destroy_helper_type<_Alloc> = _Alloc;
pub type std_allocator_traits___has_destroy =
    std_allocator_traits___destroy_helper;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct std_allocator_traits___maxsize_helper {
    pub _address: u8,
}
pub type std_allocator_traits___maxsize_helper_type<_Alloc2> = _Alloc2;
pub type std_allocator_traits___has_max_size =
    std_allocator_traits___maxsize_helper;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct std_allocator_traits___select_helper {
    pub _address: u8,
}
pub type std_allocator_traits___select_helper_type<_Alloc2> = _Alloc2;
pub type std_allocator_traits___has_soccc =
    std_allocator_traits___select_helper;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct __gnu_cxx___normal_iterator<_Iterator> {
    pub _M_current: _Iterator,
    pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<_Iterator>>,
}
pub type __gnu_cxx___normal_iterator___traits_type = std_iterator_traits;
pub type __gnu_cxx___normal_iterator_iterator_type<_Iterator> = _Iterator;
pub type __gnu_cxx___normal_iterator_iterator_category =
    __gnu_cxx___normal_iterator___traits_type;
pub type __gnu_cxx___normal_iterator_value_type =
    __gnu_cxx___normal_iterator___traits_type;
pub type __gnu_cxx___normal_iterator_difference_type =
    __gnu_cxx___normal_iterator___traits_type;
pub type __gnu_cxx___normal_iterator_reference =
    __gnu_cxx___normal_iterator___traits_type;
pub type __gnu_cxx___normal_iterator_pointer =
    __gnu_cxx___normal_iterator___traits_type;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct __gnu_cxx__Char_types {
    pub _address: u8,
}
pub type __gnu_cxx__Char_types_int_type = ::std::os::raw::c_ulong;
pub type __gnu_cxx__Char_types_pos_type = std_streampos;
pub type __gnu_cxx__Char_types_off_type = std_streamoff;
pub type __gnu_cxx__Char_types_state_type = mbstate_t;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct __gnu_cxx_char_traits {
    pub _address: u8,
}
pub type __gnu_cxx_char_traits_char_type<_CharT> = _CharT;
pub type __gnu_cxx_char_traits_int_type = __gnu_cxx__Char_types;
pub type __gnu_cxx_char_traits_pos_type = __gnu_cxx__Char_types;
pub type __gnu_cxx_char_traits_off_type = __gnu_cxx__Char_types;
pub type __gnu_cxx_char_traits_state_type = __gnu_cxx__Char_types;
#[repr(C)]
#[derive(Debug)]
pub struct __gnu_cxx_new_allocator {
    pub _address: u8,
}
pub type __gnu_cxx_new_allocator_size_type = usize;
pub type __gnu_cxx_new_allocator_difference_type = isize;
pub type __gnu_cxx_new_allocator_pointer<_Tp> = *mut _Tp;
pub type __gnu_cxx_new_allocator_const_pointer<_Tp> = *mut _Tp;
pub type __gnu_cxx_new_allocator_reference<_Tp> = *mut _Tp;
pub type __gnu_cxx_new_allocator_const_reference<_Tp> = *mut _Tp;
pub type __gnu_cxx_new_allocator_value_type<_Tp> = _Tp;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct __gnu_cxx_new_allocator_rebind {
    pub _address: u8,
}
pub type __gnu_cxx_new_allocator_rebind_other = __gnu_cxx_new_allocator;
pub type __gnu_cxx_new_allocator_propagate_on_container_move_assignment =
    std_true_type;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct __gnu_cxx___alloc_traits {
    pub _address: u8,
}
pub type __gnu_cxx___alloc_traits_allocator_type<_Alloc> = _Alloc;
pub type __gnu_cxx___alloc_traits__Base_type = std_allocator_traits;
pub type __gnu_cxx___alloc_traits_value_type =
    __gnu_cxx___alloc_traits__Base_type;
pub type __gnu_cxx___alloc_traits_pointer =
    __gnu_cxx___alloc_traits__Base_type;
pub type __gnu_cxx___alloc_traits_const_pointer =
    __gnu_cxx___alloc_traits__Base_type;
pub type __gnu_cxx___alloc_traits_size_type =
    __gnu_cxx___alloc_traits__Base_type;
pub type __gnu_cxx___alloc_traits_difference_type =
    __gnu_cxx___alloc_traits__Base_type;
pub type __gnu_cxx___alloc_traits_reference =
    *mut __gnu_cxx___alloc_traits_value_type;
pub type __gnu_cxx___alloc_traits_const_reference =
    *const __gnu_cxx___alloc_traits_value_type;
pub type __gnu_cxx___alloc_traits___is_custom_pointer = std___and_;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct __gnu_cxx___alloc_traits_rebind {
    pub _address: u8,
}
pub type __gnu_cxx___alloc_traits_rebind_other =
    __gnu_cxx___alloc_traits__Base_type;
#[repr(C)]
#[derive(Debug, Copy)]
pub struct __mbstate_t {
    pub __count: ::std::os::raw::c_int,
    pub __value: __mbstate_t__bindgen_ty_1,
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct __mbstate_t__bindgen_ty_1 {
    pub __wch: __BindgenUnionField<::std::os::raw::c_uint>,
    pub __wchb: __BindgenUnionField<[::std::os::raw::c_char; 4usize]>,
    pub bindgen_union_field: u32,
}

Expected Results

The naming should obviously be valid. On IRC the idea was voiced that this might be related to "ABI tagging" but I do lack further insight into this issue.

RUST_LOG=bindgen Output

The log did not provide further details:

-*- mode: compilation; default-directory: "~/repos/rust/bindgen_mvnp/src/" -*-
Compilation started at Wed Jul  5 23:38:45

RUST_LOG=bindgen cargo build
   Compiling alice-sys v0.1.0 (file:///home/christian/repos/rust/bindgen_mvnp)
error[E0412]: cannot find type `std_basic_string__Alloc_hider` in this scope
  --> /home/christian/repos/rust/bindgen_mvnp/target/debug/build/alice-sys-350880093f241c3d/out/bindings.rs:30:22
   |
30 |     pub _M_dataplus: std_basic_string__Alloc_hider,
   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ did you mean `std___cxx11_basic_string__Alloc_hider`?

error[E0412]: cannot find type `std_basic_string_size_type` in this scope
  --> /home/christian/repos/rust/bindgen_mvnp/target/debug/build/alice-sys-350880093f241c3d/out/bindings.rs:31:27
   |
31 |     pub _M_string_length: std_basic_string_size_type,
   |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^ did you mean `std___cxx11_basic_string_size_type`?

error[E0412]: cannot find type `std_basic_string__bindgen_ty_2` in this scope
  --> /home/christian/repos/rust/bindgen_mvnp/target/debug/build/alice-sys-350880093f241c3d/out/bindings.rs:32:27
   |
32 |     pub __bindgen_anon_1: std_basic_string__bindgen_ty_2<_CharT>,
   |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ did you mean `std___cxx11_basic_string__bindgen_ty_2`?

error[E0412]: cannot find type `std_basic_string__Char_alloc_type` in this scope
  --> /home/christian/repos/rust/bindgen_mvnp/target/debug/build/alice-sys-350880093f241c3d/out/bindings.rs:40:5
   |
40 |     std_basic_string__Char_alloc_type;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ did you mean `std___cxx11_basic_string__Char_alloc_type`?

error[E0412]: cannot find type `std_basic_string__Alloc_traits` in this scope
  --> /home/christian/repos/rust/bindgen_mvnp/target/debug/build/alice-sys-350880093f241c3d/out/bindings.rs:41:47
   |
41 | pub type std___cxx11_basic_string_size_type = std_basic_string__Alloc_traits;
   |                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ did you mean `std___cxx11_basic_string__Alloc_traits`?

error[E0412]: cannot find type `std_basic_string__Alloc_traits` in this scope
  --> /home/christian/repos/rust/bindgen_mvnp/target/debug/build/alice-sys-350880093f241c3d/out/bindings.rs:43:5
   |
43 |     std_basic_string__Alloc_traits;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ did you mean `std___cxx11_basic_string__Alloc_traits`?

error[E0412]: cannot find type `std_basic_string__Alloc_traits` in this scope
  --> /home/christian/repos/rust/bindgen_mvnp/target/debug/build/alice-sys-350880093f241c3d/out/bindings.rs:44:47
   |
44 | pub type std___cxx11_basic_string_reference = std_basic_string__Alloc_traits;
   |                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ did you mean `std___cxx11_basic_string__Alloc_traits`?

error[E0412]: cannot find type `std_basic_string__Alloc_traits` in this scope
  --> /home/christian/repos/rust/bindgen_mvnp/target/debug/build/alice-sys-350880093f241c3d/out/bindings.rs:46:5
   |
46 |     std_basic_string__Alloc_traits;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ did you mean `std___cxx11_basic_string__Alloc_traits`?

error[E0412]: cannot find type `std_basic_string__Alloc_traits` in this scope
  --> /home/christian/repos/rust/bindgen_mvnp/target/debug/build/alice-sys-350880093f241c3d/out/bindings.rs:47:45
   |
47 | pub type std___cxx11_basic_string_pointer = std_basic_string__Alloc_traits;
   |                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ did you mean `std___cxx11_basic_string__Alloc_traits`?

error[E0412]: cannot find type `std_basic_string__Alloc_traits` in this scope
  --> /home/christian/repos/rust/bindgen_mvnp/target/debug/build/alice-sys-350880093f241c3d/out/bindings.rs:49:5
   |
49 |     std_basic_string__Alloc_traits;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ did you mean `std___cxx11_basic_string__Alloc_traits`?

error[E0412]: cannot find type `std_basic_string_pointer` in this scope
  --> /home/christian/repos/rust/bindgen_mvnp/target/debug/build/alice-sys-350880093f241c3d/out/bindings.rs:51:33
   |
51 |     __gnu_cxx___normal_iterator<std_basic_string_pointer>;
   |                                 ^^^^^^^^^^^^^^^^^^^^^^^^ did you mean `std___cxx11_basic_string_pointer`?

error[E0412]: cannot find type `std_basic_string_const_pointer` in this scope
  --> /home/christian/repos/rust/bindgen_mvnp/target/debug/build/alice-sys-350880093f241c3d/out/bindings.rs:53:33
   |
53 |     __gnu_cxx___normal_iterator<std_basic_string_const_pointer>;
   |                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ did you mean `std___cxx11_basic_string_const_pointer`?

error[E0412]: cannot find type `std_basic_string_const_iterator` in this scope
  --> /home/christian/repos/rust/bindgen_mvnp/target/debug/build/alice-sys-350880093f241c3d/out/bindings.rs:55:26
   |
55 |     std_reverse_iterator<std_basic_string_const_iterator>;
   |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ did you mean `std___cxx11_basic_string_const_iterator`?

error[E0412]: cannot find type `std_basic_string_iterator` in this scope
  --> /home/christian/repos/rust/bindgen_mvnp/target/debug/build/alice-sys-350880093f241c3d/out/bindings.rs:57:26
   |
57 |     std_reverse_iterator<std_basic_string_iterator>;
   |                          ^^^^^^^^^^^^^^^^^^^^^^^^^ did you mean `std___cxx11_basic_string_iterator`?

error[E0412]: cannot find type `std_basic_string_const_iterator` in this scope
  --> /home/christian/repos/rust/bindgen_mvnp/target/debug/build/alice-sys-350880093f241c3d/out/bindings.rs:59:5
   |
59 |     std_basic_string_const_iterator;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ did you mean `std___cxx11_basic_string_const_iterator`?

error[E0412]: cannot find type `std_basic_string_pointer` in this scope
  --> /home/christian/repos/rust/bindgen_mvnp/target/debug/build/alice-sys-350880093f241c3d/out/bindings.rs:63:15
   |
63 |     pub _M_p: std_basic_string_pointer,
   |               ^^^^^^^^^^^^^^^^^^^^^^^^ did you mean `std___cxx11_basic_string_pointer`?

error[E0412]: cannot find type `std_basic_string_pointer` in this scope
  --> /home/christian/repos/rust/bindgen_mvnp/target/debug/build/alice-sys-350880093f241c3d/out/bindings.rs:63:15
   |
63 |     pub _M_p: std_basic_string_pointer,
   |               ^^^^^^^^^^^^^^^^^^^^^^^^ did you mean `std___cxx11_basic_string_pointer`?

error[E0412]: cannot find type `std_basic_string__bindgen_ty_1` in this scope
  --> /home/christian/repos/rust/bindgen_mvnp/target/debug/build/alice-sys-350880093f241c3d/out/bindings.rs:66:11
   |
66 |           std_basic_string__bindgen_ty_1 =
   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ did you mean `std___cxx11_basic_string__bindgen_ty_1`?

error[E0412]: cannot find type `std_basic_string_size_type` in this scope
  --> /home/christian/repos/rust/bindgen_mvnp/target/debug/build/alice-sys-350880093f241c3d/out/bindings.rs:75:52
   |
75 |     pub _M_allocated_capacity: __BindgenUnionField<std_basic_string_size_type>,
   |                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^ did you mean `std___cxx11_basic_string_size_type`?

error[E0412]: cannot find type `std_basic_string` in this scope
  --> /home/christian/repos/rust/bindgen_mvnp/target/debug/build/alice-sys-350880093f241c3d/out/bindings.rs:79:31
   |
79 | pub type std___cxx11_string = std_basic_string<::std::os::raw::c_char>;
   |                               ^^^^^^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `std_string` in this scope
   --> /home/christian/repos/rust/bindgen_mvnp/target/debug/build/alice-sys-350880093f241c3d/out/bindings.rs:379:18
    |
379 |     pub m_value: std_string,
    |                  ^^^^^^^^^^ not found in this scope

error[E0204]: the trait `Copy` may not be implemented for this type
  --> /home/christian/repos/rust/bindgen_mvnp/target/debug/build/alice-sys-350880093f241c3d/out/bindings.rs:61:17
   |
61 | #[derive(Debug, Copy, Clone)]
   |                 ^^^^
62 | pub struct std___cxx11_basic_string__Alloc_hider {
63 |     pub _M_p: std_basic_string_pointer,
   |     ---------------------------------- this field does not implement `Copy`

error[E0204]: the trait `Copy` may not be implemented for this type
  --> /home/christian/repos/rust/bindgen_mvnp/target/debug/build/alice-sys-350880093f241c3d/out/bindings.rs:72:17
   |
72 | #[derive(Debug, Copy, Clone)]
   |                 ^^^^
...
75 |     pub _M_allocated_capacity: __BindgenUnionField<std_basic_string_size_type>,
   |     -------------------------------------------------------------------------- this field does not implement `Copy`

error: aborting due to 23 previous errors

error: Could not compile `alice-sys`.

To learn more, run the command again with --verbose.

@fitzgen
Copy link
Member

fitzgen commented Jul 5, 2017

The next steps to making this issue actionable are to look at what's inside <string> that is causing the __cxx11 prefix to get attached, and/or preprocess and C-Reduce the test case given.

I suspect it is using an inline namespace or something.

@emilio
Copy link
Contributor

emilio commented Jul 6, 2017

This seems like we're mishandling inline namespaces somewhere somewhere... Does the error go away if you turn on the conservative_inline_namespaces option?

And yeah, a reduced test-case based on the above would be neat! I can try to construct one, but I'll be mostly away until the next week, so if you beat me to it, that'd be rad :)

@cbourjau
Copy link
Author

cbourjau commented Jul 6, 2017

Setting the conservative_inline_namespace option did indeed solve the problem. I also (tried) to run creduce on the example code

# predicate.sh

#!/usr/bin/env bash

# Exit the script with a nonzero exit code if:
# * any individual command finishes with a nonzero exit code, or
# * we access any undefined variable.
set -eu

# Print out Rust backtraces on panic. Useful for minimizing a particular panic.
export RUST_BACKTRACE=1

# If the `libclang.so` you're using for `bindgen` isn't the system
# `libclang.so`, let the linker find it.
export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/

# Make sure that the reduced test case is valid C/C++ by compiling it. If it
# isn't valid C/C++, this command will exit with a nonzero exit code and cause
# the whole script to do the same.
clang --std=c++11 -c ./pre_processed.hpp

# Run `bindgen` and `grep` for the thing your hunting down! Make sure to include
# `2>&1` to get at stderr if you're hunting down a panic.
bindgen \
    --whitelist-type=Test \
    ./pre_processed.hpp \
    -- -x c++ --std=c++11 \
    2>&1 \
    | grep "__cxx11"

I am not sure if I greped the right string here, but this yielded:

namespace __cxx11 {
template <typename> class A {
  enum {};
};
}

which looks indeed namespace related as Emilio suggested. Any ideas on how to proceed?

@emilio
Copy link
Contributor

emilio commented Jul 6, 2017

Hmm... I don't think grepping for that will work, you presumably need a more complex test, or doing | rustc - | grep __cx11, or something of that sort.

Complete shot in the dark, since I haven't been able to reproduce it yet, does:

diff --git a/src/ir/item.rs b/src/ir/item.rs
index 3564c6e8..786cc708 100644
--- a/src/ir/item.rs
+++ b/src/ir/item.rs
@@ -649,6 +649,12 @@ impl Item {
                         _ => return item.id(),
                     }
                 }
+                ItemKind::Module(ref module) => {
+                    if !module.is_inline() || ctx.options().conservative_inline_namespaces {
+                        return item.id();
+                    }
+                    item = ctx.resolve_item(item.parent_id());
+                }
                 _ => return item.id(),
             }
         }

Fix the problem?

@emilio
Copy link
Contributor

emilio commented Jul 6, 2017

Ok, here it is:

namespace std {
inline namespace __cxx11 {
  template<typename CharT>
  class basic_string {
    struct Alloc_hider {
      void* storage;
    } hider;
    unsigned long length;
    struct {
      CharT inline_storage[4];
    };
  };
}
};

@emilio
Copy link
Contributor

emilio commented Jul 6, 2017

Ok, so the test-case above works with any of the --enable-cxx-namespaces and --conservative-inline-namespaces options.

@emilio
Copy link
Contributor

emilio commented Jul 6, 2017

#792

@emilio
Copy link
Contributor

emilio commented Jul 6, 2017

(I'm really bad at being mostly away, whoops)

bors-servo pushed a commit that referenced this issue Jul 6, 2017
ir: Properly skip inline namespaces when building names.

Fixes #789
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants