blob: a0d93b130043d3bfe275196e2f9742537755862f (
plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
// RUN: grep -Ev "// *[A-Z-]+:" %S/Inputs/basic.h > %T/basic.h
// RUN: cpp11-migrate -use-nullptr %t.cpp -- -I %S
// RUN: FileCheck -input-file=%t.cpp %s
// RUN: FileCheck -input-file=%T/basic.h %S/Inputs/basic.h
#include "Inputs/basic.h"
const unsigned int g_null = 0;
#define NULL 0
void test_assignment() {
int *p1 = 0;
// CHECK: int *p1 = nullptr;
p1 = 0;
// CHECK: p1 = nullptr;
int *p2 = NULL;
// CHECK: int *p2 = nullptr;
p2 = p1;
// CHECK: p2 = p1;
const int null = 0;
int *p3 = null;
// CHECK: int *p3 = nullptr;
p3 = NULL;
// CHECK: p3 = nullptr;
int *p4 = p3;
// CHECK: int *p4 = p3;
p4 = null;
// CHECK: p4 = nullptr;
int i1 = 0;
// CHECK: int i1 = 0;
int i2 = NULL;
// CHECK: int i2 = NULL;
int i3 = null;
// CHECK: int i3 = null;
int *p5, *p6, *p7;
p5 = p6 = p7 = NULL;
// CHECK: p5 = p6 = p7 = nullptr;
}
struct Foo {
Foo(int *p = NULL) : m_p1(p) {}
// CHECK: Foo(int *p = nullptr) : m_p1(p) {}
void bar(int *p = 0) {}
// CHECK: void bar(int *p = nullptr) {}
void baz(int i = 0) {}
// CHECK: void baz(int i = 0) {}
int *m_p1;
static int *m_p2;
};
int *Foo::m_p2 = NULL;
// CHECK: int *Foo::m_p2 = nullptr;
template <typename T>
struct Bar {
Bar(T *p) : m_p(p) {
m_p = static_cast<T*>(NULL);
// CHECK: m_p = nullptr;
m_p = static_cast<T*>(reinterpret_cast<int*>((void*)NULL));
// CHECK: m_p = nullptr;
m_p = static_cast<T*>(p ? p : static_cast<void*>(g_null));
// CHECK: m_p = static_cast<T*>(p ? p : nullptr);
T *p2 = static_cast<T*>(reinterpret_cast<int*>((void*)NULL));
// CHECK: T *p2 = nullptr;
m_p = NULL;
// CHECK: m_p = nullptr;
int i = static_cast<int>(0.f);
// CHECK: int i = static_cast<int>(0.f);
T *i2 = static_cast<int>(0.f);
// CHECK: T *i2 = nullptr;
}
T *m_p;
};
struct Baz {
Baz() : i(0) {}
int i;
};
void test_cxx_cases() {
Foo f(g_null);
// CHECK: Foo f(nullptr);
f.bar(NULL);
// CHECK: f.bar(nullptr);
f.baz(g_null);
// CHECK: f.baz(g_null);
f.m_p1 = 0;
// CHECK: f.m_p1 = nullptr;
Bar<int> b(g_null);
// CHECK: Bar<int> b(nullptr);
Baz b2;
int Baz::*memptr(0);
// CHECK: int Baz::*memptr(nullptr);
memptr = 0;
// CHECK: memptr = nullptr;
}
void test_function_default_param1(void *p = 0);
// CHECK: void test_function_default_param1(void *p = nullptr);
void test_function_default_param2(void *p = NULL);
// CHECK: void test_function_default_param2(void *p = nullptr);
void test_function_default_param3(void *p = g_null);
// CHECK: void test_function_default_param3(void *p = nullptr);
void test_function(int *p) {}
// CHECK: void test_function(int *p) {}
void test_function_no_ptr_param(int i) {}
void test_function_call() {
test_function(0);
// CHECK: test_function(nullptr);
test_function(NULL);
// CHECK: test_function(nullptr);
test_function(g_null);
// CHECK: test_function(nullptr);
test_function_no_ptr_param(0);
// CHECK: test_function_no_ptr_param(0);
}
char *test_function_return1() {
return 0;
// CHECK: return nullptr;
}
void *test_function_return2() {
return NULL;
// CHECK: return nullptr;
}
long *test_function_return3() {
return g_null;
// CHECK: return nullptr;
}
int test_function_return4() {
return 0;
// CHECK: return 0;
}
int test_function_return5() {
return NULL;
// CHECK: return NULL;
}
int test_function_return6() {
return g_null;
// CHECK: return g_null;
}
|