]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/SemaCXX/nullptr.cpp
Import Clang, at r72732.
[FreeBSD/FreeBSD.git] / test / SemaCXX / nullptr.cpp
1 // RUN: clang-cc -fsyntax-only -verify -std=c++0x %s
2 #include <stdint.h>
3
4 // Don't have decltype yet.
5 typedef __typeof__(nullptr) nullptr_t;
6
7 struct A {};
8
9 int o1(char*);
10 void o1(uintptr_t);
11 void o2(char*); // expected-note {{candidate}}
12 void o2(int A::*); // expected-note {{candidate}}
13
14 nullptr_t f(nullptr_t null)
15 {
16   // Implicit conversions.
17   null = nullptr;
18   void *p = nullptr;
19   p = null;
20   int *pi = nullptr;
21   pi = null;
22   null = 0;
23   int A::*pm = nullptr;
24   pm = null;
25   void (*pf)() = nullptr;
26   pf = null;
27   void (A::*pmf)() = nullptr;
28   pmf = null;
29   bool b = nullptr;
30
31   // Can't convert nullptr to integral implicitly.
32   uintptr_t i = nullptr; // expected-error {{incompatible type initializing}}
33
34   // Operators
35   (void)(null == nullptr);
36   (void)(null <= nullptr);
37   (void)(null == (void*)0);
38   (void)((void*)0 == nullptr);
39   (void)(null <= (void*)0);
40   (void)((void*)0 <= nullptr);
41   (void)(1 > nullptr); // expected-error {{invalid operands to binary expression}}
42   (void)(1 != nullptr); // expected-error {{invalid operands to binary expression}}
43   (void)(1 + nullptr); // expected-error {{invalid operands to binary expression}}
44   (void)(0 ? nullptr : 0); // expected-error {{incompatible operand types}}
45   (void)(0 ? nullptr : (void*)0);
46
47   // Overloading
48   int t = o1(nullptr);
49   t = o1(null);
50   o2(nullptr); // expected-error {{ambiguous}}
51
52   // nullptr is an rvalue, null is an lvalue
53   (void)&nullptr; // expected-error {{address expression must be an lvalue}}
54   nullptr_t *pn = &null;
55
56   // You can reinterpret_cast nullptr to an integer.
57   (void)reinterpret_cast<uintptr_t>(nullptr);
58
59   // You can throw nullptr.
60   throw nullptr;
61 }
62
63 // Template arguments can be nullptr.
64 template <int *PI, void (*PF)(), int A::*PM, void (A::*PMF)()>
65 struct T {};
66
67 typedef T<nullptr, nullptr, nullptr, nullptr> NT;