[cfe-commits] r118276 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaCXX/nullptr.cpp
Anders Carlsson
andersca at mac.com
Fri Nov 5 08:21:33 PDT 2010
Author: andersca
Date: Fri Nov 5 10:21:33 2010
New Revision: 118276
URL: http://llvm.org/viewvc/llvm-project?rev=118276&view=rev
Log:
Expressions of type std::nullptr_t can be used as sentinels.
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaCXX/nullptr.cpp
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=118276&r1=118275&r2=118276&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Nov 5 10:21:33 2010
@@ -193,6 +193,10 @@
if (!sentinelExpr) return;
if (sentinelExpr->isTypeDependent()) return;
if (sentinelExpr->isValueDependent()) return;
+
+ // nullptr_t is always treated as null.
+ if (sentinelExpr->getType()->isNullPtrType()) return;
+
if (sentinelExpr->getType()->isAnyPointerType() &&
sentinelExpr->IgnoreParenCasts()->isNullPointerConstant(Context,
Expr::NPC_ValueDependentIsNull))
Modified: cfe/trunk/test/SemaCXX/nullptr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/nullptr.cpp?rev=118276&r1=118275&r2=118276&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/nullptr.cpp (original)
+++ cfe/trunk/test/SemaCXX/nullptr.cpp Fri Nov 5 10:21:33 2010
@@ -84,3 +84,12 @@
// Test that we prefer g(void*) over g(bool).
static_assert(is_same<decltype(g(nullptr)), void*>::value, "");
}
+
+namespace test2 {
+ void f(int, ...) __attribute__((sentinel));
+
+ void g() {
+ // nullptr can be used as the sentinel value.
+ f(10, nullptr);
+ }
+}
More information about the cfe-commits
mailing list