diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 15a71708966033..c8d3c1243fc109 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1624,6 +1624,11 @@ bool ByteCodeExprGen::VisitCXXScalarValueInitExpr( return this->visitZeroInitializer(classifyPrim(Ty), Ty, E); } +template +bool ByteCodeExprGen::VisitSizeOfPackExpr(const SizeOfPackExpr *E) { + return this->emitConst(E->getPackLength(), E); +} + template bool ByteCodeExprGen::discard(const Expr *E) { if (E->containsErrors()) return false; diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h b/clang/lib/AST/Interp/ByteCodeExprGen.h index 83986d3dd579ed..ec9b6bb1408453 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.h +++ b/clang/lib/AST/Interp/ByteCodeExprGen.h @@ -107,6 +107,7 @@ class ByteCodeExprGen : public ConstStmtVisitor, bool>, bool VisitSourceLocExpr(const SourceLocExpr *E); bool VisitOffsetOfExpr(const OffsetOfExpr *E); bool VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E); + bool VisitSizeOfPackExpr(const SizeOfPackExpr *E); protected: bool visitExpr(const Expr *E) override; diff --git a/clang/test/AST/Interp/functions.cpp b/clang/test/AST/Interp/functions.cpp index 4bef9c2f7c0d1f..ab562e70606b67 100644 --- a/clang/test/AST/Interp/functions.cpp +++ b/clang/test/AST/Interp/functions.cpp @@ -371,3 +371,10 @@ namespace Variadic { constexpr int (*VFP)(...) = variadic_function2; static_assert(VFP() == 12, ""); } + +namespace Packs { + template + constexpr int foo() { return sizeof...(T); } + static_assert(foo() == 2, ""); + static_assert(foo<>() == 0, ""); +}