Skip to content

--wrap-static-fns emits incomplete struct _bindgen_ty_N for anonymous record parameters #3480

Description

@lwz23

Input C/C++ Header

static int take(struct { int x; int y; } s, int t) { return s.x + t; }

Bindgen Invocation

$ bindgen input.h --wrap-static-fns --wrap-static-fns-path wrap -- -x c -std=gnu11

Actual Results

bindgen exits 0. The generated wrapper is:

#include "input.h"

int take__extern(struct _bindgen_ty_1 s, int t) { return take(s, t); }

struct _bindgen_ty_1 is not in the header. clang:

wrap.c:5:25: warning: declaration of 'struct _bindgen_ty_1' will not be visible outside of this function
wrap.c:5:39: error: variable has incomplete type 'struct _bindgen_ty_1'

codegen/serialize.rs prints struct {canonical_name} for TypeKind::Comp. For an anonymous record that name is _bindgen_ty_N. A named struct S { int x; int y; } wrapper prints struct S and compiles.

Same thing for an anonymous union (union _bindgen_ty_1).

This is not #3403 (pointer-to-array declarators) or #2805 (_Bool vs bool).

Expected Results

The wrapper should use a C type that is complete after #include "input.h" (the original anonymous type, or a tag defined in the wrapper).

Environment

bindgen: 0.73.1 (rust-lang/rust-bindgen 77cbc723)
clang/libclang: Homebrew clang 21.1.8
rustc: 1.97.1
target: aarch64-apple-darwin
OS: macOS

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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