Skip to content

Commit 8e69052

Browse files
committed
[clang][Interp] Handle ArrayTypeTraitExprs
1 parent 367f355 commit 8e69052

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,6 +1755,14 @@ bool ByteCodeExprGen<Emitter>::VisitTypeTraitExpr(const TypeTraitExpr *E) {
17551755
return this->emitConst(E->getValue(), E);
17561756
}
17571757

1758+
template <class Emitter>
1759+
bool ByteCodeExprGen<Emitter>::VisitArrayTypeTraitExpr(
1760+
const ArrayTypeTraitExpr *E) {
1761+
if (DiscardResult)
1762+
return true;
1763+
return this->emitConst(E->getValue(), E);
1764+
}
1765+
17581766
template <class Emitter>
17591767
bool ByteCodeExprGen<Emitter>::VisitLambdaExpr(const LambdaExpr *E) {
17601768
if (DiscardResult)

clang/lib/AST/Interp/ByteCodeExprGen.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class ByteCodeExprGen : public ConstStmtVisitor<ByteCodeExprGen<Emitter>, bool>,
9999
bool VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E);
100100
bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E);
101101
bool VisitTypeTraitExpr(const TypeTraitExpr *E);
102+
bool VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E);
102103
bool VisitLambdaExpr(const LambdaExpr *E);
103104
bool VisitPredefinedExpr(const PredefinedExpr *E);
104105
bool VisitCXXThrowExpr(const CXXThrowExpr *E);

clang/test/AST/Interp/literals.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,18 @@ namespace TypeTraits {
910910
struct U {};
911911
static_assert(S3<U>{}.foo(), "");
912912
static_assert(!S3<T>{}.foo(), "");
913+
914+
typedef int Int;
915+
typedef Int IntAr[10];
916+
typedef const IntAr ConstIntAr;
917+
typedef ConstIntAr ConstIntArAr[4];
918+
919+
static_assert(__array_rank(IntAr) == 1, "");
920+
static_assert(__array_rank(ConstIntArAr) == 2, "");
921+
922+
static_assert(__array_extent(IntAr, 0) == 10, "");
923+
static_assert(__array_extent(ConstIntArAr, 0) == 4, "");
924+
static_assert(__array_extent(ConstIntArAr, 1) == 10, "");
913925
}
914926

915927
#if __cplusplus >= 201402L

0 commit comments

Comments
 (0)