Skip to content

wasm32 c++ constructors missing return values #1912

@devsnek

Description

@devsnek

Input C/C++ Header

class X {
 public:
  X();
}

Bindgen Invocation

$ bindgen input.h -- -target wasm32-wasi -xc++ -fvisibility=default

Actual Results

extern "C" {
    #[link_name = "\u{1}_ZN1XC1Ev"]
    pub fn X_X(this: *mut X);
}

Expected Results

extern "C" {
    #[link_name = "\u{1}_ZN1XC1Ev"]
    pub fn X_X(this: *mut X) -> *mut X;
}

I went to try and fix this myself, and found this code, so there seems to be some larger bug:

let ret = if is_constructor && ctx.is_target_wasm32() {
// Constructors in Clang wasm32 target return a pointer to the object
// being constructed.
let void = Item::builtin_type(TypeKind::Void, false, ctx);
Item::builtin_type(TypeKind::Pointer(void), false, ctx)
} else {
Item::from_ty_or_ref(ty_ret_type, cursor, None, ctx)
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions