From: Eli Friedman Date: Wed, 18 Jan 2012 02:54:10 +0000 (+0000) Subject: The value of a case statement is a potentially evaluated context. Found by inspection. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6b3014b07c40a6ed8b0c8ed63950df02eeb82c28;p=clang 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 4908e883b8..58c690d49f 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -4984,8 +4984,8 @@ StmtResult TreeTransform::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 3736685d43..5ccb398c32 100644 --- a/test/SemaCXX/constant-expression-cxx11.cpp +++ b/test/SemaCXX/constant-expression-cxx11.cpp @@ -1022,3 +1022,9 @@ namespace ComplexConstexpr { typedef _Complex float fcomplex; constexpr fcomplex test7 = fcomplex(); } + +namespace InstantiateCaseStmt { + template constexpr int f() { return x; } + template int g(int c) { switch(c) { case f(): return 1; } return 0; } + int gg(int c) { return g<4>(c); } +}