1 // RUN: %clang_cc1 -fsyntax-only -verify=expected,c23 -std=c23 %s
2 // RUN: %clang_cc1 -fsyntax-only -verify=expected,c17 -std=c17 %s
4 #define AUTO_MACRO(_NAME, ARG, ARG2, ARG3) \
5 auto _NAME = ARG + (ARG2 / ARG3);
9 auto b
; // c23-error {{'auto' not allowed in struct member}} \
10 c17
-error
{{type name does
not allow storage
class to be specified
}} \
11 c17
-error
{{type specifier missing
, defaults to
'int'; ISO C99
and later
do not support implicit
int}}
14 auto smth
; // c23-error {{'auto' not allowed in union member}} \
15 c17
-error
{{type name does
not allow storage
class to be specified
}} \
16 c17
-error
{{type specifier missing
, defaults to
'int'; ISO C99
and later
do not support implicit
int}}
20 enum E
: auto { // c23-error {{'auto' not allowed here}} \
21 c17
-error
{{expected a type
}} \
22 c17
-error
{{type name does
not allow storage
class to be specified
}}
28 auto basic_usage(auto auto) { // c23-error {{'auto' not allowed in function prototype}} \
29 c23
-error
{{'auto' not allowed in function
return type
}} \
30 c23
-error
{{cannot combine with previous
'auto' declaration specifier
}} \
31 c17
-error
{{invalid storage
class specifier in function declarator
}} \
32 c17
-error
{{illegal storage
class on function
}} \
33 c17
-warning
{{duplicate
'auto' declaration specifier
}} \
34 c17
-warning
{{omitting the parameter name in a function definition is a C23 extension
}} \
35 c17
-error
{{type specifier missing
, defaults to
'int'; ISO C99
and later
do not support implicit
int}} \
36 c17
-error
{{type specifier missing
, defaults to
'int'; ISO C99
and later
do not support implicit
int}}
38 auto = 4; // expected-error {{expected identifier or '('}}
40 auto a
= 4; // c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
42 auto auto aa
= 12; // c23-error {{cannot combine with previous 'auto' declaration specifier}} \
43 c17
-warning
{{duplicate
'auto' declaration specifier
}} \
44 c17
-error
{{type specifier missing
, defaults to
'int'; ISO C99
and later
do not support implicit
int}}
46 auto b
[4]; // c23-error {{'auto' not allowed in array declaration}} \
47 c17
-error
{{type specifier missing
, defaults to
'int'; ISO C99
and later
do not support implicit
int}}
49 auto array
[auto]; // expected-error {{expected expression}} \
50 c23
-error
{{declaration of variable
'array' with deduced type
'auto' requires an initializer
}} \
51 c17
-error
{{type specifier missing
, defaults to
'int'; ISO C99
and later
do not support implicit
int}}
53 AUTO_MACRO(auto, 1, 2, 3); // c23-error {{cannot combine with previous 'auto' declaration specifier}} \
54 expected
-error
{{expected identifier
or '('}} \
55 c17
-warning
{{duplicate
'auto' declaration specifier
}}
57 auto c
= (auto)a
; // expected-error {{expected expression}} \
58 c17
-error
{{type specifier missing
, defaults to
'int'; ISO C99
and later
do not support implicit
int}}
60 auto ci
= (auto){12}; // expected-error {{expected expression}} \
61 c17
-error
{{type specifier missing
, defaults to
'int'; ISO C99
and later
do not support implicit
int}}
63 int auto_cxx_decl
= auto(0); // expected-error {{expected expression}}
69 struct s_auto
{ auto a
; }; // c23-error {{'auto' not allowed in struct member}} \
70 c17
-error
{{type name does
not allow storage
class to be specified
}} \
71 c17
-error
{{type specifier missing
, defaults to
'int'; ISO C99
and later
do not support implicit
int}}
73 // FIXME: this should end up being rejected when we implement underspecified
74 // declarations in N3006.
75 auto s_int
= (struct { int a
; } *)0; // c17-error {{incompatible pointer to integer conversion initializing 'int' with an expression of type}} \
76 c17
-error
{{type specifier missing
, defaults to
'int'; ISO C99
and later
do not support implicit
int}}
78 typedef auto auto_type
; // c23-error {{'auto' not allowed in typedef}} \
79 c17
-error
{{cannot combine with previous
'typedef' declaration specifier
}} \
80 c17
-error
{{type specifier missing
, defaults to
'int'; ISO C99
and later
do not support implicit
int}}
83 void sizeof_alignas(void) {
84 auto auto_size
= sizeof(auto); // expected-error {{expected expression}} \
85 c17
-error
{{type specifier missing
, defaults to
'int'; ISO C99
and later
do not support implicit
int}}
88 void generic_alignof_alignas(void) {
90 _Generic(g
, auto : 0); // c23-error {{'auto' not allowed here}} \
91 c17
-error
{{expected a type
}} \
92 c17
-error
{{type name does
not allow storage
class to be specified
}}
94 _Alignof(auto); // expected-error {{expected expression}} \
95 expected
-warning
{{'_Alignof' applied to an expression is a GNU extension
}}
97 _Alignas(auto); // expected-error {{expected expression}} \
98 expected
-warning
{{declaration does
not declare anything
}}
101 void function_designators(void) {
102 extern auto auto_ret_func(void); // c23-error {{'auto' not allowed in function return type}} \
103 c17
-error
{{cannot combine with previous
'extern' declaration specifier
}} \
104 c17
-error
{{type specifier missing
, defaults to
'int'; ISO C99
and later
do not support implicit
int}}
106 extern void auto_param_func(auto); // c23-error {{'auto' not allowed in function prototype}} \
107 c17
-error
{{invalid storage
class specifier in function declarator
}} \
108 c17
-error
{{type specifier missing
, defaults to
'int'; ISO C99
and later
do not support implicit
int}}
110 auto (auto_ret_func
)(void); // c23-error {{'auto' not allowed in function return type}} \
111 c17
-error
{{illegal storage
class on function
}} \
112 c17
-error
{{type specifier missing
, defaults to
'int'; ISO C99
and later
do not support implicit
int}}
114 void (auto_param_func
)(auto); // c23-error {{'auto' not allowed in function prototype}} \
115 c17
-error
{{invalid storage
class specifier in function declarator
}} \
116 c17
-error
{{type specifier missing
, defaults to
'int'; ISO C99
and later
do not support implicit
int}}
120 _Atomic(auto) atom1
= 12; // c23-error {{'auto' not allowed here}} \
121 c23
-error
{{a type specifier is required
for all declarations
}} \
122 c17
-error
{{expected a type
}} \
123 c17
-error
{{type name does
not allow storage
class to be specified
}} \
124 c17
-error
{{type specifier missing
, defaults to
'int'; ISO C99
and later
do not support implicit
int}}
126 _Atomic
auto atom2
= 12; // c23-error {{_Atomic cannot be applied to type 'auto' in C23}} \
127 c17
-error
{{type specifier missing
, defaults to
'int'; ISO C99
and later
do not support implicit
int}}
130 void attributes(void) {
131 auto ident
[[clang::annotate("this works")]] = 12; // c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}