-
Notifications
You must be signed in to change notification settings - Fork 715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't generate bindings for deleted member functions #2044
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#![allow( | ||
dead_code, | ||
non_snake_case, | ||
non_camel_case_types, | ||
non_upper_case_globals | ||
)] | ||
|
||
#[repr(C)] | ||
#[derive(Debug, Default, Copy, Clone)] | ||
pub struct A { | ||
pub _address: u8, | ||
} | ||
#[test] | ||
fn bindgen_test_layout_A() { | ||
assert_eq!( | ||
::std::mem::size_of::<A>(), | ||
1usize, | ||
concat!("Size of: ", stringify!(A)) | ||
); | ||
assert_eq!( | ||
::std::mem::align_of::<A>(), | ||
1usize, | ||
concat!("Alignment of ", stringify!(A)) | ||
); | ||
} | ||
extern "C" { | ||
#[link_name = "\u{1}_ZN1A17inline_definitionEv"] | ||
pub fn A_inline_definition(this: *mut A); | ||
} | ||
extern "C" { | ||
#[link_name = "\u{1}_ZN1A22out_of_line_definitionEv"] | ||
pub fn A_out_of_line_definition(this: *mut A); | ||
} | ||
impl A { | ||
#[inline] | ||
pub unsafe fn inline_definition(&mut self) { | ||
A_inline_definition(self) | ||
} | ||
#[inline] | ||
pub unsafe fn out_of_line_definition(&mut self) { | ||
A_out_of_line_definition(self) | ||
} | ||
} | ||
#[repr(C)] | ||
#[derive(Debug, Default, Copy, Clone)] | ||
pub struct B { | ||
pub _address: u8, | ||
} | ||
#[test] | ||
fn bindgen_test_layout_B() { | ||
assert_eq!( | ||
::std::mem::size_of::<B>(), | ||
1usize, | ||
concat!("Size of: ", stringify!(B)) | ||
); | ||
assert_eq!( | ||
::std::mem::align_of::<B>(), | ||
1usize, | ||
concat!("Alignment of ", stringify!(B)) | ||
); | ||
} | ||
#[repr(C)] | ||
#[derive(Debug, Default, Copy, Clone)] | ||
pub struct C { | ||
pub _address: u8, | ||
} | ||
#[test] | ||
fn bindgen_test_layout_C() { | ||
assert_eq!( | ||
::std::mem::size_of::<C>(), | ||
1usize, | ||
concat!("Size of: ", stringify!(C)) | ||
); | ||
assert_eq!( | ||
::std::mem::align_of::<C>(), | ||
1usize, | ||
concat!("Alignment of ", stringify!(C)) | ||
); | ||
} | ||
extern "C" { | ||
#[link_name = "\u{1}_ZN1CC1ERS_"] | ||
pub fn C_C(this: *mut C, arg1: *mut C); | ||
} | ||
impl C { | ||
#[inline] | ||
pub unsafe fn new(arg1: *mut C) -> Self { | ||
let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); | ||
C_C(__bindgen_tmp.as_mut_ptr(), arg1); | ||
__bindgen_tmp.assume_init() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// bindgen-flags: --generate-inline-functions -- -std=c++11 | ||
|
||
class A { | ||
public: | ||
// Deleted function should not get a binding. | ||
void deleted() = delete; | ||
|
||
// Inline functions should get bindings, whether they are defined inline | ||
// (in the class) or out of line. | ||
inline void inline_definition() {} | ||
inline void out_of_line_definition(); | ||
|
||
// TODO: This is an edge case that we get wrong: An inline function | ||
// without a definition in the same translation unit should still get a | ||
// binding. We currently can't distinguish this case from a deleted member | ||
// function because libclang doesn't provide a direct way to query for | ||
// deleted member functions. This seems acceptable, however, as an inline | ||
// function without a definition in the same translation unit is unlikely | ||
// to be useful in practice. | ||
inline void inline_without_definition(); | ||
}; | ||
|
||
void A::out_of_line_definition() {} | ||
|
||
class B { | ||
public: | ||
// Deleted copy constructor should not get a binding. | ||
B(B&) = delete; | ||
}; | ||
|
||
class C { | ||
public: | ||
// Defaulted copy constructor should get a binding. | ||
C(C&) = default; | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth to shuffle the logic a bit to do less work in the common case, something like: