[cfe-commits] r149045 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/Sema/const-eval.c test/SemaCXX/constant-expression-cxx11.cpp

Richard Smith richard-llvm at metafoo.co.uk
Wed Jan 25 20:47:34 PST 2012


Author: rsmith
Date: Wed Jan 25 22:47:34 2012
New Revision: 149045

URL: http://llvm.org/viewvc/llvm-project?rev=149045&view=rev
Log:
constexpr: evaluate (bool)&x as true when x is a local variable or a temporary.

Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp
    cfe/trunk/test/Sema/const-eval.c
    cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=149045&r1=149044&r2=149045&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Wed Jan 25 22:47:34 2012
@@ -950,10 +950,6 @@
     return true;
   }
 
-  // Require the base expression to be a global l-value.
-  // FIXME: C++11 requires such conversions. Remove this check.
-  if (!IsGlobalLValue(Value.getLValueBase())) return false;
-
   // We have a non-null base.  These are generally known to be true, but if it's
   // a weak declaration it can be null at runtime.
   Result = true;

Modified: cfe/trunk/test/Sema/const-eval.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/const-eval.c?rev=149045&r1=149044&r2=149045&view=diff
==============================================================================
--- cfe/trunk/test/Sema/const-eval.c (original)
+++ cfe/trunk/test/Sema/const-eval.c Wed Jan 25 22:47:34 2012
@@ -24,7 +24,7 @@
 void f()
 {
   int a;
-  EVAL_EXPR(15, (_Bool)&a); // expected-error {{fields must have a constant size}}
+  EVAL_EXPR(15, (_Bool)&a);
 }
 
 // FIXME: Turn into EVAL_EXPR test once we have more folding.

Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=149045&r1=149044&r2=149045&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Wed Jan 25 22:47:34 2012
@@ -737,6 +737,9 @@
 constexpr int n = f(T(5));
 static_assert(f(T(5)) == 5, "");
 
+constexpr bool b(int n) { return &n; }
+static_assert(b(0), "");
+
 }
 
 namespace Union {





More information about the cfe-commits mailing list