File tree Expand file tree Collapse file tree 5 files changed +59
-1
lines changed Expand file tree Collapse file tree 5 files changed +59
-1
lines changed Original file line number Diff line number Diff line change 1+ // bindgen-flags: --use-specific-virtual-function-receiver --generate-inline-functions -- -x c++ -std=c++14
2+
3+ class Fish {
4+ public:
5+ virtual void swim () {
6+ }
7+ };
Original file line number Diff line number Diff line change @@ -533,7 +533,10 @@ impl FunctionSig {
533533 let is_const = is_method && cursor. method_is_const ( ) ;
534534 let is_virtual = is_method && cursor. method_is_virtual ( ) ;
535535 let is_static = is_method && cursor. method_is_static ( ) ;
536- if !is_static && !is_virtual {
536+ if !is_static &&
537+ ( !is_virtual ||
538+ ctx. options ( ) . use_specific_virtual_function_receiver )
539+ {
537540 let parent = cursor. semantic_parent ( ) ;
538541 let class = Item :: parse ( parent, None , ctx)
539542 . expect ( "Expected to parse the class" ) ;
Original file line number Diff line number Diff line change @@ -441,6 +441,9 @@ struct BindgenCommand {
441441 /// Always output explicit padding fields.
442442 #[ arg( long) ]
443443 explicit_padding : bool ,
444+ /// Always be specific about the 'receiver' of a virtual function.
445+ #[ arg( long) ]
446+ use_specific_virtual_function_receiver : bool ,
444447 /// Use distinct char16_t
445448 #[ arg( long) ]
446449 use_distinct_char16_t : bool ,
@@ -632,6 +635,7 @@ where
632635 translate_enum_integer_types,
633636 c_naming,
634637 explicit_padding,
638+ use_specific_virtual_function_receiver,
635639 use_distinct_char16_t,
636640 vtable_generation,
637641 sort_semantically,
@@ -930,6 +934,7 @@ where
930934 translate_enum_integer_types,
931935 c_naming,
932936 explicit_padding,
937+ use_specific_virtual_function_receiver,
933938 use_distinct_char16_t,
934939 vtable_generation,
935940 sort_semantically,
Original file line number Diff line number Diff line change @@ -153,6 +153,21 @@ macro_rules! options {
153153}
154154
155155options ! {
156+ /// Whether to specify the type of a virtual function receiver
157+ use_specific_virtual_function_receiver: bool {
158+ methods: {
159+ /// Normally, virtual functions have void* as their 'this' type.
160+ /// If this flag is enabled, override that behavior to indicate a
161+ /// pointer of the specific type.
162+ /// Disabled by default.
163+ pub fn use_specific_virtual_function_receiver( mut self , doit: bool ) -> Builder {
164+ self . options. use_specific_virtual_function_receiver = doit;
165+ self
166+ }
167+ } ,
168+ as_args: "--use-specific-virtual-function-receiver" ,
169+ } ,
170+
156171 /// Whether we should distinguish between C++'s 'char16_t' and 'u16'.
157172 /// The C++ type `char16_t` is its own special type; it's not a typedef
158173 /// of some other integer (this differs from C).
You can’t perform that action at this time.
0 commit comments