Debian Codegraph @

libstdc++-v3/testsuite/17_intro/names.cc

raw
1 // Copyright (C) 2017-2025 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // { dg-do compile }
19 // { dg-add-options no_pch }
20
21 // Define macros for some common variables names that we must not use for
22 // naming variables, parameters etc. in the library.
23 // N.B. we cannot use '#pragma GCC poison A' because that also prevents using
24 // these names even as macro arguments, e.g. #define FOO(A) BAR(A)
25 #define A (
26 #define B (
27 #define C (
28 #define D (
29 #define E (
30 #define F (
31 #define G (
32 #define H (
33 // <complex.h> defines I
34 #define J (
35 #define K (
36 #define L (
37 #define M (
38 #define N (
39 #define O (
40 #define P (
41 #define Q (
42 #define R (
43 #define S (
44 #define T (
45 #define U (
46 #define V (
47 #define W (
48 #define X (
49 #define Y (
50 #define Z (
51 #if __cplusplus >= 201103L
52 // <random> defines member functions called a() and b()
53 #else
54 #define a (
55 #define b (
56 #endif
57 // <queue> and <stack> defined data members called c
58 #if __cplusplus <= 201703L
59 // <chrono> defines operator""d in C++20
60 #define d (
61 // <numbers> defines std::numbers::e in C++20
62 #define e (
63 #endif
64 #define f (
65 #define g (
66 #if __cplusplus >= 201402L
67 // <chrono> defines operator ""h in C++14
68 // <complex> defines operator ""i in C++14
69 #else
70 #define h (
71 #define i (
72 #endif
73 #define j (
74 #if __cplusplus >= 201103L
75 // <random> defines member functions called k()
76 #else
77 #define k (
78 #endif
79 #define l (
80 #if __cplusplus >= 201103L
81 // <random> defines member functions called m() and n()
82 #else
83 #define m (
84 #define n (
85 #endif
86 #define o (
87 #if __cplusplus >= 201103L || defined(_GLIBCXX_PARALLEL)
88 // <random> defines member functions called p()
89 // (and <tr1/random> defines them too, which is included by Parallel Mode).
90 #else
91 #define p (
92 #endif
93 #define q (
94 #define r (
95 #if __cplusplus >= 201103L || defined(_GLIBCXX_PARALLEL)
96 // <random> defines member functions called s() and t()
97 // (and <tr1/random> defines them too, which is included by Parallel Mode).
98 // <chrono> and <string> define operator ""s in C++14
99 #else
100 #define s (
101 #define t (
102 #endif
103 #define u (
104 #define v (
105 #define w (
106 #define x (
107 #if __cplusplus <= 201703L
108 // <chrono> defines operator""y in C++20
109 #define y (
110 #endif
111 #define z (
112
113 #define attributes (
114 #define bin_op (
115 #define clockid (
116 #define func (
117 #define max_val (
118 #define min_val (
119 #define object (
120 #define ostr (
121 #define policy (
122 #define sz (
123 #define tinfo (
124 #define tmp (
125 #define token (
126 #define value_t (
127
128 #if __cplusplus < 201103L
129 #define uses_allocator (
130 #endif
131
132 #if __cplusplus < 201402L
133 // <complex> defines operator""il
134 #define il (
135 #endif
136
137 #if __cplusplus < 201703L
138 // <charconv> defines to_chars_result::ptr and to_chars_result::ec
139 #define ec (
140 #define ptr (
141 // <map> and <unordered_map> define try_emplace
142 #define try_emplace (
143 #endif
144
145 #if __cplusplus < 202002L
146 #define ranges (
147 #endif
148
149 // These clash with newlib so don't use them.
150 # define __lockable cannot be used as an identifier
151 # define __null_sentinel cannot be used as an identifier
152 # define __packed cannot be used as an identifier
153 # define __unused cannot be used as an identifier
154 # define __used cannot be used as an identifier
155
156 #ifndef __APPLE__
157 #define __weak predefined qualifier on darwin
158 #define __strong predefined qualifier on darwin
159 #endif
160
161 // Common template parameter names
162 #define OutputIterator OutputIterator is not a reserved name
163 #define InputIterator InputIterator is not a reserved name
164 #define ForwardIterator ForwardIterator is not a reserved name
165 #define BidirectionalIterator BidirectionalIterator is not a reserved name
166 #define RandomAccessIterator RandomAccessIterator is not a reserved name
167 #define RandomAccessOutputIterator RandomAccessOutputIterator is not a reserved name
168 #define RAI RAI is not a reserved name
169 #define RAIter RAIter is not a reserved name
170 #define FwdIter FwdIter is not a reserved name
171 #define OutIter OutIter is not a reserved name
172 #define InIter InIter is not a reserved name
173
174 #define Alloc Alloc is not a reserved name
175 #define BinaryFunction1 BinaryFunction1 is not a reserved name
176 #define BinaryFunction2 BinaryFunction2 is not a reserved name
177 #define BinaryOperation BinaryOperation is not a reserved name
178 #define Char Char is not a reserved name
179 #define CharT CharT is not a reserved name
180 #define Cmp Cmp is not a reserved name
181 #define Compare Compare is not a reserved name
182 #define Const_Iterator Const_Iterator is not a reserved name
183 #define Const_Key_Reference Const_Key_Reference is not a reserved name
184 #define Const_Node_Iter Const_Node_Iter is not a reserved name
185 #define Const_Pointer Const_Pointer is not a reserved name
186 #define Const_Reference Const_Reference is not a reserved name
187 #define Data Data is not a reserved name
188 #define DiffType DiffType is not a reserved name
189 #define Eq Eq is not a reserved name
190 #define ExecPolicy ExecPolicy is not a reserved name
191 #define Expected Expected is not a reserved name
192 #define External_Load_Access External_Load_Access is not a reserved name
193 #define External_Size_Access External_Size_Access is not a reserved name
194 #define Fn Fn is not a reserved name
195 #define Function Function is not a reserved name
196 #define Functor Functor is not a reserved name
197 #define Hash Hash is not a reserved name
198 #define H1 H1 is not a reserved name
199 #define H2 H2 is not a reserved name
200 #define Head Head is not a reserved name
201 #define IsVector IsVector is not a reserved name
202 #define It It is not a reserved name
203 #define Iter Iter is not a reserved name
204 #define Iterator Iterator is not a reserved name
205 #define Key Key is not a reserved name
206 #define Mapped Mapped is not a reserved name
207 #define Node Node is not a reserved name
208 #define Node_iter Node_iter is not a reserved name
209 #define Node_ptr Node_ptr is not a reserved name
210 #define Overflow Overflow is not a reserved name
211 #define Pointer Pointer is not a reserved name
212 #define Policy Policy is not a reserved name
213 #define Pred Pred is not a reserved name
214 #define Proj Proj is not a reserved name
215 #define Proj1 Proj1 is not a reserved name
216 #define Proj2 Proj2 is not a reserved name
217 #define Ptr Ptr is not a reserved name
218 #define Reference Reference is not a reserved name
219 #define Seq Seq is not a reserved name
220 #define Seq_RAIter Seq_RAIter is not a reserved name
221 #define Series Series is not a reserved name
222 #define Set Set is not a reserved name
223 #define Size Size is not a reserved name
224 #define String String is not a reserved name
225 #define Tp Tp is not a reserved name
226 #define TQual TQual is not a reserved name
227 #define Traits Traits is not a reserved name
228 #define Type Type is not a reserved name
229 #define UQual UQual is not a reserved name
230 #define Value Value is not a reserved name
231 #define ValueT ValueT is not a reserved name
232 #define ValueType ValueType is not a reserved name
233
234 #ifndef _WIN32
235 // Windows SAL annotations
236 #define _In_ cannot be used as an identifier
237 #define _Inout_ cannot be used as an identifier
238 #define _Out_ cannot be used as an identifier
239 #define _Reserved_ cannot be used as an identifier
240 #define __inout cannot be used as an identifier
241 #define __in_opt cannot be used as an identifier
242 #define __out_opt cannot be used as an identifier
243 #endif
244
245 #ifdef _AIX
246 // See https://gcc.gnu.org/ml/libstdc++/2017-03/msg00015.html
247 #undef f
248 #undef r
249 #undef x
250 #undef y
251 // <sys/poll.h> defines pollfd_ext::u on AIX 7.3
252 #undef u
253 // <sys/var.h> defines vario::v
254 #undef v
255 // <sys/timer.h> defines trb::func and cputime_tmr::func
256 #undef func
257 // <sys/thread.h> defines tstate::policy
258 #undef policy
259 #endif
260
261 #ifdef __APPLE__
262 // inttypes.h: extern intmax_t imaxabs(intmax_t j);
263 #undef j
264 #endif
265
266 #ifdef __hpux__
267 #undef d
268 #undef r
269 #endif
270
271 #if defined (__linux__) && defined (__arm__)
272 // <sys/ucontext.h> defines fpregset_t::fpregs::j
273 #undef j
274 #endif
275
276 #if defined (__linux__) && defined (__powerpc__)
277 // <asm/types.h> defines __vector128::u
278 #undef u
279 #endif
280
281 #if defined (__linux__) && defined (__s390__)
282 // <sys/ucontext.h> defines fpreg_t::d and fpreg_t::f
283 #undef d
284 #undef f
285 // <asm/types.h> defines __vector128::u
286 #undef u
287 #endif
288
289 #if defined (__linux__) && defined (__sparc__)
290 #undef y
291 #endif
292
293 #if defined (__linux__) && defined (__ia64__)
294 // <bits/sigcontext.h> defines __ia64_fpreg::u
295 // <sys/ucontext.h> defines __ia64_fpreg_mcontext::u
296 #undef u
297 #endif
298
299 #if defined (__linux__) || defined (__gnu_hurd__)
300 #if __has_include(<features.h>)
301 #include <features.h>
302 #if __GLIBC__ == 2 && (__GLIBC_MINOR__ < 19 || __GLIBC_MINOR__ == 43)
303 // Glibc defines this prior to 2.19
304 #undef __unused
305 #endif
306 #endif
307 #endif
308
309 #if __has_include(<newlib.h>)
310 // newlib's <sys/cdefs.h> defines these as macros.
311 #undef __lockable
312 #undef __packed
313 #undef __unused
314 #undef __used
315 // newlib's <time.h> defines __tzrule_type with these members.
316 #undef d
317 #undef m
318 #undef n
319 #undef s
320 // newlib's <math.h> uses this for parameters
321 #undef x
322 // newlib's <inttypes.h> uses this for parameters
323 #undef j
324 #endif
325
326 #ifdef __sun__
327 // <fenv.h> defines these as members of fex_numeric_t
328 #undef l
329 #undef f
330 #undef d
331 #undef q
332 #undef p
333 // See https://gcc.gnu.org/ml/libstdc++/2019-05/msg00175.html
334 #undef ptr
335 // <sys/timespec_util.h> uses this as parameter
336 #undef r
337 // <stdlib.h> uses this as member of drand48_data
338 #undef x
339 #endif
340
341 #ifdef __VXWORKS__
342
343 #include <_vxworks-versions.h>
344
345 // Some VxWorks 6 or 7 headers are using those.
346
347 // private/objLibP.h
348 #undef u
349
350 // arch/ppc/ffs/ArchLib.h
351 #undef i
352 #undef j
353
354 // math.h
355 #undef x
356 #undef y
357
358 // stdio.h
359 #undef ptr
360
361 // VxWorks >= 7 specificities
362
363 #if _VXWORKS_MAJOR_GE(7)
364
365 // regs.h regs structure has a field 'r'
366 #undef r
367
368 #ifndef __RTP__
369 // in bootLib.h, bootParamCheck has parameters x, a-f
370 #undef a
371 #undef b
372 #undef c
373 #undef d
374 #undef e
375 #undef f
376 // in sysLib.h, func appears as a formal parameter name
377 #undef func
378 #endif // __RTP__
379
380 #endif // VxWorks Major >= 7
381
382 #endif // __VXWORKS__
383
384 #ifdef _WIN32
385 #undef Value
386 // <stdlib.h> defines _CRT_FLOAT::f
387 #undef f
388 // <stdlib.h> defines _CRT_DOUBLE::x and _LONGDOUBLE::x
389 #undef x
390 // <math.h> defines _complex::x and _complex::y
391 #undef y
392 #endif
393
394 #if defined __GLIBC_PREREQ && defined _FORTIFY_SOURCE
395 # if ! __GLIBC_PREREQ(2,41)
396 // https://sourceware.org/bugzilla/show_bug.cgi?id=32052
397 # undef sz
398 # endif
399 #endif
400
401 #include <bits/stdc++.h>