Skip to content

--represent-cxx-operators panics: "S_operator()" is not a valid Ident #3482

Description

@lwz23

Input C/C++ Header

struct S {
    int x;
    int operator()(int t) const;
};

Bindgen Invocation

$ bindgen input.h --represent-cxx-operators -- -x c++ -std=c++17

Actual Results

bindgen aborts:

panicked at bindgen/ir/context.rs:903:9:
"S_operator()" is not a valid Ident

Without the flag, operators are skipped. With --represent-cxx-operators, FunctionSig::from_ty keeps operator(), then codegen does rust_ident("S_operator()"). rust_mangle only rewrites @, ?, $, and keywords, so the parentheses reach Ident::new.

Same panic for operator[], operator+, operator==. operator int does not panic (that spelling is already a valid Ident).

The rustdoc for the flag says the names are not valid Rust and you need ParseCallbacks::generated_name_override. The CLI has no callback, so bindgen panics instead of emitting something or skipping. #3142 added the flag for post-processors that rename; it did not document an abort.

rust_mangle has the same hole for clang-accepted non-XID names, e.g. gnu11 struct 🐶 { int x; };"🐶" is not a valid Ident. CJK struct 测试 is fine (XID).

Expected Results

Do not abort. Mangle operator() to a valid Ident (or skip with a diagnostic). Callers can still rename via generated_name_override.

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