1 /* Test C23 auto. Invalid code. */
2 /* { dg-do compile } */
3 /* { dg-options "-std=c23 -pedantic-errors" } */
5 auto; /* { dg-error "empty declaration" } */
6 auto *p
= (int *) 0; /* { dg-error "plain identifier" } */
7 auto i
; /* { dg-error "initialized data declaration" } */
8 auto g
{ } /* { dg-error "initialized data declaration" } */
9 auto a
= 1, b
= 2; /* { dg-error "single declarator" } */
10 auto long e0
= 0; /* { dg-error "file-scope declaration" } */
11 long auto e1
= 0; /* { dg-error "file-scope declaration" } */
12 int auto e2
= 0; /* { dg-error "file-scope declaration" } */
15 auto e3
= 1; /* { dg-error "underspecified declaration of 'e3', which is already declared in this scope" } */
21 auto fe1
= 1; /* { dg-error "underspecified declaration of 'fe1', which is already declared in this scope" } */
22 /* { dg-error "declaration of 'fe1' with no linkage follows extern declaration" "linkage error" { target *-*-* } .-1 } */
23 auto fe2
= (struct s
*) 0; /* { dg-error "declared in underspecified object initializer" } */
24 auto fe3
= (union u
*) 0; /* { dg-error "declared in underspecified object initializer" } */
25 auto fe4
= (struct s2
{ int a
; }) { }; /* { dg-error "defined in underspecified object initializer" } */
26 auto fe5
= (struct { int a
; }) { }; /* { dg-error "defined in underspecified object initializer" } */
27 auto fe6
= (union u2
{ int a
; }) { }; /* { dg-error "defined in underspecified object initializer" } */
28 auto fe7
= (union { int a
; }) { }; /* { dg-error "defined in underspecified object initializer" } */
29 auto fe8
= sizeof (enum e
{ A
}); /* { dg-error "defined in underspecified object initializer" } */
30 /* The following case is undefined behavior (so doesn't actually require a
32 auto fe9
= sizeof (enum { B
}); /* { dg-error "defined in underspecified object initializer" } */
33 /* Examples with a forward declaration, then definition inside auto. */
35 auto fe10
= (struct s3
{ int a
; }) { }; /* { dg-error "defined in underspecified object initializer" } */
37 auto fe11
= (union u3
{ int a
; }) { }; /* { dg-error "defined in underspecified object initializer" } */
40 void f2 (auto x
); /* { dg-error "storage class specified for parameter" } */
41 void f3 (auto y
) { } /* { dg-error "storage class specified for parameter" } */
43 auto e4
= sizeof (e4
); /* { dg-error "underspecified 'e4' referenced in its initializer" } */
48 auto e5
= sizeof (e5
); /* { dg-error "underspecified 'e5' referenced in its initializer" } */
51 auto typedef int T
; /* { dg-error "'typedef' used with 'auto'" } */
52 auto auto e6
= 1; /* { dg-error "duplicate 'auto'" } */
53 static auto int e7
= 1; /* { dg-error "multiple storage classes in declaration specifiers" } */
54 _Thread_local
auto int e8
= 2; /* { dg-error "'_Thread_local' used with 'auto'" } */
55 _Thread_local
int auto e9
= 3; /* { dg-error "'_Thread_local' used with 'auto'" } */
56 /* { dg-error "file-scope declaration of 'e9' specifies 'auto'" "file-scope error" { target *-*-* } .-1 } */
58 typedef auto int T2
; /* { dg-error "multiple storage classes in declaration specifiers" } */
63 static int auto e10
= 3; /* { dg-error "multiple storage classes in declaration specifiers" } */
69 static auto l
= { 0L }; /* { dg-error "expected expression" } */
70 const auto i3
[[]] = { 4, }; /* { dg-error "expected expression" } */