Skip to content
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

C++ features we can't handle right now. #41

Closed
emilio opened this issue Aug 25, 2016 · 9 comments
Closed

C++ features we can't handle right now. #41

emilio opened this issue Aug 25, 2016 · 9 comments

Comments

@emilio
Copy link
Contributor

emilio commented Aug 25, 2016

This is a list of things we can't handle correctly in bindgen, and we're not expected to be able to in a while.

Partial template specialization

We can't get the specialized types from a construct like this via libclang, rather unfortunately. We do hackily search through the ast to get the non-specialized ones though.

template<typename T, typename U>
class Foo { };

template<typename T>
class Bar {
  Foo<T, int> mFoo;
};

In the above example the ast for Bar is the following:

(ClassTemplate Bar Invalid
    (TemplateTypeParameter T Unexposed
    )
    (FieldDecl mFoo Unexposed
        (TemplateRef Foo Invalid
        )
        (TypeRef T Unexposed
        )
    )
)

And type template parameter related functions in bindgen don't give us any information.

Template unions with template parameters inside.

We can't handle this because the size of the union depends on size_of::<T>, and that's not const fn (and we can't use const fn in stable anyway). We can try to compute it and be correct if T is not the largest type in the union.

template<typename T>
union Bar {
  T mFoo;
  int mBar;
};
@fitzgen
Copy link
Member

fitzgen commented Aug 25, 2016

Can bindgen handle SFINAE?

@emilio
Copy link
Contributor Author

emilio commented Aug 25, 2016

@fitzgen nope, for obvious reasons, sorry, forgot to mention it.

@emilio
Copy link
Contributor Author

emilio commented Sep 22, 2016

The template unions with template parameters thing should be doable once #61 lands.

@gsingh93
Copy link

gsingh93 commented Feb 7, 2017

I'm a bit surprised bindgen can't handle this:

$ cat test.h
template <typename T>
void foo(T a);
$ bindgen --version
bindgen 0.21.2
$ bindgen test.h -- -x c++
ERROR:bindgen::ir::item: Unhandled cursor kind CXCursorKind(30): Cursor(foo kind: FunctionTemplate, loc: test.h:2:6, usr: Some("c:@FT@>1#Tfoo#t0.0#v#"))
/* automatically generated by rust-bindgen */

Is this expected? It's not any fancy specialization, just a normal templated function.

@fitzgen
Copy link
Member

fitzgen commented Feb 7, 2017

@gsingh93

We can't invoke the C++ compiler to generate new instantiations of templates, so I don't think we even try to keep track of them currently.

Perhaps we could track explicit instantiations of template functions (14.7.2 in the standard) and make bindings to those.

For example, if given

template<class T> void foo(T t) { /∗ ... ∗/ }
template void foo(char);
template void foo(int);

We could generate something like:

extern "C" {
    #[link_name = "..."]
    pub fn foo_char(char);

    #[link_name = "..."]
    pub fn foo_int(int);
}

But either way, we can't create new template instantiations since we aren't a C++ compiler and aren't creatign new object files from C++ code, so without those explicit instantiations to help us know what already exists, I don't think we can do much else.

@fitzgen
Copy link
Member

fitzgen commented Feb 7, 2017

Filed #492 for tracking explicit instantiations of template functions and generating bindings for them.

@fitzgen fitzgen changed the title Things we can't handle right now. [meta] C++ features we can't handle right now. Jul 21, 2017
@fitzgen fitzgen added the meta label Aug 1, 2017
@fitzgen fitzgen changed the title [meta] C++ features we can't handle right now. C++ features we can't handle right now. Aug 1, 2017
@tamird
Copy link
Contributor

tamird commented Sep 13, 2017

Just hit this while trying to work on #492.

Here's the output, in case anyone finds it helpful: https://gist.github.com/anonymous/d20daf345e3b7512061c719e15684bb9.

Note that it includes the Unhandled cursor kind 30: Cursor(__test kind: FunctionTemplate bit tracked in #492, but also includes a bunch of Unhandled cursor kind 21: Cursor(__on_zero_shared kind: CXXMethod.

EDIT: also featured is Unhandled cursor kind 24: Cursor(shared_ptr<_Tp> kind: CXXConstructor.

@pvdrz
Copy link
Contributor

pvdrz commented Sep 15, 2022

I propose closing this issue and maybe opening tracking issue listing all the other issues related to C++ features. What do you way?

@pvdrz
Copy link
Contributor

pvdrz commented Nov 11, 2022

superseded by #2343

@pvdrz pvdrz closed this as not planned Won't fix, can't repro, duplicate, stale Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants