From: Richard Smith Date: Thu, 26 Jan 2012 04:47:34 +0000 (+0000) Subject: constexpr: evaluate (bool)&x as true when x is a local variable or a temporary. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f2e4cd760a5836ee8941d1b9be6b2e2c2dde23e6;p=clang constexpr: evaluate (bool)&x as true when x is a local variable or a temporary. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149045 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 1c0d9eae69..6a292c3925 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -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; diff --git a/test/Sema/const-eval.c b/test/Sema/const-eval.c index a40039bdc5..22ac67adad 100644 --- a/test/Sema/const-eval.c +++ b/test/Sema/const-eval.c @@ -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. diff --git a/test/SemaCXX/constant-expression-cxx11.cpp b/test/SemaCXX/constant-expression-cxx11.cpp index af66acda0a..3c85adcc18 100644 --- a/test/SemaCXX/constant-expression-cxx11.cpp +++ b/test/SemaCXX/constant-expression-cxx11.cpp @@ -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 {