diff options
Diffstat (limited to 'test/SemaCXX/nullptr.cpp')
-rw-r--r-- | test/SemaCXX/nullptr.cpp | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/test/SemaCXX/nullptr.cpp b/test/SemaCXX/nullptr.cpp index 6f660366e9989..e3136039f425b 100644 --- a/test/SemaCXX/nullptr.cpp +++ b/test/SemaCXX/nullptr.cpp @@ -109,19 +109,30 @@ namespace test3 { } } -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 +static_assert(__is_scalar(nullptr_t), ""); +static_assert(__is_pod(nullptr_t), ""); +static_assert(sizeof(nullptr_t) == sizeof(void*), ""); + +static_assert(!(nullptr < nullptr), ""); +static_assert(!(nullptr > nullptr), ""); +static_assert( nullptr <= nullptr, ""); +static_assert( nullptr >= nullptr, ""); +static_assert( nullptr == nullptr, ""); +static_assert(!(nullptr != nullptr), ""); + +static_assert(!(0 < nullptr), ""); +static_assert(!(0 > nullptr), ""); +static_assert( 0 <= nullptr, ""); +static_assert( 0 >= nullptr, ""); +static_assert( 0 == nullptr, ""); +static_assert(!(0 != nullptr), ""); + +static_assert(!(nullptr < 0), ""); +static_assert(!(nullptr > 0), ""); +static_assert( nullptr <= 0, ""); +static_assert( nullptr >= 0, ""); +static_assert( nullptr == 0, ""); +static_assert(!(nullptr != 0), ""); namespace overloading { int &f1(int*); @@ -161,3 +172,14 @@ namespace templates { X2<nullptr, nullptr, nullptr, nullptr> x2; } + +namespace null_pointer_constant { + +// Pending implementation of core issue 903, ensure we don't allow any of the +// C++11 constant evaluation semantics in null pointer constants. +struct S { int n; }; +constexpr int null() { return 0; } +void *p = S().n; // expected-error {{cannot initialize}} +void *q = null(); // expected-error {{cannot initialize}} + +} |