]> granicus.if.org Git - clang/commitdiff
The sub-statement of a case statement is not an unevaluated context!
authorEli Friedman <eli.friedman@gmail.com>
Thu, 19 Nov 2009 03:14:00 +0000 (03:14 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Thu, 19 Nov 2009 03:14:00 +0000 (03:14 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89303 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/TreeTransform.h
test/SemaTemplate/instantiate-case.cpp [new file with mode: 0644]

index 2bee32aa0fc8f3a4ae8ff90bc07f4f06781d1be3..ca680c279bdba34b064f65d8661a657a5d51a7dc 100644 (file)
@@ -3037,18 +3037,21 @@ TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
 template<typename Derived>
 Sema::OwningStmtResult
 TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
-  // The case value expressions are not potentially evaluated.
-  EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
+  OwningExprResult LHS(SemaRef), RHS(SemaRef);
+  {
+    // The case value expressions are not potentially evaluated.
+    EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
 
-  // Transform the left-hand case value.
-  OwningExprResult LHS = getDerived().TransformExpr(S->getLHS());
-  if (LHS.isInvalid())
-    return SemaRef.StmtError();
+    // Transform the left-hand case value.
+    LHS = getDerived().TransformExpr(S->getLHS());
+    if (LHS.isInvalid())
+      return SemaRef.StmtError();
 
-  // Transform the right-hand case value (for the GNU case-range extension).
-  OwningExprResult RHS = getDerived().TransformExpr(S->getRHS());
-  if (RHS.isInvalid())
-    return SemaRef.StmtError();
+    // Transform the right-hand case value (for the GNU case-range extension).
+    RHS = getDerived().TransformExpr(S->getRHS());
+    if (RHS.isInvalid())
+      return SemaRef.StmtError();
+  }
 
   // Build the case statement.
   // Case statements are always rebuilt so that they will attached to their
diff --git a/test/SemaTemplate/instantiate-case.cpp b/test/SemaTemplate/instantiate-case.cpp
new file mode 100644 (file)
index 0000000..bed39d7
--- /dev/null
@@ -0,0 +1,21 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+template<class T>
+static int alpha(T c)
+{
+    return *c; // expected-error{{indirection requires pointer operand}}
+}
+
+template<class T>
+static void
+_shexp_match()
+{
+  switch(1) {
+  case 1:
+    alpha(1); // expected-note{{instantiation of function template}}
+  }
+}
+int main() {
+  _shexp_match<char>(); // expected-note{{instantiation of function template}}
+  return 0;
+}