diff options
author | Sebastian Redl <sebastian.redl@getdesigned.at> | 2009-05-10 18:38:11 +0000 |
---|---|---|
committer | Sebastian Redl <sebastian.redl@getdesigned.at> | 2009-05-10 18:38:11 +0000 |
commit | 576fd424dfe20c855bc9a8ac5dbac0c4d11fd9ef (patch) | |
tree | 848feaf684633a0718f55a24ed033b266438c4cb /clang/test/SemaCXX/nullptr.cpp | |
parent | 9a627e60cdb55b69f99671ae98a9ce3a3af6a92a (diff) | |
download | bcm5719-llvm-576fd424dfe20c855bc9a8ac5dbac0c4d11fd9ef.tar.gz bcm5719-llvm-576fd424dfe20c855bc9a8ac5dbac0c4d11fd9ef.zip |
Implement C++0x nullptr.
llvm-svn: 71405
Diffstat (limited to 'clang/test/SemaCXX/nullptr.cpp')
-rw-r--r-- | clang/test/SemaCXX/nullptr.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/nullptr.cpp b/clang/test/SemaCXX/nullptr.cpp new file mode 100644 index 00000000000..6cc5a816831 --- /dev/null +++ b/clang/test/SemaCXX/nullptr.cpp @@ -0,0 +1,67 @@ +// RUN: clang-cc -fsyntax-only -verify -std=c++0x %s +#include <stdint.h> + +// Don't have decltype yet. +typedef __typeof__(nullptr) nullptr_t; + +struct A {}; + +int o1(char*); +void o1(uintptr_t); +void o2(char*); // expected-note {{candidate}} +void o2(int A::*); // expected-note {{candidate}} + +nullptr_t f(nullptr_t null) +{ + // Implicit conversions. + null = nullptr; + void *p = nullptr; + p = null; + int *pi = nullptr; + pi = null; + null = 0; + int A::*pm = nullptr; + pm = null; + void (*pf)() = nullptr; + pf = null; + void (A::*pmf)() = nullptr; + pmf = null; + bool b = nullptr; + + // Can't convert nullptr to integral implicitly. + uintptr_t i = nullptr; // expected-error {{incompatible type initializing}} + + // Operators + (void)(null == nullptr); + (void)(null <= nullptr); + (void)(null == (void*)0); + (void)((void*)0 == nullptr); + (void)(null <= (void*)0); + (void)((void*)0 <= nullptr); + (void)(1 > nullptr); // expected-error {{invalid operands to binary expression}} + (void)(1 != nullptr); // expected-error {{invalid operands to binary expression}} + (void)(1 + nullptr); // expected-error {{invalid operands to binary expression}} + (void)(0 ? nullptr : 0); // expected-error {{incompatible operand types}} + (void)(0 ? nullptr : (void*)0); + + // Overloading + int t = o1(nullptr); + t = o1(null); + o2(nullptr); // expected-error {{ambiguous}} + + // nullptr is an rvalue, null is an lvalue + (void)&nullptr; // expected-error {{address expression must be an lvalue}} + nullptr_t *pn = &null; + + // You can reinterpret_cast nullptr to an integer. + (void)reinterpret_cast<uintptr_t>(nullptr); + + // You can throw nullptr. + throw nullptr; +} + +// Template arguments can be nullptr. +template <int *PI, void (*PF)(), int A::*PM, void (A::*PMF)()> +struct T {}; + +typedef T<nullptr, nullptr, nullptr, nullptr> NT; |