annotate gcc/testsuite/gcc.dg/diagnostic-types-1.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* PR c/81233 */
kono
parents:
diff changeset
2 /* { dg-do compile } */
kono
parents:
diff changeset
3 /* { dg-options "-Wc++-compat -Wpedantic" } */
kono
parents:
diff changeset
4 /* Test we're printing the types, like the good compiler we are. */
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 enum E1 { A } e;
kono
parents:
diff changeset
7 enum E2 { B };
kono
parents:
diff changeset
8 extern void foo_E (enum E1); /* { dg-message "expected 'enum E1' but argument is of type 'int'" } */
kono
parents:
diff changeset
9 extern void foo (char *); /* { dg-message "expected 'char \\*' but argument is of type 'int \\*'" } */
kono
parents:
diff changeset
10 extern void foo2 (int *); /* { dg-message "expected 'int \\*' but argument is of type 'int'" } */
kono
parents:
diff changeset
11 extern void foo3 (int); /* { dg-message "expected 'int' but argument is of type 'int \\*'" } */
kono
parents:
diff changeset
12 extern void foo4 (int *); /* { dg-message "expected 'int \\*' but argument is of type 'unsigned int \\*'" } */
kono
parents:
diff changeset
13
kono
parents:
diff changeset
14 char *
kono
parents:
diff changeset
15 fn0 (int *p, char *q)
kono
parents:
diff changeset
16 {
kono
parents:
diff changeset
17 p = q; /* { dg-warning "assignment to 'int \\*' from incompatible pointer type 'char \\*'" } */
kono
parents:
diff changeset
18 int *r = q; /* { dg-warning "initialization of 'int \\*' from incompatible pointer type 'char \\*'" } */
kono
parents:
diff changeset
19 foo (r); /* { dg-warning "passing argument 1 of 'foo' from incompatible pointer type" } */
kono
parents:
diff changeset
20 return p; /* { dg-warning "returning 'int \\*' from a function with incompatible return type 'char \\*'" } */
kono
parents:
diff changeset
21 }
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 int *
kono
parents:
diff changeset
24 fn1 (int *p)
kono
parents:
diff changeset
25 {
kono
parents:
diff changeset
26 p = 1; /* { dg-warning "assignment to 'int \\*' from 'int' makes pointer from integer without a cast" } */
kono
parents:
diff changeset
27 int *q = 1; /* { dg-warning "initialization of 'int \\*' from 'int' makes pointer from integer without a cast" } */
kono
parents:
diff changeset
28 foo2 (1); /* { dg-warning "passing argument 1 of 'foo2' makes pointer from integer without a cast" } */
kono
parents:
diff changeset
29 return 1; /* { dg-warning "returning 'int' from a function with return type 'int \\*' makes pointer from integer without a cast" } */
kono
parents:
diff changeset
30 }
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 int
kono
parents:
diff changeset
33 fn2 (int i, int *p)
kono
parents:
diff changeset
34 {
kono
parents:
diff changeset
35 i = p; /* { dg-warning "assignment to 'int' from 'int \\*' makes integer from pointer without a cast" } */
kono
parents:
diff changeset
36 int j = p; /* { dg-warning "initialization of 'int' from 'int \\*' makes integer from pointer without a cast" } */
kono
parents:
diff changeset
37 foo3 (p); /* { dg-warning "passing argument 1 of 'foo3' makes integer from pointer without a cast" } */
kono
parents:
diff changeset
38 return p; /* { dg-warning "returning 'int \\*' from a function with return type 'int' makes integer from pointer without a cast" } */
kono
parents:
diff changeset
39 }
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 int *
kono
parents:
diff changeset
42 fn3 (int *p, unsigned int *u)
kono
parents:
diff changeset
43 {
kono
parents:
diff changeset
44 p = u; /* { dg-warning "pointer targets in assignment from 'unsigned int \\*' to 'int \\*' differ in signedness" } */
kono
parents:
diff changeset
45 int *q = u; /* { dg-warning "pointer targets in initialization of 'int \\*' from 'unsigned int \\*' differ in signedness" } */
kono
parents:
diff changeset
46 foo4 (u); /* { dg-warning "pointer targets in passing argument 1 of 'foo4' differ in signedness" } */
kono
parents:
diff changeset
47 return u; /* { dg-warning "pointer targets in returning 'unsigned int \\*' from a function with return type 'int \\*' differ in signedness" } */
kono
parents:
diff changeset
48 }
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 enum E1
kono
parents:
diff changeset
51 fn4 (void)
kono
parents:
diff changeset
52 {
kono
parents:
diff changeset
53 foo_E (B); /* { dg-warning "enum conversion when passing argument" } */
kono
parents:
diff changeset
54 e = 0; /* { dg-warning "enum conversion from 'int' to 'enum E1' in assignment is invalid" } */
kono
parents:
diff changeset
55 enum E1 f = 0; /* { dg-warning "enum conversion from 'int' to 'enum E1' in initialization is invalid" } */
kono
parents:
diff changeset
56 return 0; /* { dg-warning "enum conversion from 'int' to 'enum E1' in return is invalid" } */
kono
parents:
diff changeset
57 }