comparison 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
comparison
equal deleted inserted replaced
68:561a7518be6b 111:04ced10e8804
1 /* PR c/81233 */
2 /* { dg-do compile } */
3 /* { dg-options "-Wc++-compat -Wpedantic" } */
4 /* Test we're printing the types, like the good compiler we are. */
5
6 enum E1 { A } e;
7 enum E2 { B };
8 extern void foo_E (enum E1); /* { dg-message "expected 'enum E1' but argument is of type 'int'" } */
9 extern void foo (char *); /* { dg-message "expected 'char \\*' but argument is of type 'int \\*'" } */
10 extern void foo2 (int *); /* { dg-message "expected 'int \\*' but argument is of type 'int'" } */
11 extern void foo3 (int); /* { dg-message "expected 'int' but argument is of type 'int \\*'" } */
12 extern void foo4 (int *); /* { dg-message "expected 'int \\*' but argument is of type 'unsigned int \\*'" } */
13
14 char *
15 fn0 (int *p, char *q)
16 {
17 p = q; /* { dg-warning "assignment to 'int \\*' from incompatible pointer type 'char \\*'" } */
18 int *r = q; /* { dg-warning "initialization of 'int \\*' from incompatible pointer type 'char \\*'" } */
19 foo (r); /* { dg-warning "passing argument 1 of 'foo' from incompatible pointer type" } */
20 return p; /* { dg-warning "returning 'int \\*' from a function with incompatible return type 'char \\*'" } */
21 }
22
23 int *
24 fn1 (int *p)
25 {
26 p = 1; /* { dg-warning "assignment to 'int \\*' from 'int' makes pointer from integer without a cast" } */
27 int *q = 1; /* { dg-warning "initialization of 'int \\*' from 'int' makes pointer from integer without a cast" } */
28 foo2 (1); /* { dg-warning "passing argument 1 of 'foo2' makes pointer from integer without a cast" } */
29 return 1; /* { dg-warning "returning 'int' from a function with return type 'int \\*' makes pointer from integer without a cast" } */
30 }
31
32 int
33 fn2 (int i, int *p)
34 {
35 i = p; /* { dg-warning "assignment to 'int' from 'int \\*' makes integer from pointer without a cast" } */
36 int j = p; /* { dg-warning "initialization of 'int' from 'int \\*' makes integer from pointer without a cast" } */
37 foo3 (p); /* { dg-warning "passing argument 1 of 'foo3' makes integer from pointer without a cast" } */
38 return p; /* { dg-warning "returning 'int \\*' from a function with return type 'int' makes integer from pointer without a cast" } */
39 }
40
41 int *
42 fn3 (int *p, unsigned int *u)
43 {
44 p = u; /* { dg-warning "pointer targets in assignment from 'unsigned int \\*' to 'int \\*' differ in signedness" } */
45 int *q = u; /* { dg-warning "pointer targets in initialization of 'int \\*' from 'unsigned int \\*' differ in signedness" } */
46 foo4 (u); /* { dg-warning "pointer targets in passing argument 1 of 'foo4' differ in signedness" } */
47 return u; /* { dg-warning "pointer targets in returning 'unsigned int \\*' from a function with return type 'int \\*' differ in signedness" } */
48 }
49
50 enum E1
51 fn4 (void)
52 {
53 foo_E (B); /* { dg-warning "enum conversion when passing argument" } */
54 e = 0; /* { dg-warning "enum conversion from 'int' to 'enum E1' in assignment is invalid" } */
55 enum E1 f = 0; /* { dg-warning "enum conversion from 'int' to 'enum E1' in initialization is invalid" } */
56 return 0; /* { dg-warning "enum conversion from 'int' to 'enum E1' in return is invalid" } */
57 }