bugprone-reserved-identifier.cpp
9.15 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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// RUN: %check_clang_tidy %s bugprone-reserved-identifier %t -- -- \
// RUN: -I%S/Inputs/bugprone-reserved-identifier \
// RUN: -isystem %S/Inputs/bugprone-reserved-identifier/system
// no warnings expected without -header-filter=
#include "user-header.h"
#include <system-header.h>
#define _MACRO(m) int m = 0
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: declaration uses identifier '_MACRO', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}#define MACRO(m) int m = 0{{$}}
namespace _Ns {
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: declaration uses identifier '_Ns', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}namespace Ns {{{$}}
class _Object {
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_Object', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}class Object {{{$}}
int _Member;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_Member', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}} int Member;{{$}}
};
float _Global;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_Global', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}float Global;{{$}}
void _Function() {}
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier '_Function', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}void Function() {}{{$}}
using _Alias = int;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_Alias', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}using Alias = int;{{$}}
template <typename _TemplateParam>
// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: declaration uses identifier '_TemplateParam', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}template <typename TemplateParam>{{$}}
struct S {};
} // namespace _Ns
//
#define __macro(m) int m = 0
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: declaration uses identifier '__macro', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}#define macro(m) int m = 0{{$}}
namespace __ns {
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: declaration uses identifier '__ns', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}namespace ns {{{$}}
class __object {
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '__object', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}class _object {{{$}}
int __member;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '__member', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}} int _member;{{$}}
};
float __global;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '__global', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}float _global;{{$}}
void __function() {}
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier '__function', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}void _function() {}{{$}}
using __alias = int;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '__alias', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}using _alias = int;{{$}}
template <typename __templateParam>
// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: declaration uses identifier '__templateParam', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}template <typename _templateParam>{{$}}
struct S {};
} // namespace __ns
//
#define macro___m(m) int m = 0
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: declaration uses identifier 'macro___m', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}#define macro_m(m) int m = 0{{$}}
namespace ns___n {
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: declaration uses identifier 'ns___n', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}namespace ns_n {{{$}}
class object___o {
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier 'object___o', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}class object_o {{{$}}
int member___m;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier 'member___m', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}} int member_m;{{$}}
};
float global___g;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier 'global___g', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}float global_g;{{$}}
void function___f() {}
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier 'function___f', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}void function_f() {}{{$}}
using alias___a = int;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier 'alias___a', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}using alias_a = int;{{$}}
template <typename templateParam___t>
// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: declaration uses identifier 'templateParam___t', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}template <typename templateParam_t>{{$}}
struct S {};
} // namespace ns___n
//
#define _macro(m) int m = 0
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: declaration uses identifier '_macro', which is reserved in the global namespace [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}#define macro(m) int m = 0{{$}}
namespace _ns {
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: declaration uses identifier '_ns', which is reserved in the global namespace [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}namespace ns {{{$}}
int _i;
// no warning
} // namespace _ns
class _object {
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_object', which is reserved in the global namespace [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}class object {{{$}}
int _member;
// no warning
};
float _global;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_global', which is reserved in the global namespace [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}float global;{{$}}
void _function() {}
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier '_function', which is reserved in the global namespace [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}void function() {}{{$}}
using _alias = int;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_alias', which is reserved in the global namespace [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}using alias = int;{{$}}
template <typename _templateParam> // no warning, template params are not in the global namespace
struct S {};
void _float() {}
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier '_float', which is reserved in the global namespace; cannot be fixed because 'float' would conflict with a keyword [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}void _float() {}{{$}}
#define SOME_MACRO
int SOME__MACRO;
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration uses identifier 'SOME__MACRO', which is a reserved identifier; cannot be fixed because 'SOME_MACRO' would conflict with a macro definition [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}int SOME__MACRO;{{$}}
void _TWO__PROBLEMS() {}
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier '_TWO__PROBLEMS', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}void TWO_PROBLEMS() {}{{$}}
void _two__problems() {}
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier '_two__problems', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}void two_problems() {}{{$}}
int __;
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration uses identifier '__', which is a reserved identifier; cannot be fixed automatically [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}int __;{{$}}
int _________;
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration uses identifier '_________', which is a reserved identifier; cannot be fixed automatically [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}int _________;{{$}}
int _;
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration uses identifier '_', which is reserved in the global namespace; cannot be fixed automatically [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}int _;{{$}}
// these should pass
#define MACRO(m) int m = 0
namespace Ns {
class Object {
int Member;
};
float Global;
void Function() {}
using Alias = int;
template <typename TemplateParam>
struct S {};
} // namespace Ns
namespace ns_ {
class object_ {
int member_;
};
float global_;
void function_() {}
using alias_ = int;
template <typename templateParam_>
struct S {};
} // namespace ns_
class object_ {
int member_;
};
float global_;
void function_() {}
using alias_ = int;
template <typename templateParam_>
struct S_ {};