Index: include/clang/AST/Expr.h =================================================================== --- include/clang/AST/Expr.h +++ include/clang/AST/Expr.h @@ -2852,6 +2852,15 @@ return const_cast(this)->getSubExprAsWritten(); } + /// There are two global types of casts - implicit and explicit. An explicit + /// cast corresponds to a cast written in the source code, while an implicit + /// cast is materialized for the purposes of automatic conversions. + /// But in AST, some explicit casts are represented as ExplicitCastExpr plus + /// one or more immediate ImplicitCastExpr (i.e. with nothing inbetween). + /// This function returns false if this cast is either an ExplicitCastExpr + /// itself, or it is a part of the ExplicitCastExpr group. + bool isActuallyImplicitCast() const; + /// If this cast applies a user-defined conversion, retrieve the conversion /// function that it invokes. NamedDecl *getConversionFunction() const; @@ -3009,6 +3018,13 @@ } }; +inline bool CastExpr::isActuallyImplicitCast() const { + if (auto *IC = dyn_cast(this)) + return !IC->getIsPartOfExplicitCast(); + assert(isa(this) && "it has to be Explicit cast then."); + return false; // Explicit cast is clearly not an Implicit cast. +} + /// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style /// cast in C++ (C++ [expr.cast]), which uses the syntax /// (Type)expr. For example: @c (int)f.