diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-05-21 23:15:46 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-05-21 23:15:46 +0000 |
commit | 80af31397aceef27426fc47756524bda8a2a31b8 (patch) | |
tree | 70de177ab2fb95fc12ef4c22d700e3ac3b6e8e06 /clang/test/SemaCXX/nullptr.cpp | |
parent | babca9aee9cf4fcfdb1256f0754e30b3dcaeebca (diff) | |
download | bcm5719-llvm-80af31397aceef27426fc47756524bda8a2a31b8.tar.gz bcm5719-llvm-80af31397aceef27426fc47756524bda8a2a31b8.zip |
Audit and finish the implementation of C++0x nullptr, fixing two
minor issues along the way:
- Non-type template parameters of type 'std::nullptr_t' were not
permitted.
- We didn't properly introduce built-in operators for nullptr ==,
!=, <, <=, >=, or > as candidate functions .
To my knowledge, there's only one (minor but annoying) part of nullptr
that hasn't been implemented: catching a thrown 'nullptr' as a pointer
or pointer-to-member, per C++0x [except.handle]p4.
llvm-svn: 131813
Diffstat (limited to 'clang/test/SemaCXX/nullptr.cpp')
-rw-r--r-- | clang/test/SemaCXX/nullptr.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/nullptr.cpp b/clang/test/SemaCXX/nullptr.cpp index 84c80aa286c..d69af588a7d 100644 --- a/clang/test/SemaCXX/nullptr.cpp +++ b/clang/test/SemaCXX/nullptr.cpp @@ -60,6 +60,10 @@ nullptr_t f(nullptr_t null) // You can reinterpret_cast nullptr to an integer. (void)reinterpret_cast<uintptr_t>(nullptr); + (void)reinterpret_cast<uintptr_t>(*pn); + + int *ip = *pn; + if (*pn) { } // You can throw nullptr. throw nullptr; @@ -104,3 +108,56 @@ namespace test3 { f("%p", nullptr); } } + +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 + +namespace overloading { + int &f1(int*); + float &f1(bool); + + void test_f1() { + int &ir = (f1)(nullptr); + } + + struct ConvertsToNullPtr { + operator nullptr_t() const; + }; + + void test_conversion(ConvertsToNullPtr ctn) { + (void)(ctn == ctn); + (void)(ctn != ctn); + (void)(ctn <= ctn); + (void)(ctn >= ctn); + (void)(ctn < ctn); + (void)(ctn > ctn); + } +} + +namespace templates { + template<typename T, nullptr_t Value> + struct X { + X() { ptr = Value; } + + T *ptr; + }; + + X<int, nullptr> x; + + + template<int (*fp)(int), int* p, int A::* pmd, int (A::*pmf)(int)> + struct X2 {}; + + X2<nullptr, nullptr, nullptr, nullptr> x2; +} |