diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-02-14 22:35:28 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-02-14 22:35:28 +0000 |
commit | ab44d9b321269d3bd77bd1068e25edd7df9b6bd7 (patch) | |
tree | 64223c43b1005993a7fa620106b53ef3504280c1 | |
parent | 5b9c3974d280c1d8a186d6e5b8c2ea810db6ea4d (diff) | |
download | bcm5719-llvm-ab44d9b321269d3bd77bd1068e25edd7df9b6bd7.tar.gz bcm5719-llvm-ab44d9b321269d3bd77bd1068e25edd7df9b6bd7.zip |
constexpr: evaluation support for nullptr comparisons.
llvm-svn: 150521
-rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 10 | ||||
-rw-r--r-- | clang/test/SemaCXX/nullptr.cpp | 17 |
2 files changed, 24 insertions, 3 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 787e722a7cb..e33ca6dc650 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -4612,6 +4612,16 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) { return Success(E->getOpcode() == BO_EQ ? Equal : !Equal, E); } + if (LHSTy->isNullPtrType()) { + assert(E->isComparisonOp() && "unexpected nullptr operation"); + assert(RHSTy->isNullPtrType() && "missing pointer conversion"); + // C++11 [expr.rel]p4, [expr.eq]p3: If two operands of type std::nullptr_t + // are compared, the result is true of the operator is <=, >= or ==, and + // false otherwise. + BinaryOperator::Opcode Opcode = E->getOpcode(); + return Success(Opcode == BO_EQ || Opcode == BO_LE || Opcode == BO_GE, E); + } + if (!LHSTy->isIntegralOrEnumerationType() || !RHSTy->isIntegralOrEnumerationType()) { // We can't continue from here for non-integral types. diff --git a/clang/test/SemaCXX/nullptr.cpp b/clang/test/SemaCXX/nullptr.cpp index 0e6771b57fc..91757cf51ed 100644 --- a/clang/test/SemaCXX/nullptr.cpp +++ b/clang/test/SemaCXX/nullptr.cpp @@ -113,15 +113,26 @@ int array0[__is_scalar(nullptr_t)? 1 : -1]; int array1[__is_pod(nullptr_t)? 1 : -1]; int array2[sizeof(nullptr_t) == sizeof(void*)? 1 : -1]; -// FIXME: when we implement constexpr, this will be testable. -#if 0 int relational0[nullptr < nullptr? -1 : 1]; int relational1[nullptr > nullptr? -1 : 1]; int relational2[nullptr <= nullptr? 1 : -1]; int relational3[nullptr >= nullptr? 1 : -1]; int equality[nullptr == nullptr? 1 : -1]; int inequality[nullptr != nullptr? -1 : 1]; -#endif + +int relational0_a[0 < nullptr? -1 : 1]; +int relational1_a[0 > nullptr? -1 : 1]; +int relational2_a[0 <= nullptr? 1 : -1]; +int relational3_a[0 >= nullptr? 1 : -1]; +int equality_a[0 == nullptr? 1 : -1]; +int inequality_a[0 != nullptr? -1 : 1]; + +int relationalnullptr_b[nullptr < 0? -1 : 1]; +int relational1_b[nullptr > 0? -1 : 1]; +int relational2_b[nullptr <= 0? 1 : -1]; +int relational3_b[nullptr >= 0? 1 : -1]; +int equality_b[nullptr == 0? 1 : -1]; +int inequality_b[nullptr != 0? -1 : 1]; namespace overloading { int &f1(int*); |