rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

bindgen identifies unused template parameters in std::unique_ptr<std::string> with latest Mac OS SDK

Open adetaylor opened this issue 1 year ago • 0 comments

Using bindgen HEAD revision 7cc26581.

input.hpp contains:

/**
* <div rustbindgen="true" replaces="std::unique_ptr">
*/
template<typename T> class UniquePtr {
    T* ptr;
};
/**
* <div rustbindgen="true" replaces="std::string">
*/
class CxxString {
    char* ptr;
};

#include <memory>
#include <string>
std::unique_ptr<std::string> give_str_up();

Command-line:

cargo run --   "--blocklist-item" "std::unique_ptr" "--blocklist-item" "std::string" "--allowlist-function" "give_str_up" "--enable-cxx-namespaces" input.hpp "--" "-x" "c++" "-std=c++14" "-DBINDGEN"

On a Linux machine, this generates (abridged):

extern "C" {
    #[link_name = "\u{1}_Z11give_str_upB5cxx11v"]
    pub fn give_str_up() -> root::std::unique_ptr<root::std::string>;
}

On my current MacOS X machine, it gives me:

extern "C" {
    #[link_name = "\u{1}__Z11give_str_upv"]
    pub fn give_str_up() -> root::std::__1::unique_ptr;
}

Note the lack of template parameter on unique_ptr, which is the problem I'm facing.

This seems to be a difference in the latest version of the libc++ string header, causing bindgen to believe that the template parameters are unused. This used to be OK on prior OS X versions but I can't give specifics. The SDK causing trouble is the MacOS X 15 SDK.

This is (probably) the root cause of https://github.com/google/autocxx/issues/1396.

adetaylor avatar Sep 27 '24 19:09 adetaylor