How to tell that class/struct is copyable using python bindings for clang tooling

223 views Asked by At

Our project is using clang python api to generate python bindings for C++ classes. Right now we have a limitation that the copy will only be exposed if a type has an explicitly defined copy constructor.

I would like to change it to also declare a copy for a generated copy constructor - so I need to detect that somehow.

All the structs I care about are trivially copyable, so if I can only detect trivially copyable ones that is fine as well.

How could I tell that a struct I am at is copyable or trivially copyable? I have CursorKind.STRUCT_DECL as my starting point.

1

There are 1 answers

0
Denis Yaroshevskiy On BEST ANSWER

This is what we ended up with.

a) Seems like from clang ast directly you can only ask if 'is_pod' cindex.py

Not quite what I need since pod also implies no default constructor accroding to this std::is_pod std::is_trivial.

b) What we did is:

  1. include the original file in a different tmp file that we generate and parse that.
  2. in that file generate a specially named enum <ClassName>_Traits with std::is_copy_constructible for a class of interest.