]> granicus.if.org Git - clang/commitdiff
constexpr: evaluate (bool)&x as true when x is a local variable or a temporary.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 26 Jan 2012 04:47:34 +0000 (04:47 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 26 Jan 2012 04:47:34 +0000 (04:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149045 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 1c0d9eae69f5f3c1ed13792eec8cd690839263f6..6a292c392510210ac7161a688716946b0bfce02a 100644 (file)
@@ -950,10 +950,6 @@ static bool EvalPointerValueAsBool(const CCValue &Value, bool &Result) {
     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;
index a40039bdc5bd61f0c8b24bb0abfb40633104b969..22ac67adad99fcf415c726a6d04a54272dfcb380 100644 (file)
@@ -24,7 +24,7 @@ EVAL_EXPR(14, (1 ^ l_19) && 1); // expected-error {{fields must have a constant
 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.
index af66acda0a357226c0e2898bd18df80ddad17fe3..3c85adcc1893644f9c9d42667fbfb837af5b0218 100644 (file)
@@ -737,6 +737,9 @@ constexpr int f(const S &s) {
 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 {