llvm-project
132 строки · 8.1 Кб
1// RUN: %clang_cc1 -fsyntax-only -verify=expected,c23 -std=c23 %s
2// RUN: %clang_cc1 -fsyntax-only -verify=expected,c17 -std=c17 %s
3
4#define AUTO_MACRO(_NAME, ARG, ARG2, ARG3) \
5auto _NAME = ARG + (ARG2 / ARG3);
6
7struct S {
8int a;
9auto b; // c23-error {{'auto' not allowed in struct member}} \
10c17-error {{type name does not allow storage class to be specified}} \
11c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
12union {
13char c;
14auto smth; // c23-error {{'auto' not allowed in union member}} \
15c17-error {{type name does not allow storage class to be specified}} \
16c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
17} u;
18};
19
20enum E : auto { // c23-error {{'auto' not allowed here}} \
21c17-error {{expected a type}} \
22c17-error {{type name does not allow storage class to be specified}}
23One,
24Two,
25Tree,
26};
27
28auto basic_usage(auto auto) { // c23-error {{'auto' not allowed in function prototype}} \
29c23-error {{'auto' not allowed in function return type}} \
30c23-error {{cannot combine with previous 'auto' declaration specifier}} \
31c17-error {{invalid storage class specifier in function declarator}} \
32c17-error {{illegal storage class on function}} \
33c17-warning {{duplicate 'auto' declaration specifier}} \
34c17-warning {{omitting the parameter name in a function definition is a C23 extension}} \
35c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}} \
36c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
37
38auto = 4; // expected-error {{expected identifier or '('}}
39
40auto a = 4; // c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
41
42auto auto aa = 12; // c23-error {{cannot combine with previous 'auto' declaration specifier}} \
43c17-warning {{duplicate 'auto' declaration specifier}} \
44c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
45
46auto b[4]; // c23-error {{'auto' not allowed in array declaration}} \
47c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
48
49auto array[auto]; // expected-error {{expected expression}} \
50c23-error {{declaration of variable 'array' with deduced type 'auto' requires an initializer}} \
51c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
52
53AUTO_MACRO(auto, 1, 2, 3); // c23-error {{cannot combine with previous 'auto' declaration specifier}} \
54expected-error {{expected identifier or '('}} \
55c17-warning {{duplicate 'auto' declaration specifier}}
56
57auto c = (auto)a; // expected-error {{expected expression}} \
58c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
59
60auto ci = (auto){12}; // expected-error {{expected expression}} \
61c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
62
63int auto_cxx_decl = auto(0); // expected-error {{expected expression}}
64
65return c;
66}
67
68void structs(void) {
69struct s_auto { auto a; }; // c23-error {{'auto' not allowed in struct member}} \
70c17-error {{type name does not allow storage class to be specified}} \
71c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
72
73// FIXME: this should end up being rejected when we implement underspecified
74// declarations in N3006.
75auto s_int = (struct { int a; } *)0; // c17-error {{incompatible pointer to integer conversion initializing 'int' with an expression of type}} \
76c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
77
78typedef auto auto_type; // c23-error {{'auto' not allowed in typedef}} \
79c17-error {{cannot combine with previous 'typedef' declaration specifier}} \
80c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
81}
82
83void sizeof_alignas(void) {
84auto auto_size = sizeof(auto); // expected-error {{expected expression}} \
85c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
86}
87
88void generic_alignof_alignas(void) {
89int g;
90_Generic(g, auto : 0); // c23-error {{'auto' not allowed here}} \
91c17-error {{expected a type}} \
92c17-error {{type name does not allow storage class to be specified}}
93
94_Alignof(auto); // expected-error {{expected expression}} \
95expected-warning {{'_Alignof' applied to an expression is a GNU extension}}
96
97_Alignas(auto); // expected-error {{expected expression}} \
98expected-warning {{declaration does not declare anything}}
99}
100
101void function_designators(void) {
102extern auto auto_ret_func(void); // c23-error {{'auto' not allowed in function return type}} \
103c17-error {{cannot combine with previous 'extern' declaration specifier}} \
104c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
105
106extern void auto_param_func(auto); // c23-error {{'auto' not allowed in function prototype}} \
107c17-error {{invalid storage class specifier in function declarator}} \
108c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
109
110auto (auto_ret_func)(void); // c23-error {{'auto' not allowed in function return type}} \
111c17-error {{illegal storage class on function}} \
112c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
113
114void (auto_param_func)(auto); // c23-error {{'auto' not allowed in function prototype}} \
115c17-error {{invalid storage class specifier in function declarator}} \
116c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
117}
118
119void atomic(void) {
120_Atomic(auto) atom1 = 12; // c23-error {{'auto' not allowed here}} \
121c23-error {{a type specifier is required for all declarations}} \
122c17-error {{expected a type}} \
123c17-error {{type name does not allow storage class to be specified}} \
124c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
125
126_Atomic auto atom2 = 12; // c23-error {{_Atomic cannot be applied to type 'auto' in C23}} \
127c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
128}
129
130void attributes(void) {
131auto ident [[clang::annotate("this works")]] = 12; // c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
132}
133