]>
Commit | Line | Data |
---|---|---|
8d08fdba MS |
1 | /* Report error messages, build initializers, and perform |
2 | some front-end optimizations for C++ compiler. | |
66543169 | 3 | Copyright (C) 1987, 88, 89, 92-98, 1999 Free Software Foundation, Inc. |
8d08fdba MS |
4 | Hacked by Michael Tiemann (tiemann@cygnus.com) |
5 | ||
6 | This file is part of GNU CC. | |
7 | ||
8 | GNU CC is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2, or (at your option) | |
11 | any later version. | |
12 | ||
13 | GNU CC is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with GNU CC; see the file COPYING. If not, write to | |
6bc06b8f RK |
20 | the Free Software Foundation, 59 Temple Place - Suite 330, |
21 | Boston, MA 02111-1307, USA. */ | |
8d08fdba MS |
22 | |
23 | ||
24 | /* This file is part of the C++ front end. | |
25 | It contains routines to build C++ expressions given their operands, | |
26 | including computing the types of the result, C and C++ specific error | |
27 | checks, and some optimization. | |
28 | ||
29 | There are also routines to build RETURN_STMT nodes and CASE_STMT nodes, | |
30 | and to process initializations in declarations (since they work | |
31 | like a strange sort of assignment). */ | |
32 | ||
33 | #include "config.h" | |
8d052bc7 | 34 | #include "system.h" |
8d08fdba MS |
35 | #include "tree.h" |
36 | #include "cp-tree.h" | |
37 | #include "flags.h" | |
12027a89 | 38 | #include "toplev.h" |
71144a65 | 39 | #include "output.h" |
8d08fdba | 40 | |
49c249e1 | 41 | static tree process_init_constructor PROTO((tree, tree, tree *)); |
d8e178a0 | 42 | static void ack PVPROTO ((const char *, ...)) ATTRIBUTE_PRINTF_1; |
8d08fdba | 43 | |
8d08fdba MS |
44 | /* Print an error message stemming from an attempt to use |
45 | BASETYPE as a base class for TYPE. */ | |
e92cc029 | 46 | |
8d08fdba MS |
47 | tree |
48 | error_not_base_type (basetype, type) | |
49 | tree basetype, type; | |
50 | { | |
51 | if (TREE_CODE (basetype) == FUNCTION_DECL) | |
52 | basetype = DECL_CLASS_CONTEXT (basetype); | |
8251199e | 53 | cp_error ("type `%T' is not a base type for type `%T'", basetype, type); |
8d08fdba MS |
54 | return error_mark_node; |
55 | } | |
56 | ||
57 | tree | |
58 | binfo_or_else (parent_or_type, type) | |
59 | tree parent_or_type, type; | |
60 | { | |
61 | tree binfo; | |
62 | if (TYPE_MAIN_VARIANT (parent_or_type) == TYPE_MAIN_VARIANT (type)) | |
a4443a08 | 63 | return TYPE_BINFO (parent_or_type); |
8926095f | 64 | if ((binfo = get_binfo (parent_or_type, TYPE_MAIN_VARIANT (type), 0))) |
8d08fdba MS |
65 | { |
66 | if (binfo == error_mark_node) | |
67 | return NULL_TREE; | |
68 | return binfo; | |
69 | } | |
70 | error_not_base_type (parent_or_type, type); | |
71 | return NULL_TREE; | |
72 | } | |
73 | ||
8d08fdba MS |
74 | /* According to ARM $7.1.6, "A `const' object may be initialized, but its |
75 | value may not be changed thereafter. Thus, we emit hard errors for these, | |
76 | rather than just pedwarns. If `SOFT' is 1, then we just pedwarn. (For | |
77 | example, conversions to references.) */ | |
e92cc029 | 78 | |
8d08fdba MS |
79 | void |
80 | readonly_error (arg, string, soft) | |
81 | tree arg; | |
d8e178a0 | 82 | const char *string; |
8d08fdba MS |
83 | int soft; |
84 | { | |
d8e178a0 KG |
85 | const char *fmt; |
86 | void (*fn) PVPROTO ((const char *, ...)); | |
8d08fdba MS |
87 | |
88 | if (soft) | |
fc378698 | 89 | fn = cp_pedwarn; |
8d08fdba | 90 | else |
fc378698 | 91 | fn = cp_error; |
8d08fdba MS |
92 | |
93 | if (TREE_CODE (arg) == COMPONENT_REF) | |
94 | { | |
95 | if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg, 0)))) | |
8251199e | 96 | fmt = "%s of member `%D' in read-only structure"; |
8d08fdba | 97 | else |
8251199e JM |
98 | fmt = "%s of read-only member `%D'"; |
99 | (*fn) (fmt, string, TREE_OPERAND (arg, 1)); | |
8d08fdba MS |
100 | } |
101 | else if (TREE_CODE (arg) == VAR_DECL) | |
102 | { | |
103 | if (DECL_LANG_SPECIFIC (arg) | |
104 | && DECL_IN_AGGR_P (arg) | |
105 | && !TREE_STATIC (arg)) | |
8251199e | 106 | fmt = "%s of constant field `%D'"; |
8d08fdba | 107 | else |
8251199e JM |
108 | fmt = "%s of read-only variable `%D'"; |
109 | (*fn) (fmt, string, arg); | |
8d08fdba MS |
110 | } |
111 | else if (TREE_CODE (arg) == PARM_DECL) | |
8251199e | 112 | (*fn) ("%s of read-only parameter `%D'", string, arg); |
8d08fdba MS |
113 | else if (TREE_CODE (arg) == INDIRECT_REF |
114 | && TREE_CODE (TREE_TYPE (TREE_OPERAND (arg, 0))) == REFERENCE_TYPE | |
115 | && (TREE_CODE (TREE_OPERAND (arg, 0)) == VAR_DECL | |
116 | || TREE_CODE (TREE_OPERAND (arg, 0)) == PARM_DECL)) | |
8251199e | 117 | (*fn) ("%s of read-only reference `%D'", string, TREE_OPERAND (arg, 0)); |
8d08fdba | 118 | else if (TREE_CODE (arg) == RESULT_DECL) |
8251199e | 119 | (*fn) ("%s of read-only named return value `%D'", string, arg); |
69851283 MM |
120 | else if (TREE_CODE (arg) == FUNCTION_DECL) |
121 | (*fn) ("%s of function `%D'", string, arg); | |
122 | else | |
8251199e | 123 | (*fn) ("%s of read-only location", string); |
8d08fdba MS |
124 | } |
125 | ||
a7a64a77 MM |
126 | /* If TYPE has abstract virtual functions, issue an error about trying |
127 | to create an object of that type. DECL is the object declared, or | |
128 | NULL_TREE if the declaration is unavailable. Returns 1 if an error | |
129 | occurred; zero if all was well. */ | |
e92cc029 | 130 | |
a7a64a77 | 131 | int |
8d08fdba MS |
132 | abstract_virtuals_error (decl, type) |
133 | tree decl; | |
134 | tree type; | |
135 | { | |
a7a64a77 | 136 | tree u; |
4a67c9e9 MH |
137 | tree tu; |
138 | ||
a7a64a77 MM |
139 | if (!CLASS_TYPE_P (type) || !CLASSTYPE_ABSTRACT_VIRTUALS (type)) |
140 | return 0; | |
141 | ||
142 | u = CLASSTYPE_ABSTRACT_VIRTUALS (type); | |
8d08fdba MS |
143 | if (decl) |
144 | { | |
145 | if (TREE_CODE (decl) == RESULT_DECL) | |
a7a64a77 | 146 | return 0; |
8d08fdba MS |
147 | |
148 | if (TREE_CODE (decl) == VAR_DECL) | |
8251199e | 149 | cp_error ("cannot declare variable `%D' to be of type `%T'", |
8d08fdba MS |
150 | decl, type); |
151 | else if (TREE_CODE (decl) == PARM_DECL) | |
8251199e | 152 | cp_error ("cannot declare parameter `%D' to be of type `%T'", |
8d08fdba MS |
153 | decl, type); |
154 | else if (TREE_CODE (decl) == FIELD_DECL) | |
8251199e | 155 | cp_error ("cannot declare field `%D' to be of type `%T'", |
8d08fdba MS |
156 | decl, type); |
157 | else if (TREE_CODE (decl) == FUNCTION_DECL | |
158 | && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE) | |
8251199e | 159 | cp_error ("invalid return type for method `%#D'", decl); |
8d08fdba | 160 | else if (TREE_CODE (decl) == FUNCTION_DECL) |
8251199e | 161 | cp_error ("invalid return type for function `%#D'", decl); |
8d08fdba | 162 | } |
4a67c9e9 | 163 | else |
8251199e | 164 | cp_error ("cannot allocate an object of type `%T'", type); |
4a67c9e9 | 165 | |
8d08fdba MS |
166 | /* Only go through this once. */ |
167 | if (TREE_PURPOSE (u) == NULL_TREE) | |
168 | { | |
8d08fdba | 169 | TREE_PURPOSE (u) = error_mark_node; |
4a67c9e9 | 170 | |
8ebeee52 JM |
171 | error (" since the following virtual functions are abstract:"); |
172 | for (tu = u; tu; tu = TREE_CHAIN (tu)) | |
83f660b7 | 173 | cp_error_at ("\t%#D", TREE_VALUE (tu)); |
8d08fdba | 174 | } |
4a67c9e9 | 175 | else |
8ebeee52 | 176 | cp_error (" since type `%T' has abstract virtual functions", type); |
a7a64a77 MM |
177 | |
178 | return 1; | |
8d08fdba MS |
179 | } |
180 | ||
8d08fdba MS |
181 | /* Print an error message for invalid use of an incomplete type. |
182 | VALUE is the expression that was used (or 0 if that isn't known) | |
183 | and TYPE is the type that was invalid. */ | |
184 | ||
185 | void | |
186 | incomplete_type_error (value, type) | |
187 | tree value; | |
188 | tree type; | |
189 | { | |
8d08fdba MS |
190 | /* Avoid duplicate error message. */ |
191 | if (TREE_CODE (type) == ERROR_MARK) | |
192 | return; | |
193 | ||
66543169 NS |
194 | retry: |
195 | /* We must print an error message. Be clever about what it says. */ | |
196 | ||
197 | switch (TREE_CODE (type)) | |
8d08fdba | 198 | { |
66543169 NS |
199 | case RECORD_TYPE: |
200 | case UNION_TYPE: | |
201 | case ENUMERAL_TYPE: | |
202 | cp_error ("invalid use of undefined type `%#T'", type); | |
203 | cp_error_at ("forward declaration of `%#T'", type); | |
204 | break; | |
205 | ||
206 | case VOID_TYPE: | |
207 | cp_error ("invalid use of void expression"); | |
208 | break; | |
209 | ||
210 | case ARRAY_TYPE: | |
211 | if (TYPE_DOMAIN (type)) | |
212 | { | |
213 | type = TREE_TYPE (type); | |
214 | goto retry; | |
215 | } | |
216 | cp_error ("invalid use of array with unspecified bounds"); | |
217 | break; | |
218 | ||
219 | case OFFSET_TYPE: | |
220 | bad_member: | |
221 | cp_error ("invalid use of member (did you forget the `&' ?)"); | |
222 | break; | |
223 | ||
224 | case TEMPLATE_TYPE_PARM: | |
225 | cp_error ("invalid use of template type parameter"); | |
226 | break; | |
227 | ||
228 | case UNKNOWN_TYPE: | |
229 | if (value && TREE_CODE (value) == COMPONENT_REF) | |
230 | goto bad_member; | |
231 | else if (value && TREE_CODE (value) == ADDR_EXPR) | |
232 | cp_error ("address of overloaded function with no contextual type information"); | |
233 | else if (value && TREE_CODE (value) == OVERLOAD) | |
234 | cp_error ("overloaded function with no contextual type information"); | |
235 | else | |
236 | cp_error ("insufficient contextual information to determine type"); | |
237 | break; | |
238 | ||
239 | default: | |
240 | my_friendly_abort (108); | |
8d08fdba | 241 | } |
66543169 NS |
242 | |
243 | if (value != 0 && (TREE_CODE (value) == VAR_DECL | |
244 | || TREE_CODE (value) == PARM_DECL)) | |
245 | cp_error_at ("incomplete `%D' defined here", value); | |
8d08fdba MS |
246 | } |
247 | ||
248 | /* Like error(), but don't call report_error_function(). */ | |
e92cc029 | 249 | |
8d08fdba | 250 | static void |
d8e178a0 | 251 | ack VPROTO ((const char *msg, ...)) |
8d08fdba | 252 | { |
d8e178a0 KG |
253 | #ifndef ANSI_PROTOTYPES |
254 | const char *msg; | |
255 | #endif | |
256 | va_list ap; | |
8d08fdba | 257 | |
d8e178a0 KG |
258 | VA_START (ap, msg); |
259 | ||
260 | #ifndef ANSI_PROTOTYPES | |
261 | msg = va_arg (ap, const char *); | |
262 | #endif | |
263 | ||
8d08fdba MS |
264 | if (input_filename) |
265 | fprintf (stderr, "%s:%d: ", input_filename, lineno); | |
266 | else | |
267 | fprintf (stderr, "%s: ", progname); | |
268 | ||
d8e178a0 KG |
269 | vfprintf (stderr, msg, ap); |
270 | va_end (ap); | |
271 | ||
8d08fdba MS |
272 | fprintf (stderr, "\n"); |
273 | } | |
274 | ||
275 | /* There are times when the compiler can get very confused, confused | |
276 | to the point of giving up by aborting, simply because of previous | |
277 | input errors. It is much better to have the user go back and | |
278 | correct those errors first, and see if it makes us happier, than it | |
279 | is to abort on him. This is because when one has a 10,000 line | |
280 | program, and the compiler comes back with ``core dump'', the user | |
281 | is left not knowing even where to begin to fix things and no place | |
282 | to even try and work around things. | |
283 | ||
284 | The parameter is to uniquely identify the problem to the user, so | |
285 | that they can say, I am having problem 59, and know that fix 7 will | |
286 | probably solve their problem. Or, we can document what problem | |
287 | 59 is, so they can understand how to work around it, should they | |
288 | ever run into it. | |
289 | ||
8d08fdba MS |
290 | We used to tell people to "fix the above error[s] and try recompiling |
291 | the program" via a call to fatal, but that message tended to look | |
292 | silly. So instead, we just do the equivalent of a call to fatal in the | |
51924768 | 293 | same situation (call exit). |
8d08fdba | 294 | |
51924768 JM |
295 | We used to assign sequential numbers for the aborts; now we use an |
296 | encoding of the date the abort was added, since that has more meaning | |
297 | when we only see the error message. */ | |
8d08fdba MS |
298 | |
299 | static int abortcount = 0; | |
300 | ||
301 | void | |
302 | my_friendly_abort (i) | |
303 | int i; | |
304 | { | |
305 | /* if the previous error came through here, i.e. report_error_function | |
306 | ended up calling us again, don't just exit; we want a diagnostic of | |
307 | some kind. */ | |
308 | if (abortcount == 1) | |
309 | current_function_decl = NULL_TREE; | |
310 | else if (errorcount > 0 || sorrycount > 0) | |
311 | { | |
312 | if (abortcount > 1) | |
313 | { | |
314 | if (i == 0) | |
315 | ack ("Internal compiler error."); | |
316 | else | |
317 | ack ("Internal compiler error %d.", i); | |
70ade953 | 318 | ack ("Please submit a full bug report."); |
7fc2d503 | 319 | ack ("See <URL:http://www.gnu.org/software/gcc/faq.html#bugreport> for instructions."); |
8d08fdba MS |
320 | } |
321 | else | |
8251199e | 322 | error ("confused by earlier errors, bailing out"); |
8d08fdba MS |
323 | |
324 | exit (34); | |
325 | } | |
326 | ++abortcount; | |
327 | ||
328 | if (i == 0) | |
8251199e | 329 | error ("Internal compiler error."); |
8d08fdba | 330 | else |
8251199e | 331 | error ("Internal compiler error %d.", i); |
8d08fdba | 332 | |
70ade953 | 333 | error ("Please submit a full bug report."); |
e547bb67 | 334 | fatal ("See <URL:http://www.gnu.org/software/gcc/faq.html#bugreport> for instructions."); |
8d08fdba MS |
335 | } |
336 | ||
337 | void | |
338 | my_friendly_assert (cond, where) | |
339 | int cond, where; | |
340 | { | |
341 | if (cond == 0) | |
342 | my_friendly_abort (where); | |
343 | } | |
344 | \f | |
8d08fdba MS |
345 | /* Perform appropriate conversions on the initial value of a variable, |
346 | store it in the declaration DECL, | |
347 | and print any error messages that are appropriate. | |
348 | If the init is invalid, store an ERROR_MARK. | |
349 | ||
350 | C++: Note that INIT might be a TREE_LIST, which would mean that it is | |
351 | a base class initializer for some aggregate type, hopefully compatible | |
352 | with DECL. If INIT is a single element, and DECL is an aggregate | |
353 | type, we silently convert INIT into a TREE_LIST, allowing a constructor | |
354 | to be called. | |
355 | ||
356 | If INIT is a TREE_LIST and there is no constructor, turn INIT | |
357 | into a CONSTRUCTOR and use standard initialization techniques. | |
358 | Perhaps a warning should be generated? | |
359 | ||
360 | Returns value of initializer if initialization could not be | |
361 | performed for static variable. In that case, caller must do | |
362 | the storing. */ | |
363 | ||
364 | tree | |
365 | store_init_value (decl, init) | |
366 | tree decl, init; | |
367 | { | |
368 | register tree value, type; | |
369 | ||
370 | /* If variable's type was invalidly declared, just ignore it. */ | |
371 | ||
372 | type = TREE_TYPE (decl); | |
373 | if (TREE_CODE (type) == ERROR_MARK) | |
374 | return NULL_TREE; | |
375 | ||
878cd289 MS |
376 | #if 0 |
377 | /* This breaks arrays, and should not have any effect for other decls. */ | |
8d08fdba MS |
378 | /* Take care of C++ business up here. */ |
379 | type = TYPE_MAIN_VARIANT (type); | |
878cd289 | 380 | #endif |
8d08fdba | 381 | |
e8abc66f | 382 | if (IS_AGGR_TYPE (type)) |
8d08fdba | 383 | { |
e8abc66f MS |
384 | if (! TYPE_HAS_TRIVIAL_INIT_REF (type) |
385 | && TREE_CODE (init) != CONSTRUCTOR) | |
386 | my_friendly_abort (109); | |
387 | ||
6eabb241 | 388 | if (TREE_CODE (init) == TREE_LIST) |
8d08fdba | 389 | { |
8251199e | 390 | cp_error ("constructor syntax used, but no constructor declared for type `%T'", type); |
8d08fdba MS |
391 | init = build_nt (CONSTRUCTOR, NULL_TREE, nreverse (init)); |
392 | } | |
393 | #if 0 | |
394 | if (TREE_CODE (init) == CONSTRUCTOR) | |
395 | { | |
396 | tree field; | |
8d08fdba MS |
397 | |
398 | /* Check that we're really an aggregate as ARM 8.4.1 defines it. */ | |
399 | if (CLASSTYPE_N_BASECLASSES (type)) | |
8251199e | 400 | cp_error_at ("initializer list construction invalid for derived class object `%D'", decl); |
8d08fdba | 401 | if (CLASSTYPE_VTBL_PTR (type)) |
8251199e | 402 | cp_error_at ("initializer list construction invalid for polymorphic class object `%D'", decl); |
8d08fdba MS |
403 | if (TYPE_NEEDS_CONSTRUCTING (type)) |
404 | { | |
8251199e JM |
405 | cp_error_at ("initializer list construction invalid for `%D'", decl); |
406 | error ("due to the presence of a constructor"); | |
8d08fdba MS |
407 | } |
408 | for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) | |
409 | if (TREE_PRIVATE (field) || TREE_PROTECTED (field)) | |
410 | { | |
8251199e JM |
411 | cp_error_at ("initializer list construction invalid for `%D'", decl); |
412 | cp_error_at ("due to non-public access of member `%D'", field); | |
8d08fdba | 413 | } |
72b7eeff MS |
414 | for (field = TYPE_METHODS (type); field; field = TREE_CHAIN (field)) |
415 | if (TREE_PRIVATE (field) || TREE_PROTECTED (field)) | |
8d08fdba | 416 | { |
8251199e JM |
417 | cp_error_at ("initializer list construction invalid for `%D'", decl); |
418 | cp_error_at ("due to non-public access of member `%D'", field); | |
8d08fdba MS |
419 | } |
420 | } | |
421 | #endif | |
422 | } | |
423 | else if (TREE_CODE (init) == TREE_LIST | |
424 | && TREE_TYPE (init) != unknown_type_node) | |
425 | { | |
426 | if (TREE_CODE (decl) == RESULT_DECL) | |
427 | { | |
428 | if (TREE_CHAIN (init)) | |
429 | { | |
8251199e | 430 | warning ("comma expression used to initialize return value"); |
8d08fdba MS |
431 | init = build_compound_expr (init); |
432 | } | |
433 | else | |
434 | init = TREE_VALUE (init); | |
435 | } | |
8d08fdba MS |
436 | else if (TREE_CODE (init) == TREE_LIST |
437 | && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE) | |
438 | { | |
8251199e | 439 | error ("cannot initialize arrays using this syntax"); |
8d08fdba MS |
440 | return NULL_TREE; |
441 | } | |
442 | else | |
443 | { | |
444 | /* We get here with code like `int a (2);' */ | |
445 | ||
446 | if (TREE_CHAIN (init) != NULL_TREE) | |
447 | { | |
8251199e | 448 | pedwarn ("initializer list being treated as compound expression"); |
8d08fdba MS |
449 | init = build_compound_expr (init); |
450 | } | |
451 | else | |
452 | init = TREE_VALUE (init); | |
453 | } | |
454 | } | |
455 | ||
456 | /* End of special C++ code. */ | |
457 | ||
458 | /* Digest the specified initializer into an expression. */ | |
459 | ||
460 | value = digest_init (type, init, (tree *) 0); | |
461 | ||
462 | /* Store the expression if valid; else report error. */ | |
463 | ||
464 | if (TREE_CODE (value) == ERROR_MARK) | |
465 | ; | |
7834ab39 MS |
466 | /* Other code expects that initializers for objects of types that need |
467 | constructing never make it into DECL_INITIAL, and passes 'init' to | |
f1dedc31 | 468 | build_aggr_init without checking DECL_INITIAL. So just return. */ |
7834ab39 MS |
469 | else if (TYPE_NEEDS_CONSTRUCTING (type)) |
470 | return value; | |
8d08fdba MS |
471 | else if (TREE_STATIC (decl) |
472 | && (! TREE_CONSTANT (value) | |
8ccc31eb | 473 | || ! initializer_constant_valid_p (value, TREE_TYPE (value)) |
8926095f MS |
474 | #if 0 |
475 | /* A STATIC PUBLIC int variable doesn't have to be | |
476 | run time inited when doing pic. (mrs) */ | |
8d08fdba MS |
477 | /* Since ctors and dtors are the only things that can |
478 | reference vtables, and they are always written down | |
38e01259 | 479 | the vtable definition, we can leave the |
8d08fdba MS |
480 | vtables in initialized data space. |
481 | However, other initialized data cannot be initialized | |
482 | this way. Instead a global file-level initializer | |
483 | must do the job. */ | |
8926095f MS |
484 | || (flag_pic && !DECL_VIRTUAL_P (decl) && TREE_PUBLIC (decl)) |
485 | #endif | |
486 | )) | |
487 | ||
8d08fdba | 488 | return value; |
f376e137 | 489 | #if 0 /* No, that's C. jason 9/19/94 */ |
8d08fdba MS |
490 | else |
491 | { | |
6eabb241 | 492 | if (pedantic && TREE_CODE (value) == CONSTRUCTOR) |
8d08fdba MS |
493 | { |
494 | if (! TREE_CONSTANT (value) || ! TREE_STATIC (value)) | |
8251199e | 495 | pedwarn ("ANSI C++ forbids non-constant aggregate initializer expressions"); |
8d08fdba MS |
496 | } |
497 | } | |
f376e137 | 498 | #endif |
4d6abc1c MM |
499 | |
500 | /* Store the VALUE in DECL_INITIAL. If we're building a | |
501 | statement-tree we will actually expand the initialization later | |
502 | when we output this function. */ | |
8d08fdba MS |
503 | DECL_INITIAL (decl) = value; |
504 | return NULL_TREE; | |
505 | } | |
506 | \f | |
507 | /* Digest the parser output INIT as an initializer for type TYPE. | |
508 | Return a C expression of type TYPE to represent the initial value. | |
509 | ||
510 | If TAIL is nonzero, it points to a variable holding a list of elements | |
511 | of which INIT is the first. We update the list stored there by | |
512 | removing from the head all the elements that we use. | |
513 | Normally this is only one; we use more than one element only if | |
514 | TYPE is an aggregate and INIT is not a constructor. */ | |
515 | ||
516 | tree | |
517 | digest_init (type, init, tail) | |
518 | tree type, init, *tail; | |
519 | { | |
520 | enum tree_code code = TREE_CODE (type); | |
00595019 | 521 | tree element = NULL_TREE; |
a703fb38 | 522 | tree old_tail_contents = NULL_TREE; |
8d08fdba MS |
523 | /* Nonzero if INIT is a braced grouping, which comes in as a CONSTRUCTOR |
524 | tree node which has no TREE_TYPE. */ | |
525 | int raw_constructor; | |
526 | ||
527 | /* By default, assume we use one element from a list. | |
528 | We correct this later in the sole case where it is not true. */ | |
529 | ||
530 | if (tail) | |
531 | { | |
532 | old_tail_contents = *tail; | |
533 | *tail = TREE_CHAIN (*tail); | |
534 | } | |
535 | ||
536 | if (init == error_mark_node || (TREE_CODE (init) == TREE_LIST | |
537 | && TREE_VALUE (init) == error_mark_node)) | |
538 | return error_mark_node; | |
539 | ||
540 | /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */ | |
541 | if (TREE_CODE (init) == NON_LVALUE_EXPR) | |
542 | init = TREE_OPERAND (init, 0); | |
543 | ||
e6267549 JM |
544 | if (TREE_CODE (init) == CONSTRUCTOR && TREE_TYPE (init) == type) |
545 | return init; | |
546 | ||
8d08fdba MS |
547 | raw_constructor = TREE_CODE (init) == CONSTRUCTOR && TREE_TYPE (init) == 0; |
548 | ||
dc26f471 | 549 | if (raw_constructor |
8d08fdba MS |
550 | && CONSTRUCTOR_ELTS (init) != 0 |
551 | && TREE_CHAIN (CONSTRUCTOR_ELTS (init)) == 0) | |
552 | { | |
553 | element = TREE_VALUE (CONSTRUCTOR_ELTS (init)); | |
554 | /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */ | |
555 | if (element && TREE_CODE (element) == NON_LVALUE_EXPR) | |
556 | element = TREE_OPERAND (element, 0); | |
557 | if (element == error_mark_node) | |
558 | return element; | |
559 | } | |
560 | ||
8d08fdba MS |
561 | /* Initialization of an array of chars from a string constant |
562 | optionally enclosed in braces. */ | |
563 | ||
564 | if (code == ARRAY_TYPE) | |
565 | { | |
8c90d611 JM |
566 | tree typ1; |
567 | ||
568 | if (TREE_CODE (init) == TREE_LIST) | |
569 | { | |
8251199e | 570 | error ("initializing array with parameter list"); |
8c90d611 JM |
571 | return error_mark_node; |
572 | } | |
573 | ||
574 | typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type)); | |
8d08fdba MS |
575 | if ((typ1 == char_type_node |
576 | || typ1 == signed_char_type_node | |
577 | || typ1 == unsigned_char_type_node | |
578 | || typ1 == unsigned_wchar_type_node | |
579 | || typ1 == signed_wchar_type_node) | |
580 | && ((init && TREE_CODE (init) == STRING_CST) | |
581 | || (element && TREE_CODE (element) == STRING_CST))) | |
582 | { | |
583 | tree string = element ? element : init; | |
584 | ||
585 | if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string))) | |
586 | != char_type_node) | |
587 | && TYPE_PRECISION (typ1) == BITS_PER_UNIT) | |
588 | { | |
8251199e | 589 | error ("char-array initialized from wide string"); |
8d08fdba MS |
590 | return error_mark_node; |
591 | } | |
592 | if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string))) | |
593 | == char_type_node) | |
594 | && TYPE_PRECISION (typ1) != BITS_PER_UNIT) | |
595 | { | |
8251199e | 596 | error ("int-array initialized from non-wide string"); |
8d08fdba MS |
597 | return error_mark_node; |
598 | } | |
599 | ||
8d08fdba MS |
600 | TREE_TYPE (string) = type; |
601 | if (TYPE_DOMAIN (type) != 0 | |
602 | && TREE_CONSTANT (TYPE_SIZE (type))) | |
603 | { | |
604 | register int size | |
605 | = TREE_INT_CST_LOW (TYPE_SIZE (type)); | |
606 | size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT; | |
607 | /* In C it is ok to subtract 1 from the length of the string | |
608 | because it's ok to ignore the terminating null char that is | |
609 | counted in the length of the constant, but in C++ this would | |
610 | be invalid. */ | |
611 | if (size < TREE_STRING_LENGTH (string)) | |
8251199e | 612 | pedwarn ("initializer-string for array of chars is too long"); |
8d08fdba MS |
613 | } |
614 | return string; | |
615 | } | |
616 | } | |
617 | ||
618 | /* Handle scalar types, including conversions, | |
619 | and signature pointers and references. */ | |
620 | ||
621 | if (code == INTEGER_TYPE || code == REAL_TYPE || code == POINTER_TYPE | |
622 | || code == ENUMERAL_TYPE || code == REFERENCE_TYPE | |
37c46b43 | 623 | || code == BOOLEAN_TYPE || code == COMPLEX_TYPE |
6eabb241 | 624 | || TYPE_PTRMEMFUNC_P (type)) |
8d08fdba MS |
625 | { |
626 | if (raw_constructor) | |
627 | { | |
628 | if (element == 0) | |
629 | { | |
8251199e | 630 | error ("initializer for scalar variable requires one element"); |
8d08fdba MS |
631 | return error_mark_node; |
632 | } | |
633 | init = element; | |
634 | } | |
dc26f471 | 635 | while (TREE_CODE (init) == CONSTRUCTOR && TREE_HAS_CONSTRUCTOR (init)) |
b7484fbe | 636 | { |
8251199e | 637 | cp_pedwarn ("braces around scalar initializer for `%T'", type); |
b7484fbe MS |
638 | init = CONSTRUCTOR_ELTS (init); |
639 | if (TREE_CHAIN (init)) | |
8251199e | 640 | cp_pedwarn ("ignoring extra initializers for `%T'", type); |
b7484fbe MS |
641 | init = TREE_VALUE (init); |
642 | } | |
8d08fdba MS |
643 | |
644 | return convert_for_initialization (0, type, init, LOOKUP_NORMAL, | |
645 | "initialization", NULL_TREE, 0); | |
646 | } | |
647 | ||
648 | /* Come here only for records and arrays (and unions with constructors). */ | |
649 | ||
650 | if (TYPE_SIZE (type) && ! TREE_CONSTANT (TYPE_SIZE (type))) | |
651 | { | |
8251199e | 652 | cp_error ("variable-sized object of type `%T' may not be initialized", |
7177d104 | 653 | type); |
8d08fdba MS |
654 | return error_mark_node; |
655 | } | |
656 | ||
829fd7e0 | 657 | if (code == ARRAY_TYPE || IS_AGGR_TYPE_CODE (code)) |
8d08fdba | 658 | { |
f30432d7 MS |
659 | if (raw_constructor && TYPE_NON_AGGREGATE_CLASS (type)) |
660 | { | |
8251199e | 661 | cp_error ("subobject of type `%T' must be initialized by constructor, not by `%E'", |
f30432d7 MS |
662 | type, init); |
663 | return error_mark_node; | |
664 | } | |
665 | else if (raw_constructor) | |
8d08fdba | 666 | return process_init_constructor (type, init, (tree *)0); |
dc26f471 JM |
667 | else if (can_convert_arg (type, TREE_TYPE (init), init) |
668 | || TYPE_NON_AGGREGATE_CLASS (type)) | |
669 | /* These are never initialized from multiple constructor elements. */; | |
8d08fdba MS |
670 | else if (tail != 0) |
671 | { | |
672 | *tail = old_tail_contents; | |
673 | return process_init_constructor (type, 0, tail); | |
674 | } | |
d22c8596 | 675 | |
8d08fdba | 676 | if (code != ARRAY_TYPE) |
dc26f471 JM |
677 | { |
678 | int flags = LOOKUP_NORMAL; | |
679 | /* Initialization from { } is copy-initialization. */ | |
680 | if (tail) | |
681 | flags |= LOOKUP_ONLYCONVERTING; | |
682 | ||
683 | return convert_for_initialization (NULL_TREE, type, init, flags, | |
684 | "initialization", NULL_TREE, 0); | |
685 | } | |
8d08fdba MS |
686 | } |
687 | ||
8251199e | 688 | error ("invalid initializer"); |
8d08fdba MS |
689 | return error_mark_node; |
690 | } | |
691 | \f | |
692 | /* Process a constructor for a variable of type TYPE. | |
693 | The constructor elements may be specified either with INIT or with ELTS, | |
694 | only one of which should be non-null. | |
695 | ||
696 | If INIT is specified, it is a CONSTRUCTOR node which is specifically | |
697 | and solely for initializing this datum. | |
698 | ||
699 | If ELTS is specified, it is the address of a variable containing | |
700 | a list of expressions. We take as many elements as we need | |
701 | from the head of the list and update the list. | |
702 | ||
703 | In the resulting constructor, TREE_CONSTANT is set if all elts are | |
704 | constant, and TREE_STATIC is set if, in addition, all elts are simple enough | |
705 | constants that the assembler and linker can compute them. */ | |
706 | ||
707 | static tree | |
708 | process_init_constructor (type, init, elts) | |
709 | tree type, init, *elts; | |
710 | { | |
8d08fdba MS |
711 | register tree tail; |
712 | /* List of the elements of the result constructor, | |
713 | in reverse order. */ | |
714 | register tree members = NULL; | |
e6267549 | 715 | register tree next1; |
8d08fdba MS |
716 | tree result; |
717 | int allconstant = 1; | |
718 | int allsimple = 1; | |
719 | int erroneous = 0; | |
720 | ||
721 | /* Make TAIL be the list of elements to use for the initialization, | |
722 | no matter how the data was given to us. */ | |
723 | ||
724 | if (elts) | |
725 | { | |
726 | if (warn_missing_braces) | |
8251199e | 727 | warning ("aggregate has a partly bracketed initializer"); |
8d08fdba MS |
728 | tail = *elts; |
729 | } | |
730 | else | |
731 | tail = CONSTRUCTOR_ELTS (init); | |
732 | ||
733 | /* Gobble as many elements as needed, and make a constructor or initial value | |
734 | for each element of this aggregate. Chain them together in result. | |
735 | If there are too few, use 0 for each scalar ultimate component. */ | |
736 | ||
737 | if (TREE_CODE (type) == ARRAY_TYPE) | |
738 | { | |
739 | tree domain = TYPE_DOMAIN (type); | |
740 | register long len; | |
741 | register int i; | |
742 | ||
743 | if (domain) | |
744 | len = (TREE_INT_CST_LOW (TYPE_MAX_VALUE (domain)) | |
745 | - TREE_INT_CST_LOW (TYPE_MIN_VALUE (domain)) | |
746 | + 1); | |
747 | else | |
748 | len = -1; /* Take as many as there are */ | |
749 | ||
e6267549 | 750 | for (i = 0; len < 0 || i < len; i++) |
8d08fdba | 751 | { |
e6267549 | 752 | if (tail) |
8d08fdba | 753 | { |
e6267549 JM |
754 | if (TREE_PURPOSE (tail) |
755 | && (TREE_CODE (TREE_PURPOSE (tail)) != INTEGER_CST | |
756 | || TREE_INT_CST_LOW (TREE_PURPOSE (tail)) != i)) | |
757 | sorry ("non-trivial labeled initializers"); | |
758 | ||
759 | if (TREE_VALUE (tail) != 0) | |
a5894242 | 760 | { |
e6267549 JM |
761 | tree tail1 = tail; |
762 | next1 = digest_init (TREE_TYPE (type), | |
763 | TREE_VALUE (tail), &tail1); | |
0db982be ML |
764 | if (next1 == error_mark_node) |
765 | return next1; | |
7e2067ca JM |
766 | my_friendly_assert |
767 | (same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)), | |
768 | TYPE_MAIN_VARIANT (TREE_TYPE (next1))), | |
769 | 981123); | |
e6267549 JM |
770 | my_friendly_assert (tail1 == 0 |
771 | || TREE_CODE (tail1) == TREE_LIST, 319); | |
772 | if (tail == tail1 && len < 0) | |
773 | { | |
774 | error ("non-empty initializer for array of empty elements"); | |
775 | /* Just ignore what we were supposed to use. */ | |
776 | tail1 = NULL_TREE; | |
777 | } | |
778 | tail = tail1; | |
a5894242 | 779 | } |
e6267549 | 780 | else |
8d08fdba | 781 | { |
e6267549 JM |
782 | next1 = error_mark_node; |
783 | tail = TREE_CHAIN (tail); | |
8d08fdba | 784 | } |
8d08fdba | 785 | } |
e6267549 JM |
786 | else if (len < 0) |
787 | /* We're done. */ | |
788 | break; | |
789 | else if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (type))) | |
8d08fdba | 790 | { |
e6267549 JM |
791 | /* If this type needs constructors run for |
792 | default-initialization, we can't rely on the backend to do it | |
793 | for us, so build up TARGET_EXPRs. If the type in question is | |
794 | a class, just build one up; if it's an array, recurse. */ | |
795 | ||
796 | if (IS_AGGR_TYPE (TREE_TYPE (type))) | |
797 | next1 = build_functional_cast (TREE_TYPE (type), NULL_TREE); | |
798 | else | |
799 | next1 = build (CONSTRUCTOR, NULL_TREE, NULL_TREE, NULL_TREE); | |
800 | next1 = digest_init (TREE_TYPE (type), next1, 0); | |
8d08fdba | 801 | } |
e6267549 JM |
802 | else |
803 | /* The default zero-initialization is fine for us; don't | |
804 | add anything to the CONSTRUCTOR. */ | |
805 | break; | |
8d08fdba MS |
806 | |
807 | if (next1 == error_mark_node) | |
808 | erroneous = 1; | |
809 | else if (!TREE_CONSTANT (next1)) | |
810 | allconstant = 0; | |
8ccc31eb | 811 | else if (! initializer_constant_valid_p (next1, TREE_TYPE (next1))) |
8d08fdba | 812 | allsimple = 0; |
e66d884e | 813 | members = expr_tree_cons (NULL_TREE, next1, members); |
8d08fdba MS |
814 | } |
815 | } | |
8a72a046 | 816 | else if (TREE_CODE (type) == RECORD_TYPE) |
8d08fdba MS |
817 | { |
818 | register tree field; | |
819 | ||
820 | if (tail) | |
821 | { | |
822 | if (TYPE_USES_VIRTUAL_BASECLASSES (type)) | |
823 | { | |
824 | sorry ("initializer list for object of class with virtual baseclasses"); | |
825 | return error_mark_node; | |
826 | } | |
827 | ||
828 | if (TYPE_BINFO_BASETYPES (type)) | |
829 | { | |
830 | sorry ("initializer list for object of class with baseclasses"); | |
831 | return error_mark_node; | |
832 | } | |
833 | ||
834 | if (TYPE_VIRTUAL_P (type)) | |
835 | { | |
836 | sorry ("initializer list for object using virtual functions"); | |
837 | return error_mark_node; | |
838 | } | |
839 | } | |
840 | ||
e6267549 | 841 | for (field = TYPE_FIELDS (type); field; |
8d08fdba MS |
842 | field = TREE_CHAIN (field)) |
843 | { | |
c8c133cd | 844 | if (! DECL_NAME (field) && DECL_C_BIT_FIELD (field)) |
8d08fdba | 845 | { |
e66d884e | 846 | members = expr_tree_cons (field, integer_zero_node, members); |
8d08fdba MS |
847 | continue; |
848 | } | |
849 | ||
2986ae00 | 850 | if (TREE_CODE (field) != FIELD_DECL) |
8d08fdba MS |
851 | continue; |
852 | ||
e6267549 JM |
853 | if (tail) |
854 | { | |
855 | if (TREE_PURPOSE (tail) | |
856 | && TREE_PURPOSE (tail) != field | |
857 | && TREE_PURPOSE (tail) != DECL_NAME (field)) | |
858 | sorry ("non-trivial labeled initializers"); | |
859 | ||
860 | if (TREE_VALUE (tail) != 0) | |
861 | { | |
862 | tree tail1 = tail; | |
c8fcb331 | 863 | |
e6267549 JM |
864 | next1 = digest_init (TREE_TYPE (field), |
865 | TREE_VALUE (tail), &tail1); | |
866 | my_friendly_assert (tail1 == 0 | |
867 | || TREE_CODE (tail1) == TREE_LIST, 320); | |
868 | tail = tail1; | |
869 | } | |
870 | else | |
871 | { | |
872 | next1 = error_mark_node; | |
873 | tail = TREE_CHAIN (tail); | |
874 | } | |
875 | } | |
876 | else if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (field))) | |
8d08fdba | 877 | { |
e6267549 JM |
878 | /* If this type needs constructors run for |
879 | default-initialization, we can't rely on the backend to do it | |
880 | for us, so build up TARGET_EXPRs. If the type in question is | |
881 | a class, just build one up; if it's an array, recurse. */ | |
882 | ||
883 | if (IS_AGGR_TYPE (TREE_TYPE (field))) | |
884 | next1 = build_functional_cast (TREE_TYPE (field), | |
885 | NULL_TREE); | |
886 | else | |
887 | next1 = build (CONSTRUCTOR, NULL_TREE, NULL_TREE, | |
888 | NULL_TREE); | |
889 | next1 = digest_init (TREE_TYPE (field), next1, 0); | |
8d08fdba | 890 | |
e6267549 JM |
891 | /* Warn when some struct elements are implicitly initialized. */ |
892 | if (extra_warnings) | |
893 | cp_warning ("missing initializer for member `%D'", field); | |
8d08fdba MS |
894 | } |
895 | else | |
896 | { | |
e6267549 JM |
897 | if (TREE_READONLY (field)) |
898 | cp_error ("uninitialized const member `%D'", field); | |
899 | else if (TYPE_LANG_SPECIFIC (TREE_TYPE (field)) | |
900 | && CLASSTYPE_READONLY_FIELDS_NEED_INIT (TREE_TYPE (field))) | |
901 | cp_error ("member `%D' with uninitialized const fields", | |
902 | field); | |
903 | else if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE) | |
904 | cp_error ("member `%D' is uninitialized reference", field); | |
905 | ||
906 | /* Warn when some struct elements are implicitly initialized | |
907 | to zero. */ | |
908 | if (extra_warnings) | |
909 | cp_warning ("missing initializer for member `%D'", field); | |
910 | ||
911 | /* The default zero-initialization is fine for us; don't | |
912 | add anything to the CONSTRUCTOR. */ | |
913 | continue; | |
8d08fdba MS |
914 | } |
915 | ||
916 | if (next1 == error_mark_node) | |
917 | erroneous = 1; | |
918 | else if (!TREE_CONSTANT (next1)) | |
919 | allconstant = 0; | |
8ccc31eb | 920 | else if (! initializer_constant_valid_p (next1, TREE_TYPE (next1))) |
8d08fdba | 921 | allsimple = 0; |
e66d884e | 922 | members = expr_tree_cons (field, next1, members); |
8d08fdba | 923 | } |
8d08fdba | 924 | } |
a59f8640 R |
925 | else if (TREE_CODE (type) == UNION_TYPE |
926 | /* If the initializer was empty, use default zero initialization. */ | |
927 | && tail) | |
8d08fdba MS |
928 | { |
929 | register tree field = TYPE_FIELDS (type); | |
8d08fdba MS |
930 | |
931 | /* Find the first named field. ANSI decided in September 1990 | |
932 | that only named fields count here. */ | |
6467930b MS |
933 | while (field && (DECL_NAME (field) == 0 |
934 | || TREE_CODE (field) != FIELD_DECL)) | |
8d08fdba MS |
935 | field = TREE_CHAIN (field); |
936 | ||
937 | /* If this element specifies a field, initialize via that field. */ | |
938 | if (TREE_PURPOSE (tail) != NULL_TREE) | |
939 | { | |
940 | int win = 0; | |
941 | ||
942 | if (TREE_CODE (TREE_PURPOSE (tail)) == FIELD_DECL) | |
943 | /* Handle the case of a call by build_c_cast. */ | |
944 | field = TREE_PURPOSE (tail), win = 1; | |
945 | else if (TREE_CODE (TREE_PURPOSE (tail)) != IDENTIFIER_NODE) | |
8251199e | 946 | error ("index value instead of field name in union initializer"); |
8d08fdba MS |
947 | else |
948 | { | |
949 | tree temp; | |
950 | for (temp = TYPE_FIELDS (type); | |
951 | temp; | |
952 | temp = TREE_CHAIN (temp)) | |
953 | if (DECL_NAME (temp) == TREE_PURPOSE (tail)) | |
954 | break; | |
955 | if (temp) | |
956 | field = temp, win = 1; | |
957 | else | |
e6267549 JM |
958 | cp_error ("no field `%D' in union being initialized", |
959 | TREE_PURPOSE (tail)); | |
8d08fdba MS |
960 | } |
961 | if (!win) | |
962 | TREE_VALUE (tail) = error_mark_node; | |
963 | } | |
7177d104 MS |
964 | else if (field == 0) |
965 | { | |
8251199e | 966 | cp_error ("union `%T' with no named members cannot be initialized", |
7177d104 MS |
967 | type); |
968 | TREE_VALUE (tail) = error_mark_node; | |
969 | } | |
8d08fdba MS |
970 | |
971 | if (TREE_VALUE (tail) != 0) | |
972 | { | |
973 | tree tail1 = tail; | |
974 | ||
975 | next1 = digest_init (TREE_TYPE (field), | |
976 | TREE_VALUE (tail), &tail1); | |
977 | if (tail1 != 0 && TREE_CODE (tail1) != TREE_LIST) | |
7177d104 | 978 | my_friendly_abort (357); |
8d08fdba MS |
979 | tail = tail1; |
980 | } | |
981 | else | |
982 | { | |
983 | next1 = error_mark_node; | |
984 | tail = TREE_CHAIN (tail); | |
985 | } | |
986 | ||
987 | if (next1 == error_mark_node) | |
988 | erroneous = 1; | |
989 | else if (!TREE_CONSTANT (next1)) | |
990 | allconstant = 0; | |
8ccc31eb | 991 | else if (initializer_constant_valid_p (next1, TREE_TYPE (next1)) == 0) |
8d08fdba | 992 | allsimple = 0; |
e66d884e | 993 | members = expr_tree_cons (field, next1, members); |
8d08fdba MS |
994 | } |
995 | ||
996 | /* If arguments were specified as a list, just remove the ones we used. */ | |
997 | if (elts) | |
998 | *elts = tail; | |
999 | /* If arguments were specified as a constructor, | |
1000 | complain unless we used all the elements of the constructor. */ | |
1001 | else if (tail) | |
8251199e | 1002 | pedwarn ("excess elements in aggregate initializer"); |
8d08fdba MS |
1003 | |
1004 | if (erroneous) | |
1005 | return error_mark_node; | |
1006 | ||
1007 | result = build (CONSTRUCTOR, type, NULL_TREE, nreverse (members)); | |
1008 | if (init) | |
1009 | TREE_HAS_CONSTRUCTOR (result) = TREE_HAS_CONSTRUCTOR (init); | |
1010 | if (allconstant) TREE_CONSTANT (result) = 1; | |
1011 | if (allconstant && allsimple) TREE_STATIC (result) = 1; | |
1012 | return result; | |
1013 | } | |
1014 | \f | |
1015 | /* Given a structure or union value DATUM, construct and return | |
1016 | the structure or union component which results from narrowing | |
be99da77 | 1017 | that value by the type specified in BASETYPE. For example, given the |
8d08fdba MS |
1018 | hierarchy |
1019 | ||
1020 | class L { int ii; }; | |
1021 | class A : L { ... }; | |
1022 | class B : L { ... }; | |
1023 | class C : A, B { ... }; | |
1024 | ||
1025 | and the declaration | |
1026 | ||
1027 | C x; | |
1028 | ||
1029 | then the expression | |
1030 | ||
be99da77 | 1031 | x.A::ii refers to the ii member of the L part of |
38e01259 | 1032 | the A part of the C object named by X. In this case, |
e92cc029 | 1033 | DATUM would be x, and BASETYPE would be A. */ |
8d08fdba MS |
1034 | |
1035 | tree | |
be99da77 | 1036 | build_scoped_ref (datum, basetype) |
8d08fdba | 1037 | tree datum; |
be99da77 | 1038 | tree basetype; |
8d08fdba MS |
1039 | { |
1040 | tree ref; | |
1041 | tree type = TREE_TYPE (datum); | |
1042 | ||
1043 | if (datum == error_mark_node) | |
1044 | return error_mark_node; | |
1045 | ||
1046 | if (TREE_CODE (type) == REFERENCE_TYPE) | |
1047 | type = TREE_TYPE (type); | |
1048 | ||
1049 | type = TYPE_MAIN_VARIANT (type); | |
1050 | ||
8d08fdba | 1051 | /* This is an easy conversion. */ |
be99da77 | 1052 | if (is_aggr_type (basetype, 1)) |
8d08fdba | 1053 | { |
be99da77 | 1054 | tree binfo = TYPE_BINFO (basetype); |
8d08fdba MS |
1055 | if (binfo != TYPE_BINFO (type)) |
1056 | { | |
1057 | binfo = get_binfo (binfo, type, 1); | |
1058 | if (binfo == error_mark_node) | |
1059 | return error_mark_node; | |
1060 | if (binfo == 0) | |
be99da77 | 1061 | return error_not_base_type (basetype, type); |
8d08fdba MS |
1062 | } |
1063 | ||
1064 | switch (TREE_CODE (datum)) | |
1065 | { | |
1066 | case NOP_EXPR: | |
1067 | case CONVERT_EXPR: | |
1068 | case FLOAT_EXPR: | |
1069 | case FIX_TRUNC_EXPR: | |
1070 | case FIX_FLOOR_EXPR: | |
1071 | case FIX_ROUND_EXPR: | |
1072 | case FIX_CEIL_EXPR: | |
1073 | ref = convert_pointer_to (binfo, | |
1074 | build_unary_op (ADDR_EXPR, TREE_OPERAND (datum, 0), 0)); | |
1075 | break; | |
1076 | default: | |
1077 | ref = convert_pointer_to (binfo, | |
1078 | build_unary_op (ADDR_EXPR, datum, 0)); | |
1079 | } | |
1080 | return build_indirect_ref (ref, "(compiler error in build_scoped_ref)"); | |
1081 | } | |
1082 | return error_mark_node; | |
1083 | } | |
1084 | ||
1085 | /* Build a reference to an object specified by the C++ `->' operator. | |
1086 | Usually this just involves dereferencing the object, but if the | |
1087 | `->' operator is overloaded, then such overloads must be | |
1088 | performed until an object which does not have the `->' operator | |
1089 | overloaded is found. An error is reported when circular pointer | |
1090 | delegation is detected. */ | |
e92cc029 | 1091 | |
8d08fdba MS |
1092 | tree |
1093 | build_x_arrow (datum) | |
1094 | tree datum; | |
1095 | { | |
1096 | tree types_memoized = NULL_TREE; | |
1097 | register tree rval = datum; | |
1098 | tree type = TREE_TYPE (rval); | |
a703fb38 | 1099 | tree last_rval = NULL_TREE; |
8d08fdba MS |
1100 | |
1101 | if (type == error_mark_node) | |
1102 | return error_mark_node; | |
1103 | ||
5156628f | 1104 | if (processing_template_decl) |
5566b478 MS |
1105 | return build_min_nt (ARROW_EXPR, rval); |
1106 | ||
a0a33927 MS |
1107 | if (TREE_CODE (rval) == OFFSET_REF) |
1108 | { | |
1109 | rval = resolve_offset_ref (datum); | |
1110 | type = TREE_TYPE (rval); | |
1111 | } | |
1112 | ||
8d08fdba MS |
1113 | if (TREE_CODE (type) == REFERENCE_TYPE) |
1114 | { | |
1115 | rval = convert_from_reference (rval); | |
1116 | type = TREE_TYPE (rval); | |
1117 | } | |
1118 | ||
3c215895 | 1119 | if (IS_AGGR_TYPE (type)) |
8d08fdba | 1120 | { |
3c215895 JM |
1121 | while ((rval = build_opfncall (COMPONENT_REF, LOOKUP_NORMAL, rval, |
1122 | NULL_TREE, NULL_TREE))) | |
8d08fdba MS |
1123 | { |
1124 | if (rval == error_mark_node) | |
1125 | return error_mark_node; | |
1126 | ||
1127 | if (value_member (TREE_TYPE (rval), types_memoized)) | |
1128 | { | |
8251199e | 1129 | error ("circular pointer delegation detected"); |
8d08fdba MS |
1130 | return error_mark_node; |
1131 | } | |
1132 | else | |
1133 | { | |
1134 | types_memoized = tree_cons (NULL_TREE, TREE_TYPE (rval), | |
1135 | types_memoized); | |
1136 | } | |
1137 | last_rval = rval; | |
1138 | } | |
297dcfb3 MM |
1139 | |
1140 | if (last_rval == NULL_TREE) | |
1141 | { | |
8251199e | 1142 | cp_error ("base operand of `->' has non-pointer type `%T'", type); |
297dcfb3 MM |
1143 | return error_mark_node; |
1144 | } | |
1145 | ||
8d08fdba MS |
1146 | if (TREE_CODE (TREE_TYPE (last_rval)) == REFERENCE_TYPE) |
1147 | last_rval = convert_from_reference (last_rval); | |
1148 | } | |
1149 | else | |
1150 | last_rval = default_conversion (rval); | |
1151 | ||
8d08fdba MS |
1152 | if (TREE_CODE (TREE_TYPE (last_rval)) == POINTER_TYPE) |
1153 | return build_indirect_ref (last_rval, NULL_PTR); | |
1154 | ||
8d08fdba | 1155 | if (types_memoized) |
8251199e | 1156 | error ("result of `operator->()' yields non-pointer result"); |
8d08fdba | 1157 | else |
8251199e | 1158 | error ("base operand of `->' is not a pointer"); |
8d08fdba MS |
1159 | return error_mark_node; |
1160 | } | |
1161 | ||
1162 | /* Make an expression to refer to the COMPONENT field of | |
1163 | structure or union value DATUM. COMPONENT is an arbitrary | |
1164 | expression. DATUM has not already been checked out to be of | |
1165 | aggregate type. | |
1166 | ||
1167 | For C++, COMPONENT may be a TREE_LIST. This happens when we must | |
1168 | return an object of member type to a method of the current class, | |
1169 | but there is not yet enough typing information to know which one. | |
1170 | As a special case, if there is only one method by that name, | |
1171 | it is returned. Otherwise we return an expression which other | |
1172 | routines will have to know how to deal with later. */ | |
e92cc029 | 1173 | |
8d08fdba MS |
1174 | tree |
1175 | build_m_component_ref (datum, component) | |
1176 | tree datum, component; | |
1177 | { | |
1178 | tree type; | |
1179 | tree objtype = TREE_TYPE (datum); | |
1180 | tree rettype; | |
71851aaa | 1181 | tree binfo; |
8d08fdba | 1182 | |
5156628f | 1183 | if (processing_template_decl) |
5566b478 MS |
1184 | return build_min_nt (DOTSTAR_EXPR, datum, component); |
1185 | ||
8d08fdba MS |
1186 | if (TYPE_PTRMEMFUNC_P (TREE_TYPE (component))) |
1187 | { | |
1188 | type = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (component))); | |
1189 | rettype = type; | |
1190 | } | |
1191 | else | |
1192 | { | |
162bc98d | 1193 | type = TREE_TYPE (TREE_TYPE (component)); |
4ac14744 | 1194 | rettype = TREE_TYPE (type); |
8d08fdba MS |
1195 | } |
1196 | ||
1197 | if (datum == error_mark_node || component == error_mark_node) | |
1198 | return error_mark_node; | |
1199 | ||
8d08fdba MS |
1200 | if (TREE_CODE (type) != OFFSET_TYPE && TREE_CODE (type) != METHOD_TYPE) |
1201 | { | |
8251199e | 1202 | cp_error ("`%E' cannot be used as a member pointer, since it is of type `%T'", component, type); |
8d08fdba MS |
1203 | return error_mark_node; |
1204 | } | |
1205 | ||
1206 | if (TREE_CODE (objtype) == REFERENCE_TYPE) | |
1207 | objtype = TREE_TYPE (objtype); | |
db5ae43f | 1208 | objtype = TYPE_MAIN_VARIANT (objtype); |
8d08fdba | 1209 | |
51c184be MS |
1210 | if (! IS_AGGR_TYPE (objtype)) |
1211 | { | |
8251199e JM |
1212 | cp_error ("cannot apply member pointer `%E' to `%E'", component, datum); |
1213 | cp_error ("which is of non-aggregate type `%T'", objtype); | |
51c184be MS |
1214 | return error_mark_node; |
1215 | } | |
71851aaa MS |
1216 | |
1217 | binfo = get_binfo (TYPE_METHOD_BASETYPE (type), objtype, 1); | |
1218 | if (binfo == NULL_TREE) | |
8d08fdba | 1219 | { |
8251199e | 1220 | cp_error ("member type `%T::' incompatible with object type `%T'", |
8d08fdba MS |
1221 | TYPE_METHOD_BASETYPE (type), objtype); |
1222 | return error_mark_node; | |
1223 | } | |
71851aaa MS |
1224 | else if (binfo == error_mark_node) |
1225 | return error_mark_node; | |
8d08fdba | 1226 | |
d2e5ee5c MS |
1227 | component = build (OFFSET_REF, rettype, datum, component); |
1228 | if (TREE_CODE (type) == OFFSET_TYPE) | |
1229 | component = resolve_offset_ref (component); | |
1230 | return component; | |
8d08fdba MS |
1231 | } |
1232 | ||
fc378698 | 1233 | /* Return a tree node for the expression TYPENAME '(' PARMS ')'. */ |
e92cc029 | 1234 | |
8d08fdba MS |
1235 | tree |
1236 | build_functional_cast (exp, parms) | |
1237 | tree exp; | |
1238 | tree parms; | |
1239 | { | |
1240 | /* This is either a call to a constructor, | |
1241 | or a C cast in C++'s `functional' notation. */ | |
fc378698 | 1242 | tree type; |
8d08fdba MS |
1243 | |
1244 | if (exp == error_mark_node || parms == error_mark_node) | |
1245 | return error_mark_node; | |
1246 | ||
1247 | if (TREE_CODE (exp) == IDENTIFIER_NODE) | |
1248 | { | |
8d08fdba MS |
1249 | if (IDENTIFIER_HAS_TYPE_VALUE (exp)) |
1250 | /* Either an enum or an aggregate type. */ | |
1251 | type = IDENTIFIER_TYPE_VALUE (exp); | |
1252 | else | |
1253 | { | |
1254 | type = lookup_name (exp, 1); | |
1255 | if (!type || TREE_CODE (type) != TYPE_DECL) | |
1256 | { | |
8251199e | 1257 | cp_error ("`%T' fails to be a typedef or built-in type", exp); |
8d08fdba MS |
1258 | return error_mark_node; |
1259 | } | |
1260 | type = TREE_TYPE (type); | |
1261 | } | |
1262 | } | |
45537677 MS |
1263 | else if (TREE_CODE (exp) == TYPE_DECL) |
1264 | type = TREE_TYPE (exp); | |
8d08fdba MS |
1265 | else |
1266 | type = exp; | |
1267 | ||
5156628f | 1268 | if (processing_template_decl) |
5566b478 MS |
1269 | return build_min (CAST_EXPR, type, parms); |
1270 | ||
8d08fdba MS |
1271 | if (! IS_AGGR_TYPE (type)) |
1272 | { | |
1273 | /* this must build a C cast */ | |
1274 | if (parms == NULL_TREE) | |
d18c083e | 1275 | parms = integer_zero_node; |
8ccc31eb | 1276 | else |
a0a33927 | 1277 | { |
8ccc31eb | 1278 | if (TREE_CHAIN (parms) != NULL_TREE) |
8251199e | 1279 | pedwarn ("initializer list being treated as compound expression"); |
a0a33927 MS |
1280 | parms = build_compound_expr (parms); |
1281 | } | |
8ccc31eb | 1282 | |
faf5394a | 1283 | return build_c_cast (type, parms); |
8d08fdba MS |
1284 | } |
1285 | ||
45537677 MS |
1286 | /* Prepare to evaluate as a call to a constructor. If this expression |
1287 | is actually used, for example, | |
1288 | ||
1289 | return X (arg1, arg2, ...); | |
1290 | ||
1291 | then the slot being initialized will be filled in. */ | |
1292 | ||
5566b478 | 1293 | if (TYPE_SIZE (complete_type (type)) == NULL_TREE) |
8d08fdba | 1294 | { |
8251199e | 1295 | cp_error ("type `%T' is not yet defined", type); |
8d08fdba MS |
1296 | return error_mark_node; |
1297 | } | |
a7a64a77 MM |
1298 | if (abstract_virtuals_error (NULL_TREE, type)) |
1299 | return error_mark_node; | |
8d08fdba MS |
1300 | |
1301 | if (parms && TREE_CHAIN (parms) == NULL_TREE) | |
faf5394a | 1302 | return build_c_cast (type, TREE_VALUE (parms)); |
8d08fdba | 1303 | |
3551c177 JM |
1304 | /* We need to zero-initialize POD types. Let's do that for everything |
1305 | that doesn't need a constructor. */ | |
1306 | if (parms == NULL_TREE && !TYPE_NEEDS_CONSTRUCTING (type) | |
1307 | && TYPE_HAS_DEFAULT_CONSTRUCTOR (type)) | |
1308 | { | |
1309 | exp = build (CONSTRUCTOR, type, NULL_TREE, NULL_TREE); | |
1310 | return get_target_expr (exp); | |
1311 | } | |
1312 | ||
fc378698 MS |
1313 | exp = build_method_call (NULL_TREE, ctor_identifier, parms, |
1314 | TYPE_BINFO (type), LOOKUP_NORMAL); | |
8d08fdba | 1315 | |
fc378698 | 1316 | if (exp == error_mark_node) |
a0a33927 | 1317 | return error_mark_node; |
8d08fdba | 1318 | |
fc378698 | 1319 | return build_cplus_new (type, exp); |
8d08fdba MS |
1320 | } |
1321 | \f | |
1322 | /* Return the character string for the name that encodes the | |
1323 | enumeral value VALUE in the domain TYPE. */ | |
e92cc029 | 1324 | |
8d08fdba MS |
1325 | char * |
1326 | enum_name_string (value, type) | |
1327 | tree value; | |
1328 | tree type; | |
1329 | { | |
1330 | register tree values = TYPE_VALUES (type); | |
1331 | register HOST_WIDE_INT intval = TREE_INT_CST_LOW (value); | |
1332 | ||
1333 | my_friendly_assert (TREE_CODE (type) == ENUMERAL_TYPE, 324); | |
1334 | while (values | |
1335 | && TREE_INT_CST_LOW (TREE_VALUE (values)) != intval) | |
1336 | values = TREE_CHAIN (values); | |
1337 | if (values == NULL_TREE) | |
1338 | { | |
1339 | char *buf = (char *)oballoc (16 + TYPE_NAME_LENGTH (type)); | |
1340 | ||
1341 | /* Value must have been cast. */ | |
63d088b7 KG |
1342 | sprintf (buf, "(enum %s)%ld", |
1343 | TYPE_NAME_STRING (type), (long) intval); | |
8d08fdba MS |
1344 | return buf; |
1345 | } | |
1346 | return IDENTIFIER_POINTER (TREE_PURPOSE (values)); | |
1347 | } | |
1348 | ||
f0e01782 | 1349 | #if 0 |
8d08fdba MS |
1350 | /* Print out a language-specific error message for |
1351 | (Pascal) case or (C) switch statements. | |
1352 | CODE tells what sort of message to print. | |
1353 | TYPE is the type of the switch index expression. | |
1354 | NEW is the new value that we were trying to add. | |
1355 | OLD is the old value that stopped us from adding it. */ | |
e92cc029 | 1356 | |
8d08fdba MS |
1357 | void |
1358 | report_case_error (code, type, new_value, old_value) | |
1359 | int code; | |
1360 | tree type; | |
1361 | tree new_value, old_value; | |
1362 | { | |
1363 | if (code == 1) | |
1364 | { | |
1365 | if (new_value) | |
8251199e | 1366 | error ("case label not within a switch statement"); |
8d08fdba | 1367 | else |
8251199e | 1368 | error ("default label not within a switch statement"); |
8d08fdba MS |
1369 | } |
1370 | else if (code == 2) | |
1371 | { | |
1372 | if (new_value == 0) | |
1373 | { | |
8251199e | 1374 | error ("multiple default labels in one switch"); |
8d08fdba MS |
1375 | return; |
1376 | } | |
1377 | if (TREE_CODE (new_value) == RANGE_EXPR) | |
1378 | if (TREE_CODE (old_value) == RANGE_EXPR) | |
1379 | { | |
1380 | char *buf = (char *)alloca (4 * (8 + TYPE_NAME_LENGTH (type))); | |
1381 | if (TREE_CODE (type) == ENUMERAL_TYPE) | |
1382 | sprintf (buf, "overlapping ranges [%s..%s], [%s..%s] in case expression", | |
1383 | enum_name_string (TREE_OPERAND (new_value, 0), type), | |
1384 | enum_name_string (TREE_OPERAND (new_value, 1), type), | |
1385 | enum_name_string (TREE_OPERAND (old_value, 0), type), | |
1386 | enum_name_string (TREE_OPERAND (old_value, 1), type)); | |
1387 | else | |
1388 | sprintf (buf, "overlapping ranges [%d..%d], [%d..%d] in case expression", | |
1389 | TREE_INT_CST_LOW (TREE_OPERAND (new_value, 0)), | |
1390 | TREE_INT_CST_LOW (TREE_OPERAND (new_value, 1)), | |
1391 | TREE_INT_CST_LOW (TREE_OPERAND (old_value, 0)), | |
1392 | TREE_INT_CST_LOW (TREE_OPERAND (old_value, 1))); | |
1393 | error (buf); | |
1394 | } | |
1395 | else | |
1396 | { | |
1397 | char *buf = (char *)alloca (4 * (8 + TYPE_NAME_LENGTH (type))); | |
1398 | if (TREE_CODE (type) == ENUMERAL_TYPE) | |
1399 | sprintf (buf, "range [%s..%s] includes element `%s' in case expression", | |
1400 | enum_name_string (TREE_OPERAND (new_value, 0), type), | |
1401 | enum_name_string (TREE_OPERAND (new_value, 1), type), | |
1402 | enum_name_string (old_value, type)); | |
1403 | else | |
1404 | sprintf (buf, "range [%d..%d] includes (%d) in case expression", | |
1405 | TREE_INT_CST_LOW (TREE_OPERAND (new_value, 0)), | |
1406 | TREE_INT_CST_LOW (TREE_OPERAND (new_value, 1)), | |
1407 | TREE_INT_CST_LOW (old_value)); | |
1408 | error (buf); | |
1409 | } | |
1410 | else if (TREE_CODE (old_value) == RANGE_EXPR) | |
1411 | { | |
1412 | char *buf = (char *)alloca (4 * (8 + TYPE_NAME_LENGTH (type))); | |
1413 | if (TREE_CODE (type) == ENUMERAL_TYPE) | |
1414 | sprintf (buf, "range [%s..%s] includes element `%s' in case expression", | |
1415 | enum_name_string (TREE_OPERAND (old_value, 0), type), | |
1416 | enum_name_string (TREE_OPERAND (old_value, 1), type), | |
1417 | enum_name_string (new_value, type)); | |
1418 | else | |
1419 | sprintf (buf, "range [%d..%d] includes (%d) in case expression", | |
1420 | TREE_INT_CST_LOW (TREE_OPERAND (old_value, 0)), | |
1421 | TREE_INT_CST_LOW (TREE_OPERAND (old_value, 1)), | |
1422 | TREE_INT_CST_LOW (new_value)); | |
1423 | error (buf); | |
1424 | } | |
1425 | else | |
1426 | { | |
1427 | if (TREE_CODE (type) == ENUMERAL_TYPE) | |
8251199e | 1428 | error ("duplicate label `%s' in switch statement", |
8d08fdba MS |
1429 | enum_name_string (new_value, type)); |
1430 | else | |
8251199e | 1431 | error ("duplicate label (%d) in switch statement", |
8d08fdba MS |
1432 | TREE_INT_CST_LOW (new_value)); |
1433 | } | |
1434 | } | |
1435 | else if (code == 3) | |
1436 | { | |
1437 | if (TREE_CODE (type) == ENUMERAL_TYPE) | |
8251199e | 1438 | warning ("case value out of range for enum %s", |
8d08fdba MS |
1439 | TYPE_NAME_STRING (type)); |
1440 | else | |
8251199e | 1441 | warning ("case value out of range"); |
8d08fdba MS |
1442 | } |
1443 | else if (code == 4) | |
1444 | { | |
1445 | if (TREE_CODE (type) == ENUMERAL_TYPE) | |
8251199e | 1446 | error ("range values `%s' and `%s' reversed", |
8d08fdba MS |
1447 | enum_name_string (new_value, type), |
1448 | enum_name_string (old_value, type)); | |
1449 | else | |
8251199e | 1450 | error ("range values reversed"); |
8d08fdba MS |
1451 | } |
1452 | } | |
f0e01782 | 1453 | #endif |
46b02c6d | 1454 | |
86910c53 JM |
1455 | /* Complain about defining new types in inappropriate places. We give an |
1456 | exception for C-style casts, to accommodate GNU C stylings. */ | |
1457 | ||
46b02c6d MS |
1458 | void |
1459 | check_for_new_type (string, inptree) | |
d8e178a0 | 1460 | const char *string; |
46b02c6d MS |
1461 | flagged_type_tree inptree; |
1462 | { | |
86910c53 JM |
1463 | if (inptree.new_type_flag |
1464 | && (pedantic || strcmp (string, "cast") != 0)) | |
8251199e | 1465 | pedwarn ("ANSI C++ forbids defining types within %s",string); |
46b02c6d | 1466 | } |
4cc1d462 NS |
1467 | |
1468 | /* Add new exception specifier SPEC, to the LIST we currently have. | |
1469 | If it's already in LIST then do nothing. | |
1470 | Moan if it's bad and we're allowed to. COMPLAIN < 0 means we | |
1471 | know what we're doing. */ | |
1472 | ||
1473 | tree | |
1474 | add_exception_specifier (list, spec, complain) | |
1475 | tree list, spec; | |
1476 | int complain; | |
1477 | { | |
1478 | int ok; | |
1479 | tree core = spec; | |
1480 | int is_ptr; | |
1481 | ||
1482 | if (spec == error_mark_node) | |
1483 | return list; | |
1484 | ||
1485 | my_friendly_assert (spec && (!list || TREE_VALUE (list)), 19990317); | |
1486 | ||
1487 | /* [except.spec] 1, type in an exception specifier shall not be | |
1488 | incomplete, or pointer or ref to incomplete other than pointer | |
1489 | to cv void. */ | |
1490 | is_ptr = TREE_CODE (core) == POINTER_TYPE; | |
1491 | if (is_ptr || TREE_CODE (core) == REFERENCE_TYPE) | |
1492 | core = TREE_TYPE (core); | |
1493 | if (complain < 0) | |
1494 | ok = 1; | |
1495 | else if (TYPE_MAIN_VARIANT (core) == void_type_node) | |
1496 | ok = is_ptr; | |
1497 | else if (TREE_CODE (core) == TEMPLATE_TYPE_PARM) | |
1498 | ok = 1; | |
1499 | else | |
76554ea3 | 1500 | ok = TYPE_SIZE (complete_type (core)) != NULL_TREE; |
4cc1d462 NS |
1501 | |
1502 | if (ok) | |
1503 | { | |
1504 | tree probe; | |
1505 | ||
1506 | for (probe = list; probe; probe = TREE_CHAIN (probe)) | |
1507 | if (same_type_p (TREE_VALUE (probe), spec)) | |
1508 | break; | |
1509 | if (!probe) | |
1510 | { | |
1511 | spec = build_decl_list (NULL_TREE, spec); | |
1512 | TREE_CHAIN (spec) = list; | |
1513 | list = spec; | |
1514 | } | |
1515 | } | |
1516 | else if (complain) | |
1517 | incomplete_type_error (NULL_TREE, core); | |
1518 | return list; | |
1519 | } |