[clang] 5c4dbff - [clang][Interp] Handle SubstNonTypeTemplateParmExprs
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 7 22:31:53 PDT 2022
Author: Timm Bäder
Date: 2022-09-08T07:31:07+02:00
New Revision: 5c4dbff0b6c3943dfbcba930986e23e015df97c5
URL: https://github.com/llvm/llvm-project/commit/5c4dbff0b6c3943dfbcba930986e23e015df97c5
DIFF: https://github.com/llvm/llvm-project/commit/5c4dbff0b6c3943dfbcba930986e23e015df97c5.diff
LOG: [clang][Interp] Handle SubstNonTypeTemplateParmExprs
Differential Revision: https://reviews.llvm.org/D132831
Added:
Modified:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/test/AST/Interp/functions.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index a6fea951f759..f9dac9a21978 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -231,6 +231,12 @@ bool ByteCodeExprGen<Emitter>::VisitImplicitValueInitExpr(const ImplicitValueIni
return false;
}
+template <class Emitter>
+bool ByteCodeExprGen<Emitter>::VisitSubstNonTypeTemplateParmExpr(
+ const SubstNonTypeTemplateParmExpr *E) {
+ return this->visit(E->getReplacement());
+}
+
template <class Emitter>
bool ByteCodeExprGen<Emitter>::discard(const Expr *E) {
OptionScope<Emitter> Scope(this, /*NewDiscardResult=*/true);
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 6793cdffecee..6132e2b67435 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -76,6 +76,7 @@ class ByteCodeExprGen : public ConstStmtVisitor<ByteCodeExprGen<Emitter>, bool>,
bool VisitUnaryOperator(const UnaryOperator *E);
bool VisitDeclRefExpr(const DeclRefExpr *E);
bool VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E);
+ bool VisitSubstNonTypeTemplateParmExpr(const SubstNonTypeTemplateParmExpr *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 a0e0a14a03c9..494133c10cb1 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -65,3 +65,11 @@ constexpr int recursion(int i) {
return recursion(i);
}
static_assert(recursion(10) == 0, "");
+
+template<int N = 5>
+constexpr decltype(N) getNum() {
+ return N;
+}
+static_assert(getNum<-2>() == -2, "");
+static_assert(getNum<10>() == 10, "");
+static_assert(getNum() == 5, "");
More information about the cfe-commits
mailing list