mystor / rust-cpp

Embed C++ directly inside your rust code!
Apache License 2.0
802 stars 44 forks source link

Correct placement of 'const' relative to '&' in C++ code #13

Closed SpaceManiac closed 7 years ago

SpaceManiac commented 7 years ago

To see why the old behavior was incorrect, consider this case:

fn stuff(ptr: *mut Foo) {
    cpp!([ptr as "Foo*"] { cpp_stuff(ptr); });
}

ptr is a non-mutable binding containing a mutable pointer. A reference to it is of Rust type &*mut Foo. Currently cpp_build converts this to const Foo* & which is equivalent to Rust type &mut *const Foo. With this change, it converts it to Foo* const& which is equivalent to &*mut Foo.

Similar problems arise attempting to use "const char*" as the C++-side type for *const c_char, resulting in duplicate const.

mystor commented 7 years ago

Thanks for the fix!