| 1 |
/* { dg-options "-std=gnu89 -pedantic-errors" } */ |
| 2 |
|
| 3 |
/* Overview test for C permerrors. This test should be kept in sync with the |
| 4 |
other permerror-* tests. If new permerrors are added, test cases should be |
| 5 |
added to this and the other files. */ |
| 6 |
|
| 7 |
void |
| 8 |
implicit_function_declaration (void) |
| 9 |
{ |
| 10 |
f1 (); /* { dg-bogus "-Wimplicit-function-declaration" } */ |
| 11 |
} |
| 12 |
|
| 13 |
extern implicit_int_1; /* { dg-bogus "-Wimplicit-int" } */ |
| 14 |
typedef implicit_int_2; /* { dg-bogus "-Wimplicit-int" } */ |
| 15 |
extern implicit_int_3 (void); /* { dg-bogus "-Wimplicit-int" } */ |
| 16 |
implicit_int_4 (i) /* { dg-bogus "-Wimplicit-int" } */ |
| 17 |
/* Directive here in the other files. */ |
| 18 |
{ |
| 19 |
(const) 0; /* { dg-bogus "-Wimplicit-int" } */ |
| 20 |
} |
| 21 |
|
| 22 |
extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(without types\\\) in function declaration \\\[-Wdeclaration-missing-parameter-type\\\]" } */ |
| 23 |
|
| 24 |
|
| 25 |
int * |
| 26 |
int_conversion_1 (int flag) |
| 27 |
{ |
| 28 |
void f2 (int *); |
| 29 |
flag ? "1" : 1; /* { dg-error "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" } */ |
| 30 |
flag ? 1 : "1"; /* { dg-error "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" } */ |
| 31 |
f2 (flag); /* { dg-error "passing argument 1 of 'f2' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */ |
| 32 |
{ |
| 33 |
int i1 = &flag; /* { dg-error "initialization of 'int' from 'int \\\*' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */ |
| 34 |
i1 = &flag; /* { dg-error "assignment to 'int' from 'int \\\*' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */ |
| 35 |
} |
| 36 |
return flag; /* { dg-error "returning 'int' from a function with return type 'int \\\*' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */ |
| 37 |
} |
| 38 |
|
| 39 |
int |
| 40 |
int_conversion_2 (int flag) |
| 41 |
{ |
| 42 |
void f3 (int); |
| 43 |
f3 (&flag); /* { dg-error "passing argument 1 of 'f3' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */ |
| 44 |
{ |
| 45 |
int *i1 = flag; /* { dg-error "initialization of 'int \\\*' from 'int' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */ |
| 46 |
i1 = flag; /* { dg-error "assignment to 'int \\\*' from 'int' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */ |
| 47 |
} |
| 48 |
return &flag; /* { dg-error "returning 'int \\\*' from a function with return type 'int' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */ |
| 49 |
} |
| 50 |
|
| 51 |
int * |
| 52 |
incompatible_pointer_types (int flag) |
| 53 |
{ |
| 54 |
void f4 (int *); |
| 55 |
flag ? __builtin_abs : __builtin_labs; /* { dg-warning "pointer type mismatch in conditional expression \\\[-Wincompatible-pointer-types\\\]" } */ |
| 56 |
{ |
| 57 |
int *p1 = __builtin_abs; /* { dg-error "initialization of 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ |
| 58 |
p1 = __builtin_abs; /* { dg-error "assignment to 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ |
| 59 |
} |
| 60 |
{ |
| 61 |
int *p2 = incompatible_pointer_types; /* { dg-error "initialization of 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ |
| 62 |
p2 = incompatible_pointer_types; /* { dg-error "assignment to 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ |
| 63 |
{ |
| 64 |
int *p3 = &p2; /* { dg-error "initialization of 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */ |
| 65 |
p3 = &p2; /* { dg-error "assignment to 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */ |
| 66 |
} |
| 67 |
f4 (&p2); /* { dg-error "passing argument 1 of 'f4' from incompatible pointer type \\\[-Wincompatible-pointer-types\\\]" } */ |
| 68 |
} |
| 69 |
if (flag) |
| 70 |
return __builtin_abs; /* { dg-error "returning pointer to '__builtin_abs' of type 'int \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */ |
| 71 |
else |
| 72 |
return incompatible_pointer_types; /* { dg-error "returning 'int \\\* \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible return type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */ |
| 73 |
} |
| 74 |
|
| 75 |
void |
| 76 |
return_mismatch_1 (void) |
| 77 |
{ |
| 78 |
return 0; /* { dg-error "'return' with a value, in function returning void \\\[-Wreturn-mismatch\\\]" } */ |
| 79 |
} |
| 80 |
|
| 81 |
int |
| 82 |
return_mismatch_2 (void) |
| 83 |
{ |
| 84 |
return; /* { dg-bogus "-Wreturn-mismatch" } */ |
| 85 |
} |