Debian Codegraph @

clang/test/Sema/incomplete-decl.c

raw
1 // RUN: %clang_cc1 -fsyntax-only -verify=c,expected %s
2 // RUN: %clang_cc1 -x c++ -fsyntax-only -verify=cxx,expected %s
3
4
5
6 struct foo; // c-note 4 {{forward declaration of 'struct foo'}} \
7 cxx-note 3 {{forward declaration of 'foo'}}
8
9 void b; // expected-error {{variable has incomplete type 'void'}}
10 struct foo f; // c-error {{tentative definition has type 'struct foo' that is never completed}} \
11 cxx-error {{variable has incomplete type 'struct foo'}}
12
13 static void c; // expected-error {{variable has incomplete type 'void'}}
14 static struct foo g; // c-error {{tentative definition has type 'struct foo' that is never completed}} \
15 cxx-error {{variable has incomplete type 'struct foo'}}
16
17 extern void d; // cxx-error {{variable has incomplete type 'void'}}
18 extern struct foo e;
19
20 int ary[]; // c-warning {{tentative array definition assumed to have one element}} \
21 cxx-error {{definition of variable with array type needs an explicit size or an initializer}}
22 struct foo bary[]; // c-error {{array has incomplete element type 'struct foo'}} \
23 cxx-error {{definition of variable with array type needs an explicit size or an initializer}}
24
25 void func(void) {
26 int ary[]; // expected-error {{definition of variable with array type needs an explicit size or an initializer}}
27 void b; // expected-error {{variable has incomplete type 'void'}}
28 struct foo f; // expected-error {{variable has incomplete type 'struct foo'}}
29 }
30
31 int h[]; // c-warning {{tentative array definition assumed to have one element}} \
32 cxx-error {{definition of variable with array type needs an explicit size or an initializer}}
33 int (*i)[] = &h+1; // c-error {{arithmetic on a pointer to an incomplete type 'int[]'}}
34
35 struct bar j = {1}; // expected-error {{variable has incomplete type 'struct bar'}} \
36 c-note {{forward declaration of 'struct bar'}} \
37 cxx-note 2 {{forward declaration of 'bar'}}
38
39 struct bar k; // cxx-error {{variable has incomplete type 'struct bar'}}
40 struct bar { int a; };
41
42 struct x y; //c-note 2 {{forward declaration of 'struct x'}} \
43 cxx-error {{variable has incomplete type 'struct x'}} \
44 cxx-note {{forward declaration of 'x'}}
45 void foo() {
46 (void)(1 ? y : y); // c-error 2 {{incomplete type 'struct x' where a complete type is required}}
47 }
48 struct x{
49 int a;
50 };