annotate clang/test/Sema/function.c @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents 0572611fdcc8
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1 // RUN: %clang_cc1 %s -fsyntax-only -verify -verify=c2x -pedantic
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
2 // RUN: %clang_cc1 %s -fsyntax-only -std=c2x -verify -pedantic
150
anatofuz
parents:
diff changeset
3
anatofuz
parents:
diff changeset
4 // PR1892, PR11354
anatofuz
parents:
diff changeset
5 void f(double a[restrict][5]) { __typeof(a) x = 10; } // expected-warning {{(aka 'double (*restrict)[5]')}}
anatofuz
parents:
diff changeset
6
anatofuz
parents:
diff changeset
7 int foo (__const char *__path);
anatofuz
parents:
diff changeset
8 int foo(__const char *__restrict __file);
anatofuz
parents:
diff changeset
9
anatofuz
parents:
diff changeset
10 void func(const char*); // expected-note {{previous declaration is here}}
anatofuz
parents:
diff changeset
11 void func(char*); // expected-error{{conflicting types for 'func'}}
anatofuz
parents:
diff changeset
12
anatofuz
parents:
diff changeset
13 void g(int (*)(const void **, const void **));
anatofuz
parents:
diff changeset
14 void g(int (*compar)()) {
anatofuz
parents:
diff changeset
15 }
anatofuz
parents:
diff changeset
16
anatofuz
parents:
diff changeset
17 void h(); // expected-note {{previous declaration is here}}
anatofuz
parents:
diff changeset
18 void h (const char *fmt, ...) {} // expected-error{{conflicting types for 'h'}}
anatofuz
parents:
diff changeset
19
anatofuz
parents:
diff changeset
20 // PR1965
anatofuz
parents:
diff changeset
21 int t5(b); // expected-error {{parameter list without types}}
anatofuz
parents:
diff changeset
22 int t6(int x, g); // expected-warning {{type specifier missing, defaults to 'int'}}
anatofuz
parents:
diff changeset
23
anatofuz
parents:
diff changeset
24 int t7(, ); // expected-error {{expected parameter declarator}} expected-error {{expected parameter declarator}}
anatofuz
parents:
diff changeset
25 int t8(, int a); // expected-error {{expected parameter declarator}}
anatofuz
parents:
diff changeset
26 int t9(int a, ); // expected-error {{expected parameter declarator}}
anatofuz
parents:
diff changeset
27
anatofuz
parents:
diff changeset
28
anatofuz
parents:
diff changeset
29 // PR2042
anatofuz
parents:
diff changeset
30 void t10(){}
anatofuz
parents:
diff changeset
31 void t11(){t10(1);} // expected-warning{{too many arguments}}
anatofuz
parents:
diff changeset
32
anatofuz
parents:
diff changeset
33 // PR3208
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
34 void t12(int) {} // c2x-warning{{omitting the parameter name in a function definition is a C2x extension}}
150
anatofuz
parents:
diff changeset
35
anatofuz
parents:
diff changeset
36 // PR2790
anatofuz
parents:
diff changeset
37 void t13() {
anatofuz
parents:
diff changeset
38 return 0; // expected-error {{void function 't13' should not return a value}}
anatofuz
parents:
diff changeset
39 }
anatofuz
parents:
diff changeset
40 int t14() {
anatofuz
parents:
diff changeset
41 return; // expected-error {{non-void function 't14' should return a value}}
anatofuz
parents:
diff changeset
42 }
anatofuz
parents:
diff changeset
43
anatofuz
parents:
diff changeset
44 // <rdar://problem/6097326>
anatofuz
parents:
diff changeset
45 y(y) { return y; } // expected-warning{{parameter 'y' was not declared, defaulting to type 'int'}} \
anatofuz
parents:
diff changeset
46 // expected-warning{{type specifier missing, defaults to 'int'}}
anatofuz
parents:
diff changeset
47
anatofuz
parents:
diff changeset
48
anatofuz
parents:
diff changeset
49 // PR3137, <rdar://problem/6127293>
anatofuz
parents:
diff changeset
50 extern int g0_3137(void);
anatofuz
parents:
diff changeset
51 void f0_3137() {
anatofuz
parents:
diff changeset
52 int g0_3137(void);
anatofuz
parents:
diff changeset
53 }
anatofuz
parents:
diff changeset
54 void f1_3137() {
anatofuz
parents:
diff changeset
55 int (*fp)(void) = g0_3137;
anatofuz
parents:
diff changeset
56 }
anatofuz
parents:
diff changeset
57
anatofuz
parents:
diff changeset
58 void f1static() {
anatofuz
parents:
diff changeset
59 static void f2static(int); // expected-error{{function declared in block scope cannot have 'static' storage class}}
anatofuz
parents:
diff changeset
60 register void f2register(int); // expected-error{{illegal storage class on function}}
anatofuz
parents:
diff changeset
61 }
anatofuz
parents:
diff changeset
62
anatofuz
parents:
diff changeset
63 struct incomplete_test a(void) {} // expected-error{{incomplete result type 'struct incomplete_test' in function definition}} \
anatofuz
parents:
diff changeset
64 // expected-note{{forward declaration of 'struct incomplete_test'}}
anatofuz
parents:
diff changeset
65
anatofuz
parents:
diff changeset
66
anatofuz
parents:
diff changeset
67 extern __inline
anatofuz
parents:
diff changeset
68 __attribute__((__gnu_inline__))
anatofuz
parents:
diff changeset
69 void gnu_inline1() {}
anatofuz
parents:
diff changeset
70
anatofuz
parents:
diff changeset
71 void
anatofuz
parents:
diff changeset
72 __attribute__((__gnu_inline__)) // expected-warning {{'gnu_inline' attribute requires function to be marked 'inline', attribute ignored}}
anatofuz
parents:
diff changeset
73 gnu_inline2() {}
anatofuz
parents:
diff changeset
74
anatofuz
parents:
diff changeset
75
anatofuz
parents:
diff changeset
76 // rdar://6802350
anatofuz
parents:
diff changeset
77 inline foo_t invalid_type() { // expected-error {{unknown type name 'foo_t'}}
anatofuz
parents:
diff changeset
78 }
anatofuz
parents:
diff changeset
79
anatofuz
parents:
diff changeset
80 typedef void fn_t(void);
anatofuz
parents:
diff changeset
81 fn_t t17;
anatofuz
parents:
diff changeset
82
anatofuz
parents:
diff changeset
83 // PR4049
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
84 unknown_type t18(void*) { // expected-error {{unknown type name 'unknown_type'}} \
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
85 // c2x-warning {{omitting the parameter name in a function definition is a C2x extension}}
150
anatofuz
parents:
diff changeset
86 }
anatofuz
parents:
diff changeset
87
anatofuz
parents:
diff changeset
88 unknown_type t19(int* P) { // expected-error {{unknown type name 'unknown_type'}}
anatofuz
parents:
diff changeset
89 P = P+1; // no warning.
anatofuz
parents:
diff changeset
90 }
anatofuz
parents:
diff changeset
91
anatofuz
parents:
diff changeset
92 // missing ',' before '...'
anatofuz
parents:
diff changeset
93 void t20(int i...) { } // expected-error {{requires a comma}}
anatofuz
parents:
diff changeset
94
anatofuz
parents:
diff changeset
95 int n;
anatofuz
parents:
diff changeset
96 void t21(int n, int (*array)[n]);
anatofuz
parents:
diff changeset
97
anatofuz
parents:
diff changeset
98 int func_e(int x) {
anatofuz
parents:
diff changeset
99 int func_n(int y) { // expected-error {{function definition is not allowed here}}
anatofuz
parents:
diff changeset
100 if (y > 22) {
anatofuz
parents:
diff changeset
101 return y+2;
anatofuz
parents:
diff changeset
102 } else {
anatofuz
parents:
diff changeset
103 return y-2;
anatofuz
parents:
diff changeset
104 }
anatofuz
parents:
diff changeset
105 }
anatofuz
parents:
diff changeset
106 return x + 3;
anatofuz
parents:
diff changeset
107 }
anatofuz
parents:
diff changeset
108
anatofuz
parents:
diff changeset
109 void decays(int a[3][3]); // expected-note {{passing argument to parameter 'a' here}}
anatofuz
parents:
diff changeset
110 void no_decay(int (*a)[3]); // expected-note {{passing argument to parameter 'a' here}}
anatofuz
parents:
diff changeset
111
anatofuz
parents:
diff changeset
112 void t22(int *ptr, int (*array)[3]) {
anatofuz
parents:
diff changeset
113 decays(ptr); // expected-warning {{incompatible pointer types passing 'int *' to parameter of type 'int (*)[3]'}}
anatofuz
parents:
diff changeset
114 no_decay(ptr); // expected-warning {{incompatible pointer types passing 'int *' to parameter of type 'int (*)[3]'}}
anatofuz
parents:
diff changeset
115 decays(array);
anatofuz
parents:
diff changeset
116 no_decay(array);
anatofuz
parents:
diff changeset
117 }
anatofuz
parents:
diff changeset
118
anatofuz
parents:
diff changeset
119 void const Bar (void); // ok on decl
anatofuz
parents:
diff changeset
120 // PR 20146
anatofuz
parents:
diff changeset
121 void const Bar (void) // expected-warning {{function cannot return qualified void type 'const void'}}
anatofuz
parents:
diff changeset
122 {
anatofuz
parents:
diff changeset
123 }