[cfe-dev] How to tell whether two TypeDecls are implicit convertible to each other?
Ray Zhang via cfe-dev
cfe-dev at lists.llvm.org
Thu Jun 11 23:59:18 PDT 2020
Hi,
I'm trying to contribute the C++ cast conversion tool for clang-tools-extra
and I was wondering whether there's any way to tell whether two types are
implicitly convertible to each other. The reason is because we want to
convert the C-style cast to static_cast if it's implicitly convertible, and
otherwise we fall-through to use reinterpret_cast.
In order to safely change C-style casts to static_cast, we want to be able
to tell whether two types are convertible to each other. Even if we
hardcode implicit convertibility with built-in types, In the case of
CXXRecordDecls it may be especially difficult because of user-defined cast
operators within the class/struct.
It might be that I overlooked some part of the documentation on this, but
it seems like a difficult problem. It might be that clang as a compiler has
the logic somewhere for deciding implicit convertibility, and if so could
anyone point me to the source? If not, I was thinking of transforming all
C-style casts into static_casts on the first pass, and upon failure on
building the AST, transforming broken static_casts into reinterpret_casts
on the second pass. I'm not sure if this idea will work.
Any suggestions would be greatly appreciated.
Best,
Ray
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200611/d2384aec/attachment.html>
More information about the cfe-dev
mailing list