xref: /llvm-project/clang/test/Preprocessor/macro-reserved.c (revision 844e9534c6d99ddb6bada740839760fa24d17cb6)
1 // RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
2 
3 #define for 0    // expected-warning {{keyword is hidden by macro definition}}
4 #define final 1
5 #define __HAVE_X 0
6 #define __cplusplus
7 #define _HAVE_X 0
8 #define X__Y
9 #define __STDC__ 1 // expected-warning {{redefining builtin macro}}
10 #define __clang__ 1
11 
12 #undef for
13 #undef final
14 #undef __HAVE_X
15 #undef __cplusplus
16 #undef _HAVE_X
17 #undef X__Y
18 #undef __STDC_HOSTED__ // expected-warning {{undefining builtin macro}}
19 #undef __INT32_TYPE__
20 #undef __UINT32_TYPE__
21 #undef __UINTPTR_TYPE__
22 #undef __UINT64_TYPE__
23 #undef __INT64_TYPE__
24 #undef __OPTIMIZE__
25 
26 // allowlisted definitions
27 #define while while
28 #define const
29 #define static
30 #define extern
31 #define inline
32 
33 #undef while
34 #undef const
35 #undef static
36 #undef extern
37 #undef inline
38 
39 #define inline __inline
40 #undef  inline
41 #define inline __inline__
42 #undef  inline
43 
44 #define inline inline__  // expected-warning {{keyword is hidden by macro definition}}
45 #undef  inline
46 #define extern __inline  // expected-warning {{keyword is hidden by macro definition}}
47 #undef  extern
48 #define extern __extern	 // expected-warning {{keyword is hidden by macro definition}}
49 #undef  extern
50 #define extern __extern__ // expected-warning {{keyword is hidden by macro definition}}
51 #undef  extern
52 
53 #define inline _inline   // expected-warning {{keyword is hidden by macro definition}}
54 #undef  inline
55 #define volatile   // expected-warning {{keyword is hidden by macro definition}}
56 #undef  volatile
57 
58 #pragma clang diagnostic warning "-Wreserved-macro-identifier"
59 
60 #define switch if  // expected-warning {{keyword is hidden by macro definition}}
61 #define final 1
62 #define __clusplus // expected-warning {{macro name is a reserved identifier}}
63 #define __HAVE_X 0 // expected-warning {{macro name is a reserved identifier}}
64 #define _HAVE_X 0  // expected-warning {{macro name is a reserved identifier}}
65 #define X__Y
66 
67 #undef switch
68 #undef final
69 #undef __cplusplus // expected-warning {{macro name is a reserved identifier}}
70 #undef _HAVE_X     // expected-warning {{macro name is a reserved identifier}}
71 #undef X__Y
72 
73 int x;
74 
75 #define _GNU_SOURCE          // no-warning
76 #define __STDC_FORMAT_MACROS // no-warning
77