The X: Trying to write an internal clang tidy tool that finds an expression that contains two types (A
, B
) and then throws if const A&
is implicitly convertible to B
?
Given I can find two CXXRecordDecl
for the classes, can I easily detect if A
is implicitly convertible to B
?
I've thought of walking over the constructors but that won't cover if B provides casting operators. I could walk over them both but I'm sure there are more cases that I'm missing here (like externally defined casting operators). Basically I want to detect if std::is_convertible<const B&, A>::value
would return true, something every compiler has to do when validating a cast, but very difficult for a human to write...
std::is_convertible<const B&, A>::value
would return true. – ClairclairaudienceA
could be converted toB
, though operators, and such, you are going to have to make your ownis_convertible
, which looks into the class defs for those operators. – ImportanceCXXRecordDecl
), cast (using conversion_begin(), conversion_end() ofCXXRecordDecl
) and constructors (using ctor_begin(), conversion_end() ofCXXRecordDecl
). Don't you think it is sufficient ? – Standup