[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / Sema / reserved-identifier.c
blobfa12a1575a8643a309040788dfdbec2db4424d61
1 // RUN: %clang_cc1 -isystem %S/Inputs -fsyntax-only -verify -Wreserved-identifier -Wno-visibility %s
3 #include <reserved-identifier.h>
5 __I_AM_A_SYSTEM_MACRO() // no-warning
7 void test_system_macro_expansion(void) {
8 SOME_SYSTEM_MACRO(); // no-warning
11 #define __oof foo__ // expected-warning {{macro name is a reserved identifier}}
13 int foo__bar(void) { return 0; } // no-warning
14 static int _bar(void) { return 0; } // expected-warning {{identifier '_bar' is reserved because it starts with '_' at global scope}}
15 static int _Bar(void) { return 0; } // expected-warning {{identifier '_Bar' is reserved because it starts with '_' followed by a capital letter}}
16 int _foo(void) { return 0; } // expected-warning {{identifier '_foo' is reserved because it starts with '_' at global scope}}
18 // This one is explicitly skipped by -Wreserved-identifier
19 void *_; // no-warning
21 void foo(unsigned int _Reserved) { // expected-warning {{identifier '_Reserved' is reserved because it starts with '_' followed by a capital letter}}
22 unsigned int __1 = // expected-warning {{identifier '__1' is reserved because it starts with '__'}}
23 _Reserved; // no-warning
24 goto __reserved; // expected-warning {{identifier '__reserved' is reserved because it starts with '__'}}
25 __reserved: // expected-warning {{identifier '__reserved' is reserved because it starts with '__'}}
27 goto _not_reserved;
28 _not_reserved: ;
31 void foot(unsigned int _not_reserved) {} // no-warning
33 enum __menu { // expected-warning {{identifier '__menu' is reserved because it starts with '__'}}
34 __some, // expected-warning {{identifier '__some' is reserved because it starts with '__'}}
35 _Other, // expected-warning {{identifier '_Other' is reserved because it starts with '_' followed by a capital letter}}
36 _other // expected-warning {{identifier '_other' is reserved because it starts with '_' at global scope}}
39 struct __babar { // expected-warning {{identifier '__babar' is reserved because it starts with '__'}}
42 struct _Zebulon; // expected-warning {{identifier '_Zebulon' is reserved because it starts with '_' followed by a capital letter}}
43 struct _Zebulon2 { // expected-warning {{identifier '_Zebulon2' is reserved because it starts with '_' followed by a capital letter}}
44 } * p;
45 struct _Zebulon3 *pp; // expected-warning {{identifier '_Zebulon3' is reserved because it starts with '_' followed by a capital letter}}
47 typedef struct {
48 int _Field; // expected-warning {{identifier '_Field' is reserved because it starts with '_' followed by a capital letter}}
49 int _field; // no-warning
50 } _Typedef; // expected-warning {{identifier '_Typedef' is reserved because it starts with '_' followed by a capital letter}}
52 int foobar(void) {
53 return foo__bar(); // no-warning
56 struct _reserved { // expected-warning {{identifier '_reserved' is reserved because it starts with '_' at global scope}}
57 int a;
58 } cunf(void) {
59 return (struct _reserved){1};
62 // FIXME: According to clang declaration context layering, _preserved belongs to
63 // the translation unit, so we emit a warning. It's unclear that's what the
64 // standard mandate, but it's such a corner case we can live with it.
65 void func(struct _preserved { int a; } r) {} // expected-warning {{identifier '_preserved' is reserved because it starts with '_' at global scope}}
67 extern char *_strdup(const char *); // expected-warning {{identifier '_strdup' is reserved because it starts with '_' at global scope}}
69 // Don't warn on redeclaration
70 extern char *_strdup(const char *); // no-warning
72 void ok(void) {
73 void _ko(void); // expected-warning {{identifier '_ko' is reserved because it starts with '_' at global scope}}
74 extern int _ko_again; // expected-warning {{identifier '_ko_again' is reserved because it starts with '_' at global scope}}