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