nullptr.cpp
1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 -I%S -emit-llvm -o - %s | FileCheck %s
#include <typeinfo>
// CHECK: @_ZTIDn = external constant i8*
int* a = nullptr;
void f() {
int* a = nullptr;
}
typedef decltype(nullptr) nullptr_t;
nullptr_t get_nullptr();
struct X { };
void g() {
// CHECK: call i8* @_Z11get_nullptrv()
int (X::*pmf)(int) = get_nullptr();
}
const std::type_info& f2() {
return typeid(nullptr_t);
}
union U {
int n;
nullptr_t b;
};
// CHECK-LABEL: define {{.*}}pr23833_a
// CHECK: store
// CHECK: load
// CHECK-NOT: load
// CHECK: ret i1 false
bool pr23833_a(U &u) { return u.b; }
// CHECK-LABEL: define {{.*}}pr23833_b
// CHECK: store
// CHECK: load
// CHECK-NOT: load
// CHECK: ret i8* null
nullptr_t pr23833_b(nullptr_t &n) { return n; }
struct X1 { operator int*(); };
struct X2 { operator const nullptr_t&(); };
// CHECK-LABEL: define {{.*}}pr23833_c
// CHECK: call {{.*}}X1
// CHECK: call {{.*}}X2
// CHECK-NOT: load
// CHECK: ret i32
int pr23833_c() {
return X1() != X2();
}
// CHECK-LABEL: define {{.*}}pr23833_d
// CHECK: call {{.*}}X2
// CHECK-NOT: load
// CHECK: store
// CHECK: load
// CHECK: ret i32*
int *pr23833_d() {
int *p = X2();
return p;
}
namespace PR39528 {
constexpr nullptr_t null = nullptr;
void f(nullptr_t);
void g() { f(null); }
}