weixin_39915367
weixin_39915367
2020-11-30 19:07

Expected bool, found integral variable (0.30 -> 0.31 Regression)

Regression between the 0.30 and 0.31 releases that causes an invalid type (int instead of bool) in generated bindings. Platform: MSVC x86_64

Input C/C++ Header

winpty.h I unfortunately wasn't able to get creduce working on windows so unreduced is the best I can do for now.

Bindgen Invocation

Rust
  let bindings = bindgen::Builder::default()
        .header("src/include/winpty.h")
        .clang_arg("-x")
        .clang_arg("c++")
        // Enabling this causes a different error, probably rustfmt's fault
        .rustfmt_bindings(false)
        .generate()
        .expect("Unable to generate bindings");

Actual Results


error[E0308]: mismatched types
 --> C:\Users\Zac\Programming\c++\winpty\target\debug\build\winpty-sys-7016778a370aac5f\out/bindings.rs:5:217
  |
5 | } # [ repr ( C ) ] # [ derive ( Debug , Copy , Clone ) ] pub struct __vcrt_va_list_is_reference { pub _address : u8 , } pub const __vcrt_va_list_is_reference___the_value : __vcrt_va_list_is_reference__bindgen_ty_1 = 0 ; pub type __vcrt_va_list_is_reference__bindgen_ty_1 = bool ; pub type __vcrt_bool = bool ; extern "C" {
  |                                                                                                                                                                                                                         ^ expected bool, found integral variable
  |
  = note: expected type `bool`
             found type `{integer}`

Expected Results

Compilation succeeds

该提问来源于开源项目:rust-lang/rust-bindgen

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

11条回答

  • weixin_39716264 weixin_39716264 5月前

    Thanks for the bug report!

    点赞 评论 复制链接分享
  • weixin_39649965 weixin_39649965 5月前

    Self-reminder to take a look at this one

    点赞 评论 复制链接分享
  • weixin_39649965 weixin_39649965 5月前

    Arrgh, this includes windows.h, and I'm on a Linux system.

    , any chance to call .dump_preprocessed_input before generate() and attach it here? That way I can hopefully repro it.

    点赞 评论 复制链接分享
  • weixin_39915367 weixin_39915367 5月前

    Here. Gist may not have been the best medium for this, given it's 200k lines but it appears to work for me. Tell me if you need a reupload.

    点赞 评论 复制链接分享
  • weixin_39649965 weixin_39649965 5月前

    Thanks!

    Here's a reduced test-case out of that (probably can be reduced even further):

    cpp
    template <typename _ty>
    struct __vcrt_va_list_is_reference
    {
        enum : bool { __the_value = false };
    };
    
    template <typename _ty>
    struct __vcrt_va_list_is_reference<_ty>
    {
        enum : bool { __the_value = true };
    };
    
    template <typename _ty>
    struct __vcrt_va_list_is_reference<_ty>
    {
        enum : bool { __the_value = true };
    };
    
    template <typename _ty>
    void __vcrt_va_start_verify_argument_type() throw()
    {
        static_assert(!__vcrt_va_list_is_reference<_ty>::__the_value, "va_start argument must not have reference type and must not be parenthesized");
    }
    </_ty></typename></_ty></typename></_ty></typename></typename>

    You should be able to work around this blacklisting the relevant bits, but still this is a bug of course.

    点赞 评论 复制链接分享
  • weixin_39649965 weixin_39649965 5月前

    This is probably due to us not handling enum : bool... It's rad that that's allowed, I didn't even know about that.

    点赞 评论 复制链接分享
  • weixin_39649965 weixin_39649965 5月前

    Aand indeed, more reduced test-case:

    cpp
    enum MyEnum : bool {
      Value = true,
    };
    
    点赞 评论 复制链接分享
  • weixin_39649965 weixin_39649965 5月前

    And now the regression range makes sense, because it contains 89915f95.

    点赞 评论 复制链接分享
  • weixin_39649965 weixin_39649965 5月前

    Before that we'd generate instead:

    rust
    #[repr(u8)]
    #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
    pub enum MyEnum {
        Value = 1,
    }
    
    点赞 评论 复制链接分享
  • weixin_39649965 weixin_39649965 5月前

    Submitted a fix in https://github.com/rust-lang-nursery/rust-bindgen/pull/1232.

    点赞 评论 复制链接分享
  • weixin_39915367 weixin_39915367 5月前

    Amazing, thanks!

    点赞 评论 复制链接分享

相关推荐