[cfe-commits] r150521 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/SemaCXX/nullptr.cpp
Richard Smith
richard-llvm at metafoo.co.uk
Tue Feb 14 14:35:28 PST 2012
Author: rsmith
Date: Tue Feb 14 16:35:28 2012
New Revision: 150521
URL: http://llvm.org/viewvc/llvm-project?rev=150521&view=rev
Log:
constexpr: evaluation support for nullptr comparisons.
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/SemaCXX/nullptr.cpp
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=150521&r1=150520&r2=150521&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Feb 14 16:35:28 2012
@@ -4612,6 +4612,16 @@
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.
Modified: cfe/trunk/test/SemaCXX/nullptr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/nullptr.cpp?rev=150521&r1=150520&r2=150521&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/nullptr.cpp (original)
+++ cfe/trunk/test/SemaCXX/nullptr.cpp Tue Feb 14 16:35:28 2012
@@ -113,15 +113,26 @@
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*);
More information about the cfe-commits
mailing list