Skip to content

Commit 5c4dbff

Browse files
committed
[clang][Interp] Handle SubstNonTypeTemplateParmExprs
Differential Revision: https://reviews.llvm.org/D132831
1 parent 4d700ff commit 5c4dbff

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ bool ByteCodeExprGen<Emitter>::VisitImplicitValueInitExpr(const ImplicitValueIni
231231
return false;
232232
}
233233

234+
template <class Emitter>
235+
bool ByteCodeExprGen<Emitter>::VisitSubstNonTypeTemplateParmExpr(
236+
const SubstNonTypeTemplateParmExpr *E) {
237+
return this->visit(E->getReplacement());
238+
}
239+
234240
template <class Emitter>
235241
bool ByteCodeExprGen<Emitter>::discard(const Expr *E) {
236242
OptionScope<Emitter> Scope(this, /*NewDiscardResult=*/true);

clang/lib/AST/Interp/ByteCodeExprGen.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class ByteCodeExprGen : public ConstStmtVisitor<ByteCodeExprGen<Emitter>, bool>,
7676
bool VisitUnaryOperator(const UnaryOperator *E);
7777
bool VisitDeclRefExpr(const DeclRefExpr *E);
7878
bool VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E);
79+
bool VisitSubstNonTypeTemplateParmExpr(const SubstNonTypeTemplateParmExpr *E);
7980

8081
protected:
8182
bool visitExpr(const Expr *E) override;

clang/test/AST/Interp/functions.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,11 @@ constexpr int recursion(int i) {
6565
return recursion(i);
6666
}
6767
static_assert(recursion(10) == 0, "");
68+
69+
template<int N = 5>
70+
constexpr decltype(N) getNum() {
71+
return N;
72+
}
73+
static_assert(getNum<-2>() == -2, "");
74+
static_assert(getNum<10>() == 10, "");
75+
static_assert(getNum() == 5, "");

0 commit comments

Comments
 (0)