Expressions of type std::nullptr_t can be used as sentinels.

llvm-svn: 118276
This commit is contained in:
Anders Carlsson 2010-11-05 15:21:33 +00:00
parent 6c25ca4f2b
commit e981a8c231
2 changed files with 13 additions and 0 deletions

View File

@ -193,6 +193,10 @@ void Sema::DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
if (!sentinelExpr) return; if (!sentinelExpr) return;
if (sentinelExpr->isTypeDependent()) return; if (sentinelExpr->isTypeDependent()) return;
if (sentinelExpr->isValueDependent()) return; if (sentinelExpr->isValueDependent()) return;
// nullptr_t is always treated as null.
if (sentinelExpr->getType()->isNullPtrType()) return;
if (sentinelExpr->getType()->isAnyPointerType() && if (sentinelExpr->getType()->isAnyPointerType() &&
sentinelExpr->IgnoreParenCasts()->isNullPointerConstant(Context, sentinelExpr->IgnoreParenCasts()->isNullPointerConstant(Context,
Expr::NPC_ValueDependentIsNull)) Expr::NPC_ValueDependentIsNull))

View File

@ -84,3 +84,12 @@ bool g(bool);
// Test that we prefer g(void*) over g(bool). // Test that we prefer g(void*) over g(bool).
static_assert(is_same<decltype(g(nullptr)), void*>::value, ""); 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);
}
}