[cfe-commits] r151707 - in /cfe/trunk: lib/Sema/SemaExpr.cpp lib/Sema/TreeTransform.h test/SemaTemplate/instantiate-sizeof.cpp test/SemaTemplate/instantiate-typeof.cpp

Eli Friedman eli.friedman at gmail.com
Tue Feb 28 20:03:56 PST 2012


Author: efriedma
Date: Tue Feb 28 22:03:55 2012
New Revision: 151707

URL: http://llvm.org/viewvc/llvm-project?rev=151707&view=rev
Log:
A couple minor bug-fixes for template instantiation for expressions which are sometimes potentially evaluated.


Added:
    cfe/trunk/test/SemaTemplate/instantiate-sizeof.cpp
    cfe/trunk/test/SemaTemplate/instantiate-typeof.cpp
Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/TreeTransform.h

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=151707&r1=151706&r2=151707&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Feb 28 22:03:55 2012
@@ -9308,6 +9308,8 @@
 }
 
 ExprResult Sema::TranformToPotentiallyEvaluated(Expr *E) {
+  assert(ExprEvalContexts.back().Context == Unevaluated &&
+         "Should only transform unevaluated expressions");
   ExprEvalContexts.back().Context =
       ExprEvalContexts[ExprEvalContexts.size()-2].Context;
   if (ExprEvalContexts.back().Context == Unevaluated)

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=151707&r1=151706&r2=151707&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Tue Feb 28 22:03:55 2012
@@ -4274,6 +4274,10 @@
   if (E.isInvalid())
     return QualType();
 
+  E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
+  if (E.isInvalid())
+    return QualType();
+
   QualType Result = TL.getType();
   if (getDerived().AlwaysRebuild() ||
       E.get() != TL.getUnderlyingExpr()) {
@@ -6234,20 +6238,17 @@
                                                     E->getSourceRange());
   }
 
-  ExprResult SubExpr;
-  {
-    // C++0x [expr.sizeof]p1:
-    //   The operand is either an expression, which is an unevaluated operand
-    //   [...]
-    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
+  // C++0x [expr.sizeof]p1:
+  //   The operand is either an expression, which is an unevaluated operand
+  //   [...]
+  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
 
-    SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
-    if (SubExpr.isInvalid())
-      return ExprError();
+  ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
+  if (SubExpr.isInvalid())
+    return ExprError();
 
-    if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
-      return SemaRef.Owned(E);
-  }
+  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
+    return SemaRef.Owned(E);
 
   return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
                                                   E->getOperatorLoc(),

Added: cfe/trunk/test/SemaTemplate/instantiate-sizeof.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-sizeof.cpp?rev=151707&view=auto
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-sizeof.cpp (added)
+++ cfe/trunk/test/SemaTemplate/instantiate-sizeof.cpp Tue Feb 28 22:03:55 2012
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+// Make sure we handle contexts correctly with sizeof
+template<typename T> void f(T n) {
+  int buffer[n];
+  [] { int x = sizeof(sizeof(buffer)); }();
+}
+int main() {
+  f<int>(1);
+}

Added: cfe/trunk/test/SemaTemplate/instantiate-typeof.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-typeof.cpp?rev=151707&view=auto
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-typeof.cpp (added)
+++ cfe/trunk/test/SemaTemplate/instantiate-typeof.cpp Tue Feb 28 22:03:55 2012
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+// Make sure we correctly treat __typeof as potentially-evaluated when appropriate
+template<typename T> void f(T n) {
+  int buffer[n]; // expected-note {{declared here}}
+  [] { __typeof(buffer) x; }(); // expected-error {{variable 'buffer' with variably modified type cannot be captured in a lambda expression}}
+}
+int main() {
+  f<int>(1); // expected-note {{in instantiation}}
+}





More information about the cfe-commits mailing list