The value of a case statement is a potentially evaluated context. Found by inspection.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148373 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h
index 4908e88..58c690d 100644
--- a/lib/Sema/TreeTransform.h
+++ b/lib/Sema/TreeTransform.h
@@ -4984,8 +4984,8 @@
TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
ExprResult LHS, RHS;
{
- // The case value expressions are not potentially evaluated.
- EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
+ EnterExpressionEvaluationContext Unevaluated(SemaRef,
+ Sema::ConstantEvaluated);
// Transform the left-hand case value.
LHS = getDerived().TransformExpr(S->getLHS());
diff --git a/test/SemaCXX/constant-expression-cxx11.cpp b/test/SemaCXX/constant-expression-cxx11.cpp
index 3736685..5ccb398 100644
--- a/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1022,3 +1022,9 @@
typedef _Complex float fcomplex;
constexpr fcomplex test7 = fcomplex();
}
+
+namespace InstantiateCaseStmt {
+ template<int x> constexpr int f() { return x; }
+ template<int x> int g(int c) { switch(c) { case f<x>(): return 1; } return 0; }
+ int gg(int c) { return g<4>(c); }
+}