1 /* Test C23 auto. Valid code, compilation tests. */
2 /* { dg-do compile } */
3 /* { dg-options "-std=c23 -pedantic-errors" } */
9 extern auto const d
= 0.0; /* { dg-warning "initialized and declared 'extern'" } */
10 extern const double d
;
14 const auto i3
[[]] = 4;
16 thread_local
auto f
= 1.0f
;
27 extern const volatile long double cvld
;
28 extern void (*tfp
) (void);
38 auto asv
= (struct s
) { 0 };
39 extern typeof (asv
) sv
;
40 auto s2p
= (struct s2
*) 0;
42 auto s3p
= (struct s3
*) 0;
44 static const auto volatile acvld
= 0.5L;
45 extern typeof (acvld
) cvld
;
46 /* lvalue conversion occurs on the initializer, so losing qualifiers. */
48 extern typeof (ncd
) dx
;
49 _Atomic
double ad
= 0.0;
51 extern typeof (nad
) dx
;
52 /* Function-to-pointer conversion occurs on the initializer. */
54 extern typeof (fp
) tfp
;
55 /* Array-to-pointer conversion occurs on the initializer. */
57 extern typeof (aap
) ap
;
58 /* Shadowing a declaration from a containing scope is OK. */
61 /* auto can be used in for loops. */
62 for (auto ix
= 2; ix
< 10; ix
++)
64 extern typeof (ix
) i2
;
66 /* auto is valid with bit-field initializers; the choice of type those have
67 in expressions is unspecified but should match how _Generic handles such
69 struct b
{ int a
: 2; unsigned b
: 3; } bv
= { };
72 static_assert (_Generic (bv
.a
, typeof (bfa
) : 1, default : 2) == 1);
73 static_assert (_Generic (bv
.b
, typeof (bfb
) : 1, default : 2) == 1);
74 /* The traditional meaning of auto with a type specifier is OK. */
77 auto struct t
{ int x
; } t
;
78 /* That includes the case where the type comes from a typedef name. */
79 auto ti int_from_typedef
= 3.0;
80 extern typeof (int_from_typedef
) i2
;