[cfe-users] Checking if a class can be copy constructed

Luke Zhou via cfe-users cfe-users at lists.llvm.org
Wed Dec 11 12:47:28 PST 2019


Hello,


I’ve been trying to do some code generation using clang (not libclang), and
want to find out if a class can be copy constructed.


I’ve tried testing if the copy constructor is deleted, but this does not
work well with templates. For example, I have a class that contains a
std::vector<std::unique_ptr>, whose copy constructor will apparently fail
to instantiate, but doesn’t cause the copy constructors of std::vector or
my class to be marked as deleted. Also, isInvalidDecl() returns false,
which (I think) means that the compiler didn’t even attempt to instantiate
the constructor as it has never been used.


I believe that my best bet is to try to manually check if the constructor
can instantiate. I’ve looked at clang::Sema, but was overwhelmed by the
large amount of functions. I also noticed that a lot of these functions
seem to have side effects, which is undesired since I do not want this
check to cause other parts of the code to not compile.


Am I on the right path? If so, which functions in clang::Sema should I use,
and how? If not, is there a better way?


Thank you very much.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20191211/ffbd2275/attachment.html>


More information about the cfe-users mailing list