5151#include < cstdint>
5252#include < memory>
5353#include < optional>
54+ #include < variant>
5455
5556namespace clang {
5657
@@ -2765,27 +2766,27 @@ class CXXPseudoDestructorExpr : public Expr {
27652766// / \endcode
27662767class TypeTraitExpr final
27672768 : public Expr,
2768- private llvm::TrailingObjects<TypeTraitExpr, TypeSourceInfo *> {
2769+ private llvm::TrailingObjects<TypeTraitExpr, APValue, TypeSourceInfo *> {
27692770 // / The location of the type trait keyword.
27702771 SourceLocation Loc;
27712772
27722773 // / The location of the closing parenthesis.
27732774 SourceLocation RParenLoc;
27742775
2775- // Note: The TypeSourceInfos for the arguments are allocated after the
2776- // TypeTraitExpr.
2777-
27782776 TypeTraitExpr (QualType T, SourceLocation Loc, TypeTrait Kind,
2779- ArrayRef<TypeSourceInfo *> Args,
2780- SourceLocation RParenLoc,
2781- bool Value);
2777+ ArrayRef<TypeSourceInfo *> Args, SourceLocation RParenLoc,
2778+ std::variant<bool , APValue> Value);
27822779
27832780 TypeTraitExpr (EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) {}
27842781
27852782 size_t numTrailingObjects (OverloadToken<TypeSourceInfo *>) const {
27862783 return getNumArgs ();
27872784 }
27882785
2786+ size_t numTrailingObjects (OverloadToken<APValue>) const {
2787+ return TypeTraitExprBits.IsBooleanTypeTrait ? 0 : 1 ;
2788+ }
2789+
27892790public:
27902791 friend class ASTStmtReader ;
27912792 friend class ASTStmtWriter ;
@@ -2798,19 +2799,34 @@ class TypeTraitExpr final
27982799 SourceLocation RParenLoc,
27992800 bool Value);
28002801
2802+ static TypeTraitExpr *Create (const ASTContext &C, QualType T,
2803+ SourceLocation Loc, TypeTrait Kind,
2804+ ArrayRef<TypeSourceInfo *> Args,
2805+ SourceLocation RParenLoc, APValue Value);
2806+
28012807 static TypeTraitExpr *CreateDeserialized (const ASTContext &C,
2808+ bool IsStoredAsBool,
28022809 unsigned NumArgs);
28032810
28042811 // / Determine which type trait this expression uses.
28052812 TypeTrait getTrait () const {
28062813 return static_cast <TypeTrait>(TypeTraitExprBits.Kind );
28072814 }
28082815
2809- bool getValue () const {
2810- assert (!isValueDependent ());
2816+ bool isStoredAsBoolean () const {
2817+ return TypeTraitExprBits.IsBooleanTypeTrait ;
2818+ }
2819+
2820+ bool getBoolValue () const {
2821+ assert (!isValueDependent () && TypeTraitExprBits.IsBooleanTypeTrait );
28112822 return TypeTraitExprBits.Value ;
28122823 }
28132824
2825+ const APValue &getAPValue () const {
2826+ assert (!isValueDependent () && !TypeTraitExprBits.IsBooleanTypeTrait );
2827+ return *getTrailingObjects<APValue>();
2828+ }
2829+
28142830 // / Determine the number of arguments to this type trait.
28152831 unsigned getNumArgs () const { return TypeTraitExprBits.NumArgs ; }
28162832
0 commit comments