Skip to content

Commit

Permalink
[clang][Interp] Handle ArrayTypeTraitExprs
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaederr committed Mar 16, 2024
1 parent 367f355 commit 8e69052
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1755,6 +1755,14 @@ bool ByteCodeExprGen<Emitter>::VisitTypeTraitExpr(const TypeTraitExpr *E) {
return this->emitConst(E->getValue(), E);
}

template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitArrayTypeTraitExpr(
const ArrayTypeTraitExpr *E) {
if (DiscardResult)
return true;
return this->emitConst(E->getValue(), E);
}

template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitLambdaExpr(const LambdaExpr *E) {
if (DiscardResult)
Expand Down
1 change: 1 addition & 0 deletions clang/lib/AST/Interp/ByteCodeExprGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class ByteCodeExprGen : public ConstStmtVisitor<ByteCodeExprGen<Emitter>, bool>,
bool VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E);
bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E);
bool VisitTypeTraitExpr(const TypeTraitExpr *E);
bool VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E);
bool VisitLambdaExpr(const LambdaExpr *E);
bool VisitPredefinedExpr(const PredefinedExpr *E);
bool VisitCXXThrowExpr(const CXXThrowExpr *E);
Expand Down
12 changes: 12 additions & 0 deletions clang/test/AST/Interp/literals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,18 @@ namespace TypeTraits {
struct U {};
static_assert(S3<U>{}.foo(), "");
static_assert(!S3<T>{}.foo(), "");

typedef int Int;
typedef Int IntAr[10];
typedef const IntAr ConstIntAr;
typedef ConstIntAr ConstIntArAr[4];

static_assert(__array_rank(IntAr) == 1, "");
static_assert(__array_rank(ConstIntArAr) == 2, "");

static_assert(__array_extent(IntAr, 0) == 10, "");
static_assert(__array_extent(ConstIntArAr, 0) == 4, "");
static_assert(__array_extent(ConstIntArAr, 1) == 10, "");
}

#if __cplusplus >= 201402L
Expand Down

0 comments on commit 8e69052

Please sign in to comment.