OSDN Git Service

* typeck2.c (abstract_virtual_errors): Reword diagnostics, make them
[pf3gnuchains/gcc-fork.git] / gcc / cp / typeck2.c
1 /* Report error messages, build initializers, and perform
2    some front-end optimizations for C++ compiler.
3    Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4    1999, 2000, 2001, 2002, 2004
5    Free Software Foundation, Inc.
6    Hacked by Michael Tiemann (tiemann@cygnus.com)
7
8 This file is part of GCC.
9
10 GCC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
13 any later version.
14
15 GCC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING.  If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA.  */
24
25
26 /* This file is part of the C++ front end.
27    It contains routines to build C++ expressions given their operands,
28    including computing the types of the result, C and C++ specific error
29    checks, and some optimization.
30
31    There are also routines to build RETURN_STMT nodes and CASE_STMT nodes,
32    and to process initializations in declarations (since they work
33    like a strange sort of assignment).  */
34
35 #include "config.h"
36 #include "system.h"
37 #include "coretypes.h"
38 #include "tm.h"
39 #include "tree.h"
40 #include "cp-tree.h"
41 #include "flags.h"
42 #include "toplev.h"
43 #include "output.h"
44 #include "diagnostic.h"
45
46 static tree process_init_constructor (tree, tree, tree *);
47
48 /* Print an error message stemming from an attempt to use
49    BASETYPE as a base class for TYPE.  */
50
51 tree
52 error_not_base_type (tree basetype, tree type)
53 {
54   if (TREE_CODE (basetype) == FUNCTION_DECL)
55     basetype = DECL_CONTEXT (basetype);
56   error ("type `%T' is not a base type for type `%T'", basetype, type);
57   return error_mark_node;
58 }
59
60 tree
61 binfo_or_else (tree base, tree type)
62 {
63   tree binfo = lookup_base (type, base, ba_ignore, NULL);
64
65   if (binfo == error_mark_node)
66     return NULL_TREE;
67   else if (!binfo)
68     error_not_base_type (base, type);
69   return binfo;
70 }
71
72 /* According to ARM $7.1.6, "A `const' object may be initialized, but its
73    value may not be changed thereafter.  Thus, we emit hard errors for these,
74    rather than just pedwarns.  If `SOFT' is 1, then we just pedwarn.  (For
75    example, conversions to references.)  */
76
77 void
78 readonly_error (tree arg, const char* string, int soft)
79 {
80   const char *fmt;
81   void (*fn) (const char *, ...);
82
83   if (soft)
84     fn = pedwarn;
85   else
86     fn = error;
87
88   if (TREE_CODE (arg) == COMPONENT_REF)
89     {
90       if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg, 0))))
91         fmt = "%s of data-member `%D' in read-only structure";
92       else
93         fmt = "%s of read-only data-member `%D'";
94       (*fn) (fmt, string, TREE_OPERAND (arg, 1));
95     }
96   else if (TREE_CODE (arg) == VAR_DECL)
97     {
98       if (DECL_LANG_SPECIFIC (arg)
99           && DECL_IN_AGGR_P (arg)
100           && !TREE_STATIC (arg))
101         fmt = "%s of constant field `%D'";
102       else
103         fmt = "%s of read-only variable `%D'";
104       (*fn) (fmt, string, arg);
105     }
106   else if (TREE_CODE (arg) == PARM_DECL)
107     (*fn) ("%s of read-only parameter `%D'", string, arg);
108   else if (TREE_CODE (arg) == INDIRECT_REF
109            && TREE_CODE (TREE_TYPE (TREE_OPERAND (arg, 0))) == REFERENCE_TYPE
110            && (TREE_CODE (TREE_OPERAND (arg, 0)) == VAR_DECL
111                || TREE_CODE (TREE_OPERAND (arg, 0)) == PARM_DECL))
112     (*fn) ("%s of read-only reference `%D'", string, TREE_OPERAND (arg, 0));
113   else if (TREE_CODE (arg) == RESULT_DECL)
114     (*fn) ("%s of read-only named return value `%D'", string, arg);
115   else if (TREE_CODE (arg) == FUNCTION_DECL)
116     (*fn) ("%s of function `%D'", string, arg);
117   else
118     (*fn) ("%s of read-only location", string);
119 }
120
121 /* If TYPE has abstract virtual functions, issue an error about trying
122    to create an object of that type.  DECL is the object declared, or
123    NULL_TREE if the declaration is unavailable.  Returns 1 if an error
124    occurred; zero if all was well.  */
125
126 int
127 abstract_virtuals_error (tree decl, tree type)
128 {
129   tree u;
130   tree tu;
131
132   if (!CLASS_TYPE_P (type) || !CLASSTYPE_PURE_VIRTUALS (type))
133     return 0;
134
135   if (!TYPE_SIZE (type))
136     /* TYPE is being defined, and during that time
137        CLASSTYPE_PURE_VIRTUALS holds the inline friends.  */
138     return 0;
139
140   if (dependent_type_p (type))
141     /* For a dependent type, we do not yet know which functions are pure
142        virtuals.  */
143     return 0;
144
145   u = CLASSTYPE_PURE_VIRTUALS (type);
146   if (decl)
147     {
148       if (TREE_CODE (decl) == RESULT_DECL)
149         return 0;
150
151       if (TREE_CODE (decl) == VAR_DECL)
152         cp_error_at ("cannot declare variable `%+D' to be of abstract "
153                      "type `%T'", decl, type);
154       else if (TREE_CODE (decl) == PARM_DECL)
155         cp_error_at ("cannot declare parameter `%+D' to be of abstract "
156                      "type `%T'", decl, type);
157       else if (TREE_CODE (decl) == FIELD_DECL)
158         cp_error_at ("cannot declare field `%+D' to be of abstract "
159                      "type `%T'", decl, type);
160       else if (TREE_CODE (decl) == FUNCTION_DECL
161                && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
162         cp_error_at ("invalid abstract return type for member function `%+#D'",
163                      decl);
164       else if (TREE_CODE (decl) == FUNCTION_DECL)
165         cp_error_at ("invalid abstract return type for function `%+#D'", 
166                      decl);
167       else
168         cp_error_at ("invalid abstract type for `%+D'", decl);
169     }
170   else
171     error ("cannot allocate an object of abstract type `%T'", type);
172
173   /* Only go through this once.  */
174   if (TREE_PURPOSE (u) == NULL_TREE)
175     {
176       TREE_PURPOSE (u) = error_mark_node;
177
178       inform ("%J  because the following virtual functions are pure "
179               "within `%T':", TYPE_MAIN_DECL (type), type);
180
181       for (tu = u; tu; tu = TREE_CHAIN (tu))
182         inform ("%J\t%#D", TREE_VALUE (tu), TREE_VALUE (tu));
183     }
184   else
185     inform ("%J  since type `%T' has pure virtual functions", 
186             TYPE_MAIN_DECL (type), type);
187
188   return 1;
189 }
190
191 /* Print an error message for invalid use of an incomplete type.
192    VALUE is the expression that was used (or 0 if that isn't known)
193    and TYPE is the type that was invalid.  DIAG_TYPE indicates the
194    type of diagnostic:  0 for an error, 1 for a warning, 2 for a
195    pedwarn.  */
196
197 void
198 cxx_incomplete_type_diagnostic (tree value, tree type, int diag_type)
199 {
200   int decl = 0;
201   void (*p_msg) (const char *, ...);
202   void (*p_msg_at) (const char *, ...);
203
204   if (diag_type == 1)
205     {
206       p_msg = warning;
207       p_msg_at = cp_warning_at;
208     }
209   else if (diag_type == 2)
210     {
211       p_msg = pedwarn;
212       p_msg_at = cp_pedwarn_at;
213     }
214   else
215     {
216       p_msg = error;
217       p_msg_at = cp_error_at;
218     }
219   
220   /* Avoid duplicate error message.  */
221   if (TREE_CODE (type) == ERROR_MARK)
222     return;
223
224   if (value != 0 && (TREE_CODE (value) == VAR_DECL
225                      || TREE_CODE (value) == PARM_DECL
226                      || TREE_CODE (value) == FIELD_DECL))
227     {
228       (*p_msg_at) ("`%D' has incomplete type", value);
229       decl = 1;
230     }
231 retry:
232   /* We must print an error message.  Be clever about what it says.  */
233
234   switch (TREE_CODE (type))
235     {
236     case RECORD_TYPE:
237     case UNION_TYPE:
238     case ENUMERAL_TYPE:
239       if (!decl)
240         (*p_msg) ("invalid use of undefined type `%#T'", type);
241       if (!TYPE_TEMPLATE_INFO (type))
242         (*p_msg_at) ("forward declaration of `%#T'", type);
243       else
244         (*p_msg_at) ("declaration of `%#T'", type);
245       break;
246
247     case VOID_TYPE:
248       (*p_msg) ("invalid use of `%T'", type);
249       break;
250
251     case ARRAY_TYPE:
252       if (TYPE_DOMAIN (type))
253         {
254           type = TREE_TYPE (type);
255           goto retry;
256         }
257       (*p_msg) ("invalid use of array with unspecified bounds");
258       break;
259
260     case OFFSET_TYPE:
261     bad_member:
262       (*p_msg) ("invalid use of member (did you forget the `&' ?)");
263       break;
264
265     case TEMPLATE_TYPE_PARM:
266       (*p_msg) ("invalid use of template type parameter");
267       break;
268
269     case UNKNOWN_TYPE:
270       if (value && TREE_CODE (value) == COMPONENT_REF)
271         goto bad_member;
272       else if (value && TREE_CODE (value) == ADDR_EXPR)
273         (*p_msg) ("address of overloaded function with no contextual type information");
274       else if (value && TREE_CODE (value) == OVERLOAD)
275         (*p_msg) ("overloaded function with no contextual type information");
276       else
277         (*p_msg) ("insufficient contextual information to determine type");
278       break;
279     
280     default:
281       abort ();
282     }
283 }
284
285 /* Backward-compatibility interface to incomplete_type_diagnostic;
286    required by ../tree.c.  */
287 #undef cxx_incomplete_type_error
288 void
289 cxx_incomplete_type_error (tree value, tree type)
290 {
291   cxx_incomplete_type_diagnostic (value, type, 0);
292 }
293
294 \f
295 /* The recursive part of split_nonconstant_init.  DEST is an lvalue
296    expression to which INIT should be assigned.  INIT is a CONSTRUCTOR.
297    PCODE is a pointer to the tail of a chain of statements being emitted.
298    The return value is the new tail of that chain after new statements
299    are generated.  */
300
301 static tree *
302 split_nonconstant_init_1 (tree dest, tree init, tree *pcode)
303 {
304   tree *pelt, elt, type = TREE_TYPE (dest);
305   tree sub, code, inner_type = NULL;
306   bool array_type_p = false;
307
308   pelt = &CONSTRUCTOR_ELTS (init);
309   switch (TREE_CODE (type))
310     {
311     case ARRAY_TYPE:
312       inner_type = TREE_TYPE (type);
313       array_type_p = true;
314       /* FALLTHRU */
315
316     case RECORD_TYPE:
317     case UNION_TYPE:
318     case QUAL_UNION_TYPE:
319       while ((elt = *pelt))
320         {
321           tree field_index = TREE_PURPOSE (elt);
322           tree value = TREE_VALUE (elt);
323
324           if (!array_type_p)
325             inner_type = TREE_TYPE (field_index);
326
327           if (TREE_CODE (value) == CONSTRUCTOR)
328             {
329               if (array_type_p)
330                 sub = build (ARRAY_REF, inner_type, dest, field_index);
331               else
332                 sub = build (COMPONENT_REF, inner_type, dest, field_index);
333
334               pcode = split_nonconstant_init_1 (sub, value, pcode);
335             }
336           else if (!initializer_constant_valid_p (value, inner_type))
337             {
338               *pelt = TREE_CHAIN (elt);
339
340               if (array_type_p)
341                 sub = build (ARRAY_REF, inner_type, dest, field_index);
342               else
343                 sub = build (COMPONENT_REF, inner_type, dest, field_index);
344
345               code = build (MODIFY_EXPR, inner_type, sub, value);
346               code = build_stmt (EXPR_STMT, code);
347
348               *pcode = code;
349               pcode = &TREE_CHAIN (code);
350               continue;
351             }
352           pelt = &TREE_CHAIN (elt);
353         }
354       break;
355
356     case VECTOR_TYPE:
357       if (!initializer_constant_valid_p (init, type))
358         {
359           CONSTRUCTOR_ELTS (init) = NULL;
360           code = build (MODIFY_EXPR, type, dest, init);
361           code = build_stmt (EXPR_STMT, code);
362           pcode = &TREE_CHAIN (code);
363         }
364       break;
365
366     default:
367       abort ();
368     }
369
370   return pcode;
371 }
372
373 /* A subroutine of store_init_value.  Splits non-constant static 
374    initializer INIT into a constant part and generates code to
375    perform the non-constant part of the initialization to DEST.
376    Returns the code for the runtime init.  */
377
378 static tree
379 split_nonconstant_init (tree dest, tree init)
380 {
381   tree code;
382
383   if (TREE_CODE (init) == CONSTRUCTOR)
384     {
385       code = build_stmt (COMPOUND_STMT, NULL_TREE);
386       split_nonconstant_init_1 (dest, init, &COMPOUND_BODY (code));
387       code = build1 (STMT_EXPR, void_type_node, code);
388       TREE_SIDE_EFFECTS (code) = 1;
389       DECL_INITIAL (dest) = init;
390       TREE_READONLY (dest) = 0;
391     }
392   else
393     code = build (INIT_EXPR, TREE_TYPE (dest), dest, init);
394
395   return code;
396 }
397
398 /* Perform appropriate conversions on the initial value of a variable,
399    store it in the declaration DECL,
400    and print any error messages that are appropriate.
401    If the init is invalid, store an ERROR_MARK.
402
403    C++: Note that INIT might be a TREE_LIST, which would mean that it is
404    a base class initializer for some aggregate type, hopefully compatible
405    with DECL.  If INIT is a single element, and DECL is an aggregate
406    type, we silently convert INIT into a TREE_LIST, allowing a constructor
407    to be called.
408
409    If INIT is a TREE_LIST and there is no constructor, turn INIT
410    into a CONSTRUCTOR and use standard initialization techniques.
411    Perhaps a warning should be generated?
412
413    Returns code to be executed if initialization could not be performed
414    for static variable.  In that case, caller must emit the code.  */
415
416 tree
417 store_init_value (tree decl, tree init)
418 {
419   tree value, type;
420
421   /* If variable's type was invalidly declared, just ignore it.  */
422
423   type = TREE_TYPE (decl);
424   if (TREE_CODE (type) == ERROR_MARK)
425     return NULL_TREE;
426
427   if (IS_AGGR_TYPE (type))
428     {
429       if (! TYPE_HAS_TRIVIAL_INIT_REF (type)
430           && TREE_CODE (init) != CONSTRUCTOR)
431         abort ();
432
433       if (TREE_CODE (init) == TREE_LIST)
434         {
435           error ("constructor syntax used, but no constructor declared for type `%T'", type);
436           init = build_constructor (NULL_TREE, nreverse (init));
437         }
438     }
439   else if (TREE_CODE (init) == TREE_LIST
440            && TREE_TYPE (init) != unknown_type_node)
441     {
442       if (TREE_CODE (decl) == RESULT_DECL)
443         init = build_x_compound_expr_from_list (init,
444                                                 "return value initializer");
445       else if (TREE_CODE (init) == TREE_LIST
446                && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
447         {
448           error ("cannot initialize arrays using this syntax");
449           return NULL_TREE;
450         }
451       else
452         /* We get here with code like `int a (2);' */
453         init = build_x_compound_expr_from_list (init, "initializer");
454     }
455
456   /* End of special C++ code.  */
457
458   /* Digest the specified initializer into an expression.  */
459   value = digest_init (type, init, (tree *) 0);
460
461   /* Store the expression if valid; else report error.  */
462
463   if (TREE_CODE (value) == ERROR_MARK)
464     ;
465   /* Other code expects that initializers for objects of types that need
466      constructing never make it into DECL_INITIAL, and passes 'init' to
467      build_aggr_init without checking DECL_INITIAL.  So just return.  */
468   else if (TYPE_NEEDS_CONSTRUCTING (type))
469     return build (INIT_EXPR, type, decl, value);
470   else if (TREE_STATIC (decl)
471            && (! TREE_CONSTANT (value)
472                || ! initializer_constant_valid_p (value, TREE_TYPE (value))))
473     return split_nonconstant_init (decl, value);
474   
475   /* Store the VALUE in DECL_INITIAL.  If we're building a
476      statement-tree we will actually expand the initialization later
477      when we output this function.  */
478   DECL_INITIAL (decl) = value;
479   return NULL_TREE;
480 }
481
482 \f
483 /* Digest the parser output INIT as an initializer for type TYPE.
484    Return a C expression of type TYPE to represent the initial value.
485
486    If TAIL is nonzero, it points to a variable holding a list of elements
487    of which INIT is the first.  We update the list stored there by
488    removing from the head all the elements that we use.
489    Normally this is only one; we use more than one element only if
490    TYPE is an aggregate and INIT is not a constructor.  */
491
492 tree
493 digest_init (tree type, tree init, tree* tail)
494 {
495   enum tree_code code = TREE_CODE (type);
496   tree element = NULL_TREE;
497   tree old_tail_contents = NULL_TREE;
498
499   /* By default, assume we use one element from a list.
500      We correct this later in the sole case where it is not true.  */
501
502   if (tail)
503     {
504       old_tail_contents = *tail;
505       *tail = TREE_CHAIN (*tail);
506     }
507
508   if (init == error_mark_node || (TREE_CODE (init) == TREE_LIST
509                                   && TREE_VALUE (init) == error_mark_node))
510     return error_mark_node;
511
512   if (TREE_CODE (init) == ERROR_MARK)
513     /* __PRETTY_FUNCTION__'s initializer is a bogus expression inside
514        a template function. This gets substituted during instantiation.  */
515     return init;
516
517   /* We must strip the outermost array type when completing the type,
518      because the its bounds might be incomplete at the moment.  */
519   if (!complete_type_or_else (TREE_CODE (type) == ARRAY_TYPE
520                               ? TREE_TYPE (type) : type, NULL_TREE))
521     return error_mark_node;
522   
523   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
524   if (TREE_CODE (init) == NON_LVALUE_EXPR)
525     init = TREE_OPERAND (init, 0);
526
527   if (BRACE_ENCLOSED_INITIALIZER_P (init)
528       && CONSTRUCTOR_ELTS (init) != 0
529       && TREE_CHAIN (CONSTRUCTOR_ELTS (init)) == 0)
530     {
531       element = TREE_VALUE (CONSTRUCTOR_ELTS (init));
532       /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
533       if (element && TREE_CODE (element) == NON_LVALUE_EXPR)
534         element = TREE_OPERAND (element, 0);
535       if (element == error_mark_node)
536         return element;
537     }
538
539   /* Initialization of an array of chars from a string constant
540      optionally enclosed in braces.  */
541
542   if (code == ARRAY_TYPE)
543     {
544       tree typ1;
545
546       if (TREE_CODE (init) == TREE_LIST)
547         {
548           error ("initializing array with parameter list");
549           return error_mark_node;
550         }
551
552       typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type));
553       if (char_type_p (typ1)
554           && ((init && TREE_CODE (init) == STRING_CST)
555               || (element && TREE_CODE (element) == STRING_CST)))
556         {
557           tree string = element ? element : init;
558
559           if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string)))
560                != char_type_node)
561               && TYPE_PRECISION (typ1) == BITS_PER_UNIT)
562             {
563               error ("char-array initialized from wide string");
564               return error_mark_node;
565             }
566           if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string)))
567                == char_type_node)
568               && TYPE_PRECISION (typ1) != BITS_PER_UNIT)
569             {
570               error ("int-array initialized from non-wide string");
571               return error_mark_node;
572             }
573
574           TREE_TYPE (string) = type;
575           if (TYPE_DOMAIN (type) != 0
576               && TREE_CONSTANT (TYPE_SIZE (type)))
577             {
578               int size = TREE_INT_CST_LOW (TYPE_SIZE (type));
579               size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
580               /* In C it is ok to subtract 1 from the length of the string
581                  because it's ok to ignore the terminating null char that is
582                  counted in the length of the constant, but in C++ this would
583                  be invalid.  */
584               if (size < TREE_STRING_LENGTH (string))
585                 pedwarn ("initializer-string for array of chars is too long");
586             }
587           return string;
588         }
589     }
590
591   /* Handle scalar types, including conversions,
592      and signature pointers and references.  */
593
594   if (code == INTEGER_TYPE || code == REAL_TYPE || code == POINTER_TYPE
595       || code == ENUMERAL_TYPE || code == REFERENCE_TYPE
596       || code == BOOLEAN_TYPE || code == COMPLEX_TYPE
597       || TYPE_PTR_TO_MEMBER_P (type))
598     {
599       if (BRACE_ENCLOSED_INITIALIZER_P (init))
600         {
601           if (element == 0)
602             {
603               error ("initializer for scalar variable requires one element");
604               return error_mark_node;
605             }
606           init = element;
607         }
608       while (BRACE_ENCLOSED_INITIALIZER_P (init))
609         {
610           pedwarn ("braces around scalar initializer for `%T'", type);
611           init = CONSTRUCTOR_ELTS (init);
612           if (TREE_CHAIN (init))
613             pedwarn ("ignoring extra initializers for `%T'", type);
614           init = TREE_VALUE (init);
615         }
616
617       return convert_for_initialization (0, type, init, LOOKUP_NORMAL,
618                                          "initialization", NULL_TREE, 0);
619     }
620
621   /* Come here only for records and arrays (and unions with constructors).  */
622
623   if (COMPLETE_TYPE_P (type) && ! TREE_CONSTANT (TYPE_SIZE (type)))
624     {
625       error ("variable-sized object of type `%T' may not be initialized",
626                 type);
627       return error_mark_node;
628     }
629
630   if (code == ARRAY_TYPE || code == VECTOR_TYPE || IS_AGGR_TYPE_CODE (code))
631     {
632       if (BRACE_ENCLOSED_INITIALIZER_P (init))
633         {
634           if (TYPE_NON_AGGREGATE_CLASS (type))
635             {
636               error ("subobject of type `%T' must be initialized by constructor, not by `%E'",
637                      type, init);
638               return error_mark_node;
639             }
640           return process_init_constructor (type, init, (tree *)0);
641         }
642       else if (can_convert_arg (type, TREE_TYPE (init), init)
643                || TYPE_NON_AGGREGATE_CLASS (type))
644         /* These are never initialized from multiple constructor elements.  */;
645       else if (tail != 0)
646         {
647           *tail = old_tail_contents;
648           return process_init_constructor (type, 0, tail);
649         }
650
651       if (code != ARRAY_TYPE)
652         {
653           int flags = LOOKUP_NORMAL;
654           /* Initialization from { } is copy-initialization.  */
655           if (tail)
656             flags |= LOOKUP_ONLYCONVERTING;
657
658           return convert_for_initialization (NULL_TREE, type, init, flags,
659                                              "initialization", NULL_TREE, 0);
660         }
661     }
662
663   error ("invalid initializer");
664   return error_mark_node;
665 }
666 \f
667 /* Process a constructor for a variable of type TYPE.
668    The constructor elements may be specified either with INIT or with ELTS,
669    only one of which should be non-null.
670
671    If INIT is specified, it is a CONSTRUCTOR node which is specifically
672    and solely for initializing this datum.
673
674    If ELTS is specified, it is the address of a variable containing
675    a list of expressions.  We take as many elements as we need
676    from the head of the list and update the list.
677
678    In the resulting constructor, TREE_CONSTANT is set if all elts are
679    constant, and TREE_STATIC is set if, in addition, all elts are simple enough
680    constants that the assembler and linker can compute them.  */
681
682 static tree
683 process_init_constructor (tree type, tree init, tree* elts)
684 {
685   tree tail;
686   /* List of the elements of the result constructor,
687      in reverse order.  */
688   tree members = NULL;
689   tree next1;
690   tree result;
691   int allconstant = 1;
692   int allsimple = 1;
693   int erroneous = 0;
694
695   /* Make TAIL be the list of elements to use for the initialization,
696      no matter how the data was given to us.  */
697
698   if (elts)
699     {
700       if (warn_missing_braces)
701         warning ("aggregate has a partly bracketed initializer");
702       tail = *elts;
703     }
704   else
705     tail = CONSTRUCTOR_ELTS (init);
706
707   /* Gobble as many elements as needed, and make a constructor or initial value
708      for each element of this aggregate.  Chain them together in result.
709      If there are too few, use 0 for each scalar ultimate component.  */
710
711   if (TREE_CODE (type) == ARRAY_TYPE || TREE_CODE (type) == VECTOR_TYPE)
712     {
713       long len;
714       int i;
715
716       if (TREE_CODE (type) == ARRAY_TYPE)
717         {
718           tree domain = TYPE_DOMAIN (type);
719           if (domain)
720             len = (TREE_INT_CST_LOW (TYPE_MAX_VALUE (domain))
721                    - TREE_INT_CST_LOW (TYPE_MIN_VALUE (domain))
722                    + 1);
723           else
724             len = -1;  /* Take as many as there are.  */
725         }
726       else
727         {
728           /* Vectors are like simple fixed-size arrays.  */
729           len = TYPE_VECTOR_SUBPARTS (type);
730         }
731
732       for (i = 0; len < 0 || i < len; i++)
733         {
734           if (tail)
735             {
736               if (TREE_PURPOSE (tail)
737                   && (TREE_CODE (TREE_PURPOSE (tail)) != INTEGER_CST
738                       || compare_tree_int (TREE_PURPOSE (tail), i) != 0))
739                 sorry ("non-trivial labeled initializers");
740
741               if (TREE_VALUE (tail) != 0)
742                 {
743                   tree tail1 = tail;
744                   next1 = digest_init (TREE_TYPE (type),
745                                        TREE_VALUE (tail), &tail1);
746                   if (next1 == error_mark_node)
747                     return next1;
748                   my_friendly_assert
749                     (same_type_ignoring_top_level_qualifiers_p
750                      (TREE_TYPE (type), TREE_TYPE (next1)),
751                      981123);
752                   my_friendly_assert (tail1 == 0
753                                       || TREE_CODE (tail1) == TREE_LIST, 319);
754                   if (tail == tail1 && len < 0)
755                     {
756                       error ("non-empty initializer for array of empty elements");
757                       /* Just ignore what we were supposed to use.  */
758                       tail1 = NULL_TREE;
759                     }
760                   tail = tail1;
761                 }
762               else
763                 {
764                   next1 = error_mark_node;
765                   tail = TREE_CHAIN (tail);
766                 }
767             }
768           else if (len < 0)
769             /* We're done.  */
770             break;
771           else if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (type)))
772             {
773               /* If this type needs constructors run for
774                  default-initialization, we can't rely on the backend to do it
775                  for us, so build up TARGET_EXPRs.  If the type in question is
776                  a class, just build one up; if it's an array, recurse.  */
777
778               if (IS_AGGR_TYPE (TREE_TYPE (type)))
779                 next1 = build_functional_cast (TREE_TYPE (type), NULL_TREE);
780               else
781                 next1 = build_constructor (NULL_TREE, NULL_TREE);
782               next1 = digest_init (TREE_TYPE (type), next1, 0);
783             }
784           else if (! zero_init_p (TREE_TYPE (type)))
785             next1 = build_zero_init (TREE_TYPE (type),
786                                      /*nelts=*/NULL_TREE,
787                                      /*static_storage_p=*/false);
788           else
789             /* The default zero-initialization is fine for us; don't
790                add anything to the CONSTRUCTOR.  */
791             break;
792
793           if (next1 == error_mark_node)
794             erroneous = 1;
795           else if (!TREE_CONSTANT (next1))
796             allconstant = 0;
797           else if (! initializer_constant_valid_p (next1, TREE_TYPE (next1)))
798             allsimple = 0;
799           members = tree_cons (size_int (i), next1, members);
800         }
801     }
802   else if (TREE_CODE (type) == RECORD_TYPE)
803     {
804       tree field;
805
806       if (tail)
807         {
808           if (TYPE_USES_VIRTUAL_BASECLASSES (type))
809             {
810               sorry ("initializer list for object of class with virtual base classes");
811               return error_mark_node;
812             }
813
814           if (TYPE_BINFO_BASETYPES (type))
815             {
816               sorry ("initializer list for object of class with base classes");
817               return error_mark_node;
818             }
819
820           if (TYPE_POLYMORPHIC_P (type))
821             {
822               sorry ("initializer list for object using virtual functions");
823               return error_mark_node;
824             }
825         }
826
827       for (field = TYPE_FIELDS (type); field;
828            field = TREE_CHAIN (field))
829         {
830           if (! DECL_NAME (field) && DECL_C_BIT_FIELD (field))
831             {
832               members = tree_cons (field, integer_zero_node, members);
833               continue;
834             }
835
836           if (TREE_CODE (field) != FIELD_DECL || DECL_ARTIFICIAL (field))
837             continue;
838
839           if (tail)
840             {
841               if (TREE_PURPOSE (tail)
842                   && TREE_PURPOSE (tail) != field
843                   && TREE_PURPOSE (tail) != DECL_NAME (field))
844                 sorry ("non-trivial labeled initializers");
845
846               if (TREE_VALUE (tail) != 0)
847                 {
848                   tree tail1 = tail;
849
850                   next1 = digest_init (TREE_TYPE (field),
851                                        TREE_VALUE (tail), &tail1);
852                   my_friendly_assert (tail1 == 0
853                                       || TREE_CODE (tail1) == TREE_LIST, 320);
854                   tail = tail1;
855                 }
856               else
857                 {
858                   next1 = error_mark_node;
859                   tail = TREE_CHAIN (tail);
860                 }
861             }
862           else if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (field)))
863             {
864               /* If this type needs constructors run for
865                  default-initialization, we can't rely on the backend to do it
866                  for us, so build up TARGET_EXPRs.  If the type in question is
867                  a class, just build one up; if it's an array, recurse.  */
868
869               if (IS_AGGR_TYPE (TREE_TYPE (field)))
870                 next1 = build_functional_cast (TREE_TYPE (field),
871                                                NULL_TREE);
872               else
873                 {
874                   next1 = build_constructor (NULL_TREE, NULL_TREE);
875                   if (init)
876                     TREE_HAS_CONSTRUCTOR (next1)
877                        = TREE_HAS_CONSTRUCTOR (init);
878                 }
879               next1 = digest_init (TREE_TYPE (field), next1, 0);
880
881               /* Warn when some struct elements are implicitly initialized.  */
882               if (extra_warnings
883                   && (!init || BRACE_ENCLOSED_INITIALIZER_P (init)))
884                 warning ("missing initializer for member `%D'", field);
885             }
886           else
887             {
888               if (TREE_READONLY (field))
889                 error ("uninitialized const member `%D'", field);
890               else if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (TREE_TYPE (field)))
891                 error ("member `%D' with uninitialized const fields",
892                           field);
893               else if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE)
894                 error ("member `%D' is uninitialized reference", field);
895
896               /* Warn when some struct elements are implicitly initialized
897                  to zero.  */
898               if (extra_warnings
899                   && (!init || BRACE_ENCLOSED_INITIALIZER_P (init)))
900                 warning ("missing initializer for member `%D'", field);
901
902               if (! zero_init_p (TREE_TYPE (field)))
903                 next1 = build_zero_init (TREE_TYPE (field),
904                                          /*nelts=*/NULL_TREE,
905                                          /*static_storage_p=*/false);
906               else
907                 /* The default zero-initialization is fine for us; don't
908                    add anything to the CONSTRUCTOR.  */
909                 continue;
910             }
911
912           if (next1 == error_mark_node)
913             erroneous = 1;
914           else if (!TREE_CONSTANT (next1))
915             allconstant = 0;
916           else if (! initializer_constant_valid_p (next1, TREE_TYPE (next1)))
917             allsimple = 0;
918           members = tree_cons (field, next1, members);
919         }
920     }
921   else if (TREE_CODE (type) == UNION_TYPE
922            /* If the initializer was empty, use default zero initialization.  */
923            && tail)
924     {
925       tree field = TYPE_FIELDS (type);
926
927       /* Find the first named field.  ANSI decided in September 1990
928          that only named fields count here.  */
929       while (field && (!DECL_NAME (field) || TREE_CODE (field) != FIELD_DECL))
930         field = TREE_CHAIN (field);
931
932       /* If this element specifies a field, initialize via that field.  */
933       if (TREE_PURPOSE (tail) != NULL_TREE)
934         {
935           int win = 0;
936
937           if (TREE_CODE (TREE_PURPOSE (tail)) == FIELD_DECL)
938             /* Handle the case of a call by build_c_cast.  */
939             field = TREE_PURPOSE (tail), win = 1;
940           else if (TREE_CODE (TREE_PURPOSE (tail)) != IDENTIFIER_NODE)
941             error ("index value instead of field name in union initializer");
942           else
943             {
944               tree temp;
945               for (temp = TYPE_FIELDS (type);
946                    temp;
947                    temp = TREE_CHAIN (temp))
948                 if (DECL_NAME (temp) == TREE_PURPOSE (tail))
949                   break;
950               if (temp)
951                 field = temp, win = 1;
952               else
953                 error ("no field `%D' in union being initialized",
954                           TREE_PURPOSE (tail));
955             }
956           if (!win)
957             TREE_VALUE (tail) = error_mark_node;
958         }
959       else if (field == 0)
960         {
961           error ("union `%T' with no named members cannot be initialized",
962                     type);
963           TREE_VALUE (tail) = error_mark_node;
964         }
965
966       if (TREE_VALUE (tail) != 0)
967         {
968           tree tail1 = tail;
969
970           next1 = digest_init (TREE_TYPE (field),
971                                TREE_VALUE (tail), &tail1);
972           if (tail1 != 0 && TREE_CODE (tail1) != TREE_LIST)
973             abort ();
974           tail = tail1;
975         }
976       else
977         {
978           next1 = error_mark_node;
979           tail = TREE_CHAIN (tail);
980         }
981
982       if (next1 == error_mark_node)
983         erroneous = 1;
984       else if (!TREE_CONSTANT (next1))
985         allconstant = 0;
986       else if (initializer_constant_valid_p (next1, TREE_TYPE (next1)) == 0)
987         allsimple = 0;
988       members = tree_cons (field, next1, members);
989     }
990
991   /* If arguments were specified as a list, just remove the ones we used.  */
992   if (elts)
993     *elts = tail;
994   /* If arguments were specified as a constructor,
995      complain unless we used all the elements of the constructor.  */
996   else if (tail)
997     pedwarn ("excess elements in aggregate initializer");
998
999   if (erroneous)
1000     return error_mark_node;
1001
1002   result = build_constructor (type, nreverse (members));
1003   if (TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == NULL_TREE)
1004     complete_array_type (type, result, /*do_default=*/0);
1005   if (init)
1006     TREE_HAS_CONSTRUCTOR (result) = TREE_HAS_CONSTRUCTOR (init);
1007   if (allconstant)
1008     {
1009       TREE_CONSTANT (result) = 1;
1010       TREE_INVARIANT (result) = 1;
1011       if (allsimple)
1012         TREE_STATIC (result) = 1;
1013     }
1014   return result;
1015 }
1016 \f
1017 /* Given a structure or union value DATUM, construct and return
1018    the structure or union component which results from narrowing
1019    that value to the base specified in BASETYPE.  For example, given the
1020    hierarchy
1021
1022    class L { int ii; };
1023    class A : L { ... };
1024    class B : L { ... };
1025    class C : A, B { ... };
1026
1027    and the declaration
1028
1029    C x;
1030
1031    then the expression
1032
1033    x.A::ii refers to the ii member of the L part of
1034    the A part of the C object named by X.  In this case,
1035    DATUM would be x, and BASETYPE would be A.
1036
1037    I used to think that this was nonconformant, that the standard specified
1038    that first we look up ii in A, then convert x to an L& and pull out the
1039    ii part.  But in fact, it does say that we convert x to an A&; A here
1040    is known as the "naming class".  (jason 2000-12-19)
1041
1042    BINFO_P points to a variable initialized either to NULL_TREE or to the
1043    binfo for the specific base subobject we want to convert to.  */
1044
1045 tree
1046 build_scoped_ref (tree datum, tree basetype, tree* binfo_p)
1047 {
1048   tree binfo;
1049
1050   if (datum == error_mark_node)
1051     return error_mark_node;
1052   if (*binfo_p)
1053     binfo = *binfo_p;
1054   else
1055     binfo = lookup_base (TREE_TYPE (datum), basetype, ba_check, NULL);
1056
1057   if (!binfo || binfo == error_mark_node)
1058     {
1059       *binfo_p = NULL_TREE;
1060       if (!binfo)
1061         error_not_base_type (basetype, TREE_TYPE (datum));
1062       return error_mark_node;
1063     }
1064
1065   *binfo_p = binfo;
1066   return build_base_path (PLUS_EXPR, datum, binfo, 1);
1067 }
1068
1069 /* Build a reference to an object specified by the C++ `->' operator.
1070    Usually this just involves dereferencing the object, but if the
1071    `->' operator is overloaded, then such overloads must be
1072    performed until an object which does not have the `->' operator
1073    overloaded is found.  An error is reported when circular pointer
1074    delegation is detected.  */
1075
1076 tree
1077 build_x_arrow (tree expr)
1078 {
1079   tree orig_expr = expr;
1080   tree types_memoized = NULL_TREE;
1081   tree type = TREE_TYPE (expr);
1082   tree last_rval = NULL_TREE;
1083
1084   if (type == error_mark_node)
1085     return error_mark_node;
1086
1087   if (processing_template_decl)
1088     {
1089       if (type_dependent_expression_p (expr))
1090         return build_min_nt (ARROW_EXPR, expr);
1091       expr = build_non_dependent_expr (expr);
1092     }
1093
1094   if (TREE_CODE (type) == REFERENCE_TYPE)
1095     {
1096       expr = convert_from_reference (expr);
1097       type = TREE_TYPE (expr);
1098     }
1099
1100   if (IS_AGGR_TYPE (type))
1101     {
1102       while ((expr = build_new_op (COMPONENT_REF, LOOKUP_NORMAL, expr,
1103                                    NULL_TREE, NULL_TREE,
1104                                    /*overloaded_p=*/NULL)))
1105         {
1106           if (expr == error_mark_node)
1107             return error_mark_node;
1108
1109           if (value_member (TREE_TYPE (expr), types_memoized))
1110             {
1111               error ("circular pointer delegation detected");
1112               return error_mark_node;
1113             }
1114           else
1115             {
1116               types_memoized = tree_cons (NULL_TREE, TREE_TYPE (expr),
1117                                           types_memoized);
1118             }
1119           last_rval = expr;
1120         }     
1121
1122       if (last_rval == NULL_TREE)
1123         {
1124           error ("base operand of `->' has non-pointer type `%T'", type);
1125           return error_mark_node;
1126         }
1127
1128       if (TREE_CODE (TREE_TYPE (last_rval)) == REFERENCE_TYPE)
1129         last_rval = convert_from_reference (last_rval);
1130     }
1131   else
1132     last_rval = decay_conversion (expr);
1133
1134   if (TREE_CODE (TREE_TYPE (last_rval)) == POINTER_TYPE)
1135     {
1136       if (processing_template_decl)
1137         {
1138           expr = build_min_non_dep (ARROW_EXPR, last_rval, orig_expr);
1139           /* It will be dereferenced.  */
1140           TREE_TYPE (expr) = TREE_TYPE (TREE_TYPE (last_rval));
1141           return expr;
1142         }
1143
1144       return build_indirect_ref (last_rval, NULL);
1145     }
1146
1147   if (types_memoized)
1148     error ("result of `operator->()' yields non-pointer result");
1149   else
1150     error ("base operand of `->' is not a pointer");
1151   return error_mark_node;
1152 }
1153
1154 /* Return an expression for "DATUM .* COMPONENT".  DATUM has not
1155    already been checked out to be of aggregate type.  */
1156
1157 tree
1158 build_m_component_ref (tree datum, tree component)
1159 {
1160   tree ptrmem_type;
1161   tree objtype;
1162   tree type;
1163   tree binfo;
1164
1165   datum = decay_conversion (datum);
1166
1167   if (datum == error_mark_node || component == error_mark_node)
1168     return error_mark_node;
1169
1170   ptrmem_type = TREE_TYPE (component);
1171   if (!TYPE_PTR_TO_MEMBER_P (ptrmem_type))
1172     {
1173       error ("`%E' cannot be used as a member pointer, since it is of type `%T'", 
1174              component, ptrmem_type);
1175       return error_mark_node;
1176     }
1177     
1178   objtype = TYPE_MAIN_VARIANT (TREE_TYPE (datum));  
1179   if (! IS_AGGR_TYPE (objtype))
1180     {
1181       error ("cannot apply member pointer `%E' to `%E', which is of non-aggregate type `%T'",
1182                 component, datum, objtype);
1183       return error_mark_node;
1184     }
1185
1186   type = TYPE_PTRMEM_POINTED_TO_TYPE (ptrmem_type);
1187   binfo = lookup_base (objtype, TYPE_PTRMEM_CLASS_TYPE (ptrmem_type),
1188                        ba_check, NULL);
1189   if (!binfo)
1190     {
1191       error ("member type `%T::' incompatible with object type `%T'",
1192              type, objtype);
1193       return error_mark_node;
1194     }
1195   else if (binfo == error_mark_node)
1196     return error_mark_node;
1197
1198   if (TYPE_PTRMEM_P (ptrmem_type))
1199     {
1200       /* Compute the type of the field, as described in [expr.ref].
1201          There's no such thing as a mutable pointer-to-member, so
1202          things are not as complex as they are for references to
1203          non-static data members.  */
1204       type = cp_build_qualified_type (type,
1205                                       (cp_type_quals (type)  
1206                                        | cp_type_quals (TREE_TYPE (datum))));
1207       /* Build an expression for "object + offset" where offset is the
1208          value stored in the pointer-to-data-member.  */
1209       datum = build (PLUS_EXPR, build_pointer_type (type),
1210                      build_base_path (PLUS_EXPR, build_address (datum), 
1211                                       binfo, 1),
1212                      build_nop (ptrdiff_type_node, component));
1213       return build_indirect_ref (datum, 0);
1214     }
1215   else
1216     return build (OFFSET_REF, type, datum, component);
1217 }
1218
1219 /* Return a tree node for the expression TYPENAME '(' PARMS ')'.  */
1220
1221 tree
1222 build_functional_cast (tree exp, tree parms)
1223 {
1224   /* This is either a call to a constructor,
1225      or a C cast in C++'s `functional' notation.  */
1226   tree type;
1227
1228   if (exp == error_mark_node || parms == error_mark_node)
1229     return error_mark_node;
1230
1231   if (TREE_CODE (exp) == TYPE_DECL)
1232     type = TREE_TYPE (exp);
1233   else
1234     type = exp;
1235
1236   if (processing_template_decl)
1237     {
1238       tree t = build_min (CAST_EXPR, type, parms);
1239       /* We don't know if it will or will not have side effects.  */
1240       TREE_SIDE_EFFECTS (t) = 1;
1241       return t;
1242     }
1243
1244   if (! IS_AGGR_TYPE (type))
1245     {
1246       /* This must build a C cast.  */
1247       if (parms == NULL_TREE)
1248         parms = integer_zero_node;
1249       else
1250         parms = build_x_compound_expr_from_list (parms, "functional cast");
1251
1252       return build_c_cast (type, parms);
1253     }
1254
1255   /* Prepare to evaluate as a call to a constructor.  If this expression
1256      is actually used, for example,
1257          
1258      return X (arg1, arg2, ...);
1259          
1260      then the slot being initialized will be filled in.  */
1261
1262   if (!complete_type_or_else (type, NULL_TREE))
1263     return error_mark_node;
1264   if (abstract_virtuals_error (NULL_TREE, type))
1265     return error_mark_node;
1266
1267   if (parms && TREE_CHAIN (parms) == NULL_TREE)
1268     return build_c_cast (type, TREE_VALUE (parms));
1269
1270   /* We need to zero-initialize POD types.  Let's do that for everything
1271      that doesn't need a constructor.  */
1272   if (parms == NULL_TREE && !TYPE_NEEDS_CONSTRUCTING (type)
1273       && TYPE_HAS_DEFAULT_CONSTRUCTOR (type))
1274     {
1275       exp = build_constructor (type, NULL_TREE);
1276       return get_target_expr (exp);
1277     }
1278
1279   exp = build_special_member_call (NULL_TREE, complete_ctor_identifier, parms,
1280                                    TYPE_BINFO (type), LOOKUP_NORMAL);
1281
1282   if (exp == error_mark_node)
1283     return error_mark_node;
1284
1285   return build_cplus_new (type, exp);
1286 }
1287 \f
1288
1289 /* Add new exception specifier SPEC, to the LIST we currently have.
1290    If it's already in LIST then do nothing.
1291    Moan if it's bad and we're allowed to. COMPLAIN < 0 means we
1292    know what we're doing.  */
1293
1294 tree
1295 add_exception_specifier (tree list, tree spec, int complain)
1296 {
1297   bool ok;
1298   tree core = spec;
1299   bool is_ptr;
1300   int diag_type = -1; /* none */
1301   
1302   if (spec == error_mark_node)
1303     return list;
1304   
1305   my_friendly_assert (spec && (!list || TREE_VALUE (list)), 19990317);
1306   
1307   /* [except.spec] 1, type in an exception specifier shall not be
1308      incomplete, or pointer or ref to incomplete other than pointer
1309      to cv void.  */
1310   is_ptr = TREE_CODE (core) == POINTER_TYPE;
1311   if (is_ptr || TREE_CODE (core) == REFERENCE_TYPE)
1312     core = TREE_TYPE (core);
1313   if (complain < 0)
1314     ok = true;
1315   else if (VOID_TYPE_P (core))
1316     ok = is_ptr;
1317   else if (TREE_CODE (core) == TEMPLATE_TYPE_PARM)
1318     ok = true;
1319   else if (processing_template_decl)
1320     ok = true;
1321   else
1322     {
1323       ok = true;
1324       /* 15.4/1 says that types in an exception specifier must be complete,
1325          but it seems more reasonable to only require this on definitions
1326          and calls.  So just give a pedwarn at this point; we will give an
1327          error later if we hit one of those two cases.  */
1328       if (!COMPLETE_TYPE_P (complete_type (core)))
1329         diag_type = 2; /* pedwarn */
1330     }
1331
1332   if (ok)
1333     {
1334       tree probe;
1335       
1336       for (probe = list; probe; probe = TREE_CHAIN (probe))
1337         if (same_type_p (TREE_VALUE (probe), spec))
1338           break;
1339       if (!probe)
1340         list = tree_cons (NULL_TREE, spec, list);
1341     }
1342   else
1343     diag_type = 0; /* error */
1344     
1345   if (diag_type >= 0 && complain)
1346     cxx_incomplete_type_diagnostic (NULL_TREE, core, diag_type);
1347
1348   return list;
1349 }
1350
1351 /* Combine the two exceptions specifier lists LIST and ADD, and return
1352    their union.  */
1353
1354 tree
1355 merge_exception_specifiers (tree list, tree add)
1356 {
1357   if (!list || !add)
1358     return NULL_TREE;
1359   else if (!TREE_VALUE (list))
1360     return add;
1361   else if (!TREE_VALUE (add))
1362     return list;
1363   else
1364     {
1365       tree orig_list = list;
1366       
1367       for (; add; add = TREE_CHAIN (add))
1368         {
1369           tree spec = TREE_VALUE (add);
1370           tree probe;
1371           
1372           for (probe = orig_list; probe; probe = TREE_CHAIN (probe))
1373             if (same_type_p (TREE_VALUE (probe), spec))
1374               break;
1375           if (!probe)
1376             {
1377               spec = build_tree_list (NULL_TREE, spec);
1378               TREE_CHAIN (spec) = list;
1379               list = spec;
1380             }
1381         }
1382     }
1383   return list;
1384 }
1385
1386 /* Subroutine of build_call.  Ensure that each of the types in the
1387    exception specification is complete.  Technically, 15.4/1 says that
1388    they need to be complete when we see a declaration of the function,
1389    but we should be able to get away with only requiring this when the
1390    function is defined or called.  See also add_exception_specifier.  */
1391
1392 void
1393 require_complete_eh_spec_types (tree fntype, tree decl)
1394 {
1395   tree raises;
1396   /* Don't complain about calls to op new.  */
1397   if (decl && DECL_ARTIFICIAL (decl))
1398     return;
1399   for (raises = TYPE_RAISES_EXCEPTIONS (fntype); raises;
1400        raises = TREE_CHAIN (raises))
1401     {
1402       tree type = TREE_VALUE (raises);
1403       if (type && !COMPLETE_TYPE_P (type))
1404         {
1405           if (decl)
1406             error
1407               ("call to function `%D' which throws incomplete type `%#T'",
1408                decl, type);
1409           else
1410             error ("call to function which throws incomplete type `%#T'",
1411                    decl);
1412         }
1413     }
1414 }