]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/gcc.dg/c2x-auto-3.c
testsuite: Refer more consistently to C23 not C2X
[thirdparty/gcc.git] / gcc / testsuite / gcc.dg / c2x-auto-3.c
CommitLineData
54bac0ce 1/* Test C23 auto. Invalid code. */
e3c898e1 2/* { dg-do compile } */
54bac0ce 3/* { dg-options "-std=c23 -pedantic-errors" } */
e3c898e1
JM
4
5auto; /* { dg-error "empty declaration" } */
6auto *p = (int *) 0; /* { dg-error "plain identifier" } */
7auto i; /* { dg-error "initialized data declaration" } */
8auto g { } /* { dg-error "initialized data declaration" } */
9auto a = 1, b = 2; /* { dg-error "single declarator" } */
10auto long e0 = 0; /* { dg-error "file-scope declaration" } */
11long auto e1 = 0; /* { dg-error "file-scope declaration" } */
12int auto e2 = 0; /* { dg-error "file-scope declaration" } */
13
14extern int e3;
15auto e3 = 1; /* { dg-error "underspecified declaration of 'e3', which is already declared in this scope" } */
16
17void
18f ()
19{
20 extern int fe1;
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
31 diagnostic). */
32 auto fe9 = sizeof (enum { B }); /* { dg-error "defined in underspecified object initializer" } */
33 /* Examples with a forward declaration, then definition inside auto. */
34 struct s3;
35 auto fe10 = (struct s3 { int a; }) { }; /* { dg-error "defined in underspecified object initializer" } */
36 union u3;
37 auto fe11 = (union u3 { int a; }) { }; /* { dg-error "defined in underspecified object initializer" } */
38}
39
40void f2 (auto x); /* { dg-error "storage class specified for parameter" } */
41void f3 (auto y) { } /* { dg-error "storage class specified for parameter" } */
42
43auto e4 = sizeof (e4); /* { dg-error "underspecified 'e4' referenced in its initializer" } */
44__SIZE_TYPE__ e5;
45void
46f4 ()
47{
48 auto e5 = sizeof (e5); /* { dg-error "underspecified 'e5' referenced in its initializer" } */
49}
50
51auto typedef int T; /* { dg-error "'typedef' used with 'auto'" } */
52auto auto e6 = 1; /* { dg-error "duplicate 'auto'" } */
53static 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 } */
57
58typedef auto int T2; /* { dg-error "multiple storage classes in declaration specifiers" } */
59
60void
61f5 ()
62{
63 static int auto e10 = 3; /* { dg-error "multiple storage classes in declaration specifiers" } */
64}
84eb3955
JM
65
66void
67f6 ()
68{
69 static auto l = { 0L }; /* { dg-error "expected expression" } */
70 const auto i3 [[]] = { 4, }; /* { dg-error "expected expression" } */
71}