Papierkorb / bindgen

Binding and wrapper generator for C/C++ libraries
GNU General Public License v3.0
179 stars 18 forks source link

DefaultConstructor: more robust detection of default-constructible types #91

Closed HertzDevil closed 3 years ago

HertzDevil commented 3 years ago

Currently the DefaultConstructor processor checks for private default constructors, but misses out other situations where the default ctor would be deleted (= delete, const / reference data member etc.), and Clang doesn't report these cases either. This patch fixes it by using std::is_default_constructible itself to check whether a given type is default-constructible. The steps are:

For example, the temporary file for basic_spec.cpp will look like:

#include "basic.cpp"
#include "/.../assets/parser_helper.hpp"
template class BindgenTypeInfo<Adder>;
template class BindgenTypeInfo<ImplicitConstructor>;
template class BindgenTypeInfo<PrivateConstructor>;
template class BindgenTypeInfo<DeletedConstructor>;
template class BindgenTypeInfo<TypeConversion>;

This avoids the need to reimplement default ctor detection on the Crystal side (not even private ctor checking). The same technique may be used to check for other C++ compile-time properties inside BindgenTypeInfo.

This PR also ensures that methods marked with = delete are not generated by the Clang parser, as otherwise classes with explicitly deleted ctors will still have those ctors wrapped.

Papierkorb commented 3 years ago

I was sure that this worked at some point. But then, I'm amazed that the Clang parser part works with so many Clang versions without too many ifdefs. Wouldn't surprise me if Clang just broke it on their end like they like to do.

Thanks for the patch!