1 // RUN: %clang_cc1 -fsyntax-only -verify -Wreserved-identifier -Wno-visibility %s
2
3 #define __oof foo__ // expected-warning {{macro name is a reserved identifier}}
4
foo__bar()5 int foo__bar() { return 0; } // no-warning
_bar()6 static int _bar() { return 0; } // expected-warning {{identifier '_bar' is reserved because it starts with '_' at global scope}}
_Bar()7 static int _Bar() { return 0; } // expected-warning {{identifier '_Bar' is reserved because it starts with '_' followed by a capital letter}}
_foo()8 int _foo() { return 0; } // expected-warning {{identifier '_foo' is reserved because it starts with '_' at global scope}}
9
10 // This one is explicitly skipped by -Wreserved-identifier
11 void *_; // no-warning
12
foo(unsigned int _Reserved)13 void foo(unsigned int _Reserved) { // expected-warning {{identifier '_Reserved' is reserved because it starts with '_' followed by a capital letter}}
14 unsigned int __1 = // expected-warning {{identifier '__1' is reserved because it starts with '__'}}
15 _Reserved; // no-warning
16 goto __reserved; // expected-warning {{identifier '__reserved' is reserved because it starts with '__'}}
17 __reserved: // expected-warning {{identifier '__reserved' is reserved because it starts with '__'}}
18 ;
19 }
20
foot(unsigned int _not_reserved)21 void foot(unsigned int _not_reserved) {} // no-warning
22
23 enum __menu { // expected-warning {{identifier '__menu' is reserved because it starts with '__'}}
24 __some, // expected-warning {{identifier '__some' is reserved because it starts with '__'}}
25 _Other, // expected-warning {{identifier '_Other' is reserved because it starts with '_' followed by a capital letter}}
26 _other // expected-warning {{identifier '_other' is reserved because it starts with '_' at global scope}}
27 };
28
29 struct __babar { // expected-warning {{identifier '__babar' is reserved because it starts with '__'}}
30 };
31
32 struct _Zebulon; // expected-warning {{identifier '_Zebulon' is reserved because it starts with '_' followed by a capital letter}}
33 struct _Zebulon2 { // expected-warning {{identifier '_Zebulon2' is reserved because it starts with '_' followed by a capital letter}}
34 } * p;
35 struct _Zebulon3 *pp; // expected-warning {{identifier '_Zebulon3' is reserved because it starts with '_' followed by a capital letter}}
36
37 typedef struct {
38 int _Field; // expected-warning {{identifier '_Field' is reserved because it starts with '_' followed by a capital letter}}
39 int _field; // no-warning
40 } _Typedef; // expected-warning {{identifier '_Typedef' is reserved because it starts with '_' followed by a capital letter}}
41
foobar()42 int foobar() {
43 return foo__bar(); // no-warning
44 }
45
46 struct _reserved { // expected-warning {{identifier '_reserved' is reserved because it starts with '_' at global scope}}
47 int a;
cunf(void)48 } cunf(void) {
49 return (struct _reserved){1};
50 }
51
52 // FIXME: According to clang declaration context layering, _preserved belongs to
53 // the translation unit, so we emit a warning. It's unclear that's what the
54 // standard mandate, but it's such a corner case we can live with it.
func(struct _preserved{ int a; } r)55 void func(struct _preserved { int a; } r) {} // expected-warning {{identifier '_preserved' is reserved because it starts with '_' at global scope}}
56
57 extern char *_strdup(const char *); // expected-warning {{identifier '_strdup' is reserved because it starts with '_' at global scope}}
58
59 // Don't warn on redecleration
60 extern char *_strdup(const char *); // no-warning
61
ok()62 void ok() {
63 void _ko(); // expected-warning {{identifier '_ko' is reserved because it starts with '_' at global scope}}
64 extern int _ko_again; // expected-warning {{identifier '_ko_again' is reserved because it starts with '_' at global scope}}
65 }
66