summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/param-type-mismatch.c
blob: 9e654a9e9c65abbe260b01ecb264a421d3109560 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/* { dg-options "-fdiagnostics-show-caret -Wpointer-sign" }  */

/* A collection of calls where argument 2 is of the wrong type.  */

/* decl, with argname.  */

extern int callee_1 (int one, const char *two, float three); /* { dg-line callee_1 } */

int test_1 (int first, int second, float third)
{
  return callee_1 (first, second, third); /* { dg-warning "passing argument 2 of 'callee_1' makes pointer from integer without a cast" }  */
  /* { dg-begin-multiline-output "" }
   return callee_1 (first, second, third);
                           ^~~~~~
                           |
                           int
     { dg-end-multiline-output "" } */
  /* { dg-message "expected 'const char \\*' but argument is of type 'int'" "" { target *-*-* } callee_1 } */
  /* { dg-begin-multiline-output "" }
 extern int callee_1 (int one, const char *two, float three);
                               ~~~~~~~~~~~~^~~
     { dg-end-multiline-output "" } */
}

/* decl, without argname.  */

extern int callee_2 (int, const char *, float); /* { dg-line callee_2 } */

int test_2 (int first, int second, float third)
{
  return callee_2 (first, second, third); /* { dg-warning "passing argument 2 of 'callee_2' makes pointer from integer without a cast" } */
  /* { dg-begin-multiline-output "" }
   return callee_2 (first, second, third);
                           ^~~~~~
                           |
                           int
     { dg-end-multiline-output "" } */
  /* { dg-message "expected 'const char \\*' but argument is of type 'int'" "" { target *-*-* } callee_2 } */
  /* { dg-begin-multiline-output "" }
 extern int callee_2 (int, const char *, float);
                           ^~~~~~~~~~~~
     { dg-end-multiline-output "" } */
}

/* defn, with argname.  */

static int callee_3 (int one, const char *two, float three) /* { dg-line callee_3 } */
{
  return callee_2 (one, two, three);
}

int test_3 (int first, int second, float third)
{
  return callee_3 (first, second, third); // { dg-warning "passing argument 2 of 'callee_3' makes pointer from integer without a cast" }
  /* { dg-begin-multiline-output "" }
   return callee_3 (first, second, third);
                           ^~~~~~
                           |
                           int
     { dg-end-multiline-output "" } */
  /* { dg-message "expected 'const char \\*' but argument is of type 'int'" "" { target *-*-* } callee_3 } */
  /* { dg-begin-multiline-output "" }
 static int callee_3 (int one, const char *two, float three)
                               ~~~~~~~~~~~~^~~
     { dg-end-multiline-output "" } */
}

/* Trivial decl, with argname.  */

extern int callee_4 (int one, float two, float three); /* { dg-line callee_4 } */

int test_4 (int first, const char *second, float third)
{
  return callee_4 (first, second, third); /* { dg-error "incompatible type for argument 2 of 'callee_4'" }  */
  /* { dg-begin-multiline-output "" }
   return callee_4 (first, second, third);
                           ^~~~~~
                           |
                           const char *
     { dg-end-multiline-output "" } */
  /* { dg-message "expected 'float' but argument is of type 'const char \\*'" "" { target *-*-* } callee_4 } */
  /* { dg-begin-multiline-output "" }
 extern int callee_4 (int one, float two, float three);
                               ~~~~~~^~~
     { dg-end-multiline-output "" } */
}

/* Trivial decl, without argname.  */

extern int callee_5 (int, float, float); /* { dg-line callee_5 } */

int test_5 (int first, const char *second, float third)
{
  return callee_5 (first, second, third); /* { dg-error "incompatible type for argument 2 of 'callee_5'" }  */
  /* { dg-begin-multiline-output "" }
   return callee_5 (first, second, third);
                           ^~~~~~
                           |
                           const char *
     { dg-end-multiline-output "" } */
  /* { dg-message "expected 'float' but argument is of type 'const char \\*'" "" { target *-*-* } callee_5 } */
  /* { dg-begin-multiline-output "" }
 extern int callee_5 (int, float, float);
                           ^~~~~
     { dg-end-multiline-output "" } */
}

/* Callback with name.  */

extern int callee_6 (int one, int (*two)(int, int), float three); /* { dg-line callee_6 } */

int test_6 (int first, int second, float third)
{
  return callee_6 (first, second, third); /* { dg-warning "passing argument 2 of 'callee_6' makes pointer from integer without a cast" } */
  /* { dg-begin-multiline-output "" }
   return callee_6 (first, second, third);
                           ^~~~~~
                           |
                           int
     { dg-end-multiline-output "" } */
  /* { dg-message " expected 'int \\(\\*\\)\\(int,  int\\)' but argument is of type 'int'" "" { target *-*-* } callee_6 } */
  /* { dg-begin-multiline-output "" }
 extern int callee_6 (int one, int (*two)(int, int), float three);
                               ~~~~~~^~~~~~~~~~~~~~
     { dg-end-multiline-output "" } */
}

/* Callback without name.  */

extern int callee_7 (int one, int (*)(int, int), float three); /* { dg-line callee_7 } */

int test_7 (int first, int second, float third)
{
  return callee_7 (first, second, third); /* { dg-warning "passing argument 2 of 'callee_7' makes pointer from integer without a cast" } */
  /* { dg-begin-multiline-output "" }
   return callee_7 (first, second, third);
                           ^~~~~~
                           |
                           int
     { dg-end-multiline-output "" } */
  /* { dg-message " expected 'int \\(\\*\\)\\(int,  int\\)' but argument is of type 'int'" "" { target *-*-* } callee_7 } */
  /* { dg-begin-multiline-output "" }
 extern int callee_7 (int one, int (*)(int, int), float three);
                               ^~~~~~~~~~~~~~~~~
     { dg-end-multiline-output "" } */
}

/* -Wincompatible-pointer-types for a parameter.  */

extern int callee_8 (int one, float *two, float (three)); /* { dg-line callee_8 } */

int test_8 (int first, int *second, float third)
{
  return callee_8 (first, second, third); /* { dg-warning "passing argument 2 of 'callee_8' from incompatible pointer type" } */
  /* { dg-begin-multiline-output "" }
   return callee_8 (first, second, third);
                           ^~~~~~
                           |
                           int *
     { dg-end-multiline-output "" } */
  /* { dg-message "expected 'float \\*' but argument is of type 'int \\*'" "" { target *-*-* } callee_8 } */
  /* { dg-begin-multiline-output "" }
 extern int callee_8 (int one, float *two, float (three));
                               ~~~~~~~^~~
     { dg-end-multiline-output "" } */
}

/* -Wpointer-sign for a parameter.  */

extern int callee_9 (int one, int *two, float (three)); /* { dg-line callee_9 } */

int test_9 (int first, unsigned int *second, float third)
{
  return callee_9 (first, second, third); /* { dg-warning "pointer targets in passing argument 2 of 'callee_9' differ in signedness" } */
  /* { dg-begin-multiline-output "" }
   return callee_9 (first, second, third);
                           ^~~~~~
                           |
                           unsigned int *
     { dg-end-multiline-output "" } */
  /* { dg-message "expected 'int \\*' but argument is of type 'unsigned int \\*'" "" { target *-*-* } callee_9 } */
  /* { dg-begin-multiline-output "" }
 extern int callee_9 (int one, int *two, float (three));
                               ~~~~~^~~
     { dg-end-multiline-output "" } */
}