blob: a3aab7fbe3e097af1157a97cc2bb600a571e02f2 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s
Sebastian Redl6e8ed162009-05-10 18:38:11 +00002#include <stdint.h>
3
4// Don't have decltype yet.
5typedef __typeof__(nullptr) nullptr_t;
6
7struct A {};
8
9int o1(char*);
10void o1(uintptr_t);
11void o2(char*); // expected-note {{candidate}}
12void o2(int A::*); // expected-note {{candidate}}
13
14nullptr_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.
Eli Friedmancfdc81a2009-12-19 08:11:05 +000032 uintptr_t i = nullptr; // expected-error {{cannot initialize}}
Sebastian Redl6e8ed162009-05-10 18:38:11 +000033
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.
64template <int *PI, void (*PF)(), int A::*PM, void (A::*PMF)()>
65struct T {};
66
67typedef T<nullptr, nullptr, nullptr, nullptr> NT;