1 // RUN: %check_clang_tidy %s bugprone-reserved-identifier %t -- -- \
2 // RUN: -I%S/Inputs/bugprone-reserved-identifier \
3 // RUN: -isystem %S/Inputs/bugprone-reserved-identifier/system
4
5 // no warnings expected without -header-filter=
6 #include "user-header.h"
7 #include <system-header.h>
8
9 #define _MACRO(m) int m = 0
10 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: declaration uses identifier '_MACRO', which is a reserved identifier [bugprone-reserved-identifier]
11 // CHECK-FIXES: {{^}}#define MACRO(m) int m = 0{{$}}
12
13 namespace _Ns {
14 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: declaration uses identifier '_Ns', which is a reserved identifier [bugprone-reserved-identifier]
15 // CHECK-FIXES: {{^}}namespace Ns {{{$}}
16
17 class _Object {
18 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_Object', which is a reserved identifier [bugprone-reserved-identifier]
19 // CHECK-FIXES: {{^}}class Object {{{$}}
20 int _Member;
21 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_Member', which is a reserved identifier [bugprone-reserved-identifier]
22 // CHECK-FIXES: {{^}} int Member;{{$}}
23 };
24
25 float _Global;
26 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_Global', which is a reserved identifier [bugprone-reserved-identifier]
27 // CHECK-FIXES: {{^}}float Global;{{$}}
28
_Function()29 void _Function() {}
30 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier '_Function', which is a reserved identifier [bugprone-reserved-identifier]
31 // CHECK-FIXES: {{^}}void Function() {}{{$}}
32
33 using _Alias = int;
34 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_Alias', which is a reserved identifier [bugprone-reserved-identifier]
35 // CHECK-FIXES: {{^}}using Alias = int;{{$}}
36
37 template <typename _TemplateParam>
38 // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: declaration uses identifier '_TemplateParam', which is a reserved identifier [bugprone-reserved-identifier]
39 // CHECK-FIXES: {{^}}template <typename TemplateParam>{{$}}
40 struct S {};
41
42 } // namespace _Ns
43
44 //
45
46 #define __macro(m) int m = 0
47 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: declaration uses identifier '__macro', which is a reserved identifier [bugprone-reserved-identifier]
48 // CHECK-FIXES: {{^}}#define macro(m) int m = 0{{$}}
49
50 namespace __ns {
51 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: declaration uses identifier '__ns', which is a reserved identifier [bugprone-reserved-identifier]
52 // CHECK-FIXES: {{^}}namespace ns {{{$}}
53 class __object {
54 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '__object', which is a reserved identifier [bugprone-reserved-identifier]
55 // CHECK-FIXES: {{^}}class _object {{{$}}
56 int __member;
57 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '__member', which is a reserved identifier [bugprone-reserved-identifier]
58 // CHECK-FIXES: {{^}} int _member;{{$}}
59 };
60
61 float __global;
62 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '__global', which is a reserved identifier [bugprone-reserved-identifier]
63 // CHECK-FIXES: {{^}}float _global;{{$}}
64
__function()65 void __function() {}
66 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier '__function', which is a reserved identifier [bugprone-reserved-identifier]
67 // CHECK-FIXES: {{^}}void _function() {}{{$}}
68
69 using __alias = int;
70 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '__alias', which is a reserved identifier [bugprone-reserved-identifier]
71 // CHECK-FIXES: {{^}}using _alias = int;{{$}}
72
73 template <typename __templateParam>
74 // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: declaration uses identifier '__templateParam', which is a reserved identifier [bugprone-reserved-identifier]
75 // CHECK-FIXES: {{^}}template <typename _templateParam>{{$}}
76 struct S {};
77
78 } // namespace __ns
79
80 //
81
82 #define macro___m(m) int m = 0
83 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: declaration uses identifier 'macro___m', which is a reserved identifier [bugprone-reserved-identifier]
84 // CHECK-FIXES: {{^}}#define macro_m(m) int m = 0{{$}}
85
86 namespace ns___n {
87 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: declaration uses identifier 'ns___n', which is a reserved identifier [bugprone-reserved-identifier]
88 // CHECK-FIXES: {{^}}namespace ns_n {{{$}}
89 class object___o {
90 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier 'object___o', which is a reserved identifier [bugprone-reserved-identifier]
91 // CHECK-FIXES: {{^}}class object_o {{{$}}
92 int member___m;
93 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier 'member___m', which is a reserved identifier [bugprone-reserved-identifier]
94 // CHECK-FIXES: {{^}} int member_m;{{$}}
95 };
96
97 float global___g;
98 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier 'global___g', which is a reserved identifier [bugprone-reserved-identifier]
99 // CHECK-FIXES: {{^}}float global_g;{{$}}
100
function___f()101 void function___f() {}
102 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier 'function___f', which is a reserved identifier [bugprone-reserved-identifier]
103 // CHECK-FIXES: {{^}}void function_f() {}{{$}}
104
105 using alias___a = int;
106 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier 'alias___a', which is a reserved identifier [bugprone-reserved-identifier]
107 // CHECK-FIXES: {{^}}using alias_a = int;{{$}}
108
109 template <typename templateParam___t>
110 // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: declaration uses identifier 'templateParam___t', which is a reserved identifier [bugprone-reserved-identifier]
111 // CHECK-FIXES: {{^}}template <typename templateParam_t>{{$}}
112 struct S {};
113
114 } // namespace ns___n
115
116 //
117
118 #define _macro(m) int m = 0
119 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: declaration uses identifier '_macro', which is reserved in the global namespace [bugprone-reserved-identifier]
120 // CHECK-FIXES: {{^}}#define macro(m) int m = 0{{$}}
121
122 namespace _ns {
123 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: declaration uses identifier '_ns', which is reserved in the global namespace [bugprone-reserved-identifier]
124 // CHECK-FIXES: {{^}}namespace ns {{{$}}
125 int _i;
126 // no warning
127 } // namespace _ns
128 class _object {
129 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_object', which is reserved in the global namespace [bugprone-reserved-identifier]
130 // CHECK-FIXES: {{^}}class object {{{$}}
131 int _member;
132 // no warning
133 };
134 float _global;
135 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_global', which is reserved in the global namespace [bugprone-reserved-identifier]
136 // CHECK-FIXES: {{^}}float global;{{$}}
_function()137 void _function() {}
138 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier '_function', which is reserved in the global namespace [bugprone-reserved-identifier]
139 // CHECK-FIXES: {{^}}void function() {}{{$}}
140 using _alias = int;
141 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_alias', which is reserved in the global namespace [bugprone-reserved-identifier]
142 // CHECK-FIXES: {{^}}using alias = int;{{$}}
143 template <typename _templateParam> // no warning, template params are not in the global namespace
144 struct S {};
145
_float()146 void _float() {}
147 // 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]
148 // CHECK-FIXES: {{^}}void _float() {}{{$}}
149
150 #define SOME_MACRO
151 int SOME__MACRO;
152 // 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]
153 // CHECK-FIXES: {{^}}int SOME__MACRO;{{$}}
154
_TWO__PROBLEMS()155 void _TWO__PROBLEMS() {}
156 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier '_TWO__PROBLEMS', which is a reserved identifier [bugprone-reserved-identifier]
157 // CHECK-FIXES: {{^}}void TWO_PROBLEMS() {}{{$}}
_two__problems()158 void _two__problems() {}
159 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier '_two__problems', which is a reserved identifier [bugprone-reserved-identifier]
160 // CHECK-FIXES: {{^}}void two_problems() {}{{$}}
161
162 int __;
163 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration uses identifier '__', which is a reserved identifier; cannot be fixed automatically [bugprone-reserved-identifier]
164 // CHECK-FIXES: {{^}}int __;{{$}}
165
166 int _________;
167 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration uses identifier '_________', which is a reserved identifier; cannot be fixed automatically [bugprone-reserved-identifier]
168 // CHECK-FIXES: {{^}}int _________;{{$}}
169
170 int _;
171 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration uses identifier '_', which is reserved in the global namespace; cannot be fixed automatically [bugprone-reserved-identifier]
172 // CHECK-FIXES: {{^}}int _;{{$}}
173
174 // these should pass
175 #define MACRO(m) int m = 0
176
177 namespace Ns {
178 class Object {
179 int Member;
180 };
181 float Global;
182
Function()183 void Function() {}
184 using Alias = int;
185 template <typename TemplateParam>
186 struct S {};
187 } // namespace Ns
188 namespace ns_ {
189 class object_ {
190 int member_;
191 };
192 float global_;
function_()193 void function_() {}
194 using alias_ = int;
195 template <typename templateParam_>
196 struct S {};
197 } // namespace ns_
198
199 class object_ {
200 int member_;
201 };
202 float global_;
function_()203 void function_() {}
204 using alias_ = int;
205 template <typename templateParam_>
206 struct S_ {};
207