Search code examples
c++clanglibtooling

Testing if class is copy constructable using libtooling


I would like to use libtooling to test whether the defined by a CXXRecordDecl is copy constructable.

I have already tried :

  • hasCopyConstructorWithConstParam()
  • hasTrivialCopyConstructor() || hasNonTrivialCopyConstructor()

Unfortunately, both of those expressions return true if the class's copy constructor is implicitly deleted. This can occur if the class inherits from a non-copyable class or has a member variable that is non-copyable.

The logic to test whether a class is copy constructable is non-trivial and must be exist somewhere in clang. How can I test if a class is copy constructable with libtooling?


Solution

  • Turn comment into answer:

    You can retrieve the constructor with CXXRecordDecl::ctor_begin

    and check CXXConstructorDecl::isDeleted().