]> granicus.if.org Git - clang/commitdiff
Expressions of type std::nullptr_t can be used as sentinels.
authorAnders Carlsson <andersca@mac.com>
Fri, 5 Nov 2010 15:21:33 +0000 (15:21 +0000)
committerAnders Carlsson <andersca@mac.com>
Fri, 5 Nov 2010 15:21:33 +0000 (15:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118276 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/SemaCXX/nullptr.cpp

index 6df818cd7a5a460d497392670045f8fa7c75c300..9ac4ce88d102ebf2238c54982d9c37a79505ba55 100644 (file)
@@ -193,6 +193,10 @@ void Sema::DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
   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))
index 0a0d098e364f6a187bf7d94a5f3414f329980eb3..4f6e2e6eb1c58f8c564fa1c0b83e7b808207531e 100644 (file)
@@ -84,3 +84,12 @@ bool g(bool);
 // 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);
+  }
+}