059375b5e270163dd79994193e9102691d571f25
[gcc.git] / gcc / cp / semantics.c
1 /* Perform the semantic phase of parsing, i.e., the process of
2 building tree structure, checking semantic consistency, and
3 building RTL. These routines are used both during actual parsing
4 and during the instantiation of template functions.
5
6 Copyright (C) 1998, 1999 Free Software Foundation, Inc.
7 Written by Mark Mitchell (mmitchell@usa.net) based on code found
8 formerly in parse.y and pt.c.
9
10 This file is part of GNU CC.
11
12 GNU CC is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2, or (at your option)
15 any later version.
16
17 GNU CC is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with GNU CC; see the file COPYING. If not, write to the Free
24 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 02111-1307, USA. */
26
27 #include "config.h"
28 #include "system.h"
29 #include "tree.h"
30 #include "cp-tree.h"
31 #include "except.h"
32 #include "lex.h"
33 #include "toplev.h"
34
35 /* There routines provide a modular interface to perform many parsing
36 operations. They may therefore be used during actual parsing, or
37 during template instantiation, which may be regarded as a
38 degenerate form of parsing. Since the current g++ parser is
39 lacking in several respects, and will be reimplemented, we are
40 attempting to move most code that is not directly related to
41 parsing into this file; that will make implementing the new parser
42 much easier since it will be able to make use of these routines. */
43
44 /* When parsing a template, LAST_TREE contains the last statement
45 parsed. These are chained together through the TREE_CHAIN field,
46 but often need to be re-organized since the parse is performed
47 bottom-up. This macro makes LAST_TREE the indicated SUBSTMT of
48 STMT. */
49
50 #define RECHAIN_STMTS(stmt, substmt, last) \
51 do { \
52 substmt = last; \
53 TREE_CHAIN (stmt) = NULL_TREE; \
54 last_tree = stmt; \
55 } while (0)
56
57 #define RECHAIN_STMTS_FROM_LAST(stmt, substmt) \
58 RECHAIN_STMTS (stmt, substmt, last_tree)
59
60 #define RECHAIN_STMTS_FROM_CHAIN(stmt, substmt) \
61 RECHAIN_STMTS (stmt, substmt, TREE_CHAIN (stmt))
62
63 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
64
65 void
66 finish_expr_stmt (expr)
67 tree expr;
68 {
69 if (expr != NULL_TREE)
70 {
71 if (!processing_template_decl)
72 {
73 emit_line_note (input_filename, lineno);
74 /* Do default conversion if safe and possibly important,
75 in case within ({...}). */
76 if ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
77 && lvalue_p (expr))
78 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE)
79 expr = default_conversion (expr);
80 }
81
82 cplus_expand_expr_stmt (expr);
83 clear_momentary ();
84 }
85
86 finish_stmt ();
87 }
88
89 /* Begin an if-statement. Returns a newly created IF_STMT if
90 appropriate. */
91
92 tree
93 begin_if_stmt ()
94 {
95 tree r;
96
97 if (processing_template_decl)
98 {
99 r = build_min_nt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
100 add_tree (r);
101 }
102 else
103 r = NULL_TREE;
104
105 do_pushlevel ();
106
107 return r;
108 }
109
110 /* Process the COND of an if-statement, which may be given by
111 IF_STMT. */
112
113 void
114 finish_if_stmt_cond (cond, if_stmt)
115 tree cond;
116 tree if_stmt;
117 {
118 if (processing_template_decl)
119 {
120 if (last_tree != if_stmt)
121 RECHAIN_STMTS_FROM_LAST (if_stmt, IF_COND (if_stmt));
122 else
123 IF_COND (if_stmt) = copy_to_permanent (cond);
124 }
125 else
126 {
127 emit_line_note (input_filename, lineno);
128 expand_start_cond (condition_conversion (cond), 0);
129 }
130 }
131
132 /* Finish the then-clause of an if-statement, which may be given by
133 IF_STMT. */
134
135 tree
136 finish_then_clause (if_stmt)
137 tree if_stmt;
138 {
139 if (processing_template_decl)
140 {
141 RECHAIN_STMTS_FROM_CHAIN (if_stmt,
142 THEN_CLAUSE (if_stmt));
143 last_tree = if_stmt;
144 return if_stmt;
145 }
146 else
147 return NULL_TREE;
148 }
149
150 /* Begin the else-clause of an if-statement. */
151
152 void
153 begin_else_clause ()
154 {
155 if (!processing_template_decl)
156 expand_start_else ();
157 }
158
159 /* Finish the else-clause of an if-statement, which may be given by
160 IF_STMT. */
161
162 void
163 finish_else_clause (if_stmt)
164 tree if_stmt;
165 {
166 if (processing_template_decl)
167 RECHAIN_STMTS_FROM_CHAIN (if_stmt, ELSE_CLAUSE (if_stmt));
168 }
169
170 /* Finsh an if-statement. */
171
172 void
173 finish_if_stmt ()
174 {
175 if (!processing_template_decl)
176 expand_end_cond ();
177
178 do_poplevel ();
179 finish_stmt ();
180 }
181
182 /* Begin a while-statement. Returns a newly created WHILE_STMT if
183 appropriate. */
184
185 tree
186 begin_while_stmt ()
187 {
188 tree r;
189
190 if (processing_template_decl)
191 {
192 r = build_min_nt (WHILE_STMT, NULL_TREE, NULL_TREE);
193 add_tree (r);
194 }
195 else
196 {
197 emit_nop ();
198 emit_line_note (input_filename, lineno);
199 expand_start_loop (1);
200 r = NULL_TREE;
201 }
202
203 do_pushlevel ();
204
205 return r;
206 }
207
208 /* Process the COND of an if-statement, which may be given by
209 WHILE_STMT. */
210
211 void
212 finish_while_stmt_cond (cond, while_stmt)
213 tree cond;
214 tree while_stmt;
215 {
216 if (processing_template_decl)
217 {
218 if (last_tree != while_stmt)
219 RECHAIN_STMTS_FROM_LAST (while_stmt,
220 WHILE_COND (while_stmt));
221 else
222 TREE_OPERAND (while_stmt, 0) = copy_to_permanent (cond);
223 }
224 else
225 {
226 emit_line_note (input_filename, lineno);
227 expand_exit_loop_if_false (0, condition_conversion (cond));
228 }
229
230 /* If COND wasn't a declaration, clear out the
231 block we made for it and start a new one here so the
232 optimization in expand_end_loop will work. */
233 if (getdecls () == NULL_TREE)
234 {
235 do_poplevel ();
236 do_pushlevel ();
237 }
238 }
239
240 /* Finish a while-statement, which may be given by WHILE_STMT. */
241
242 void
243 finish_while_stmt (while_stmt)
244 tree while_stmt;
245 {
246 do_poplevel ();
247
248 if (processing_template_decl)
249 RECHAIN_STMTS_FROM_CHAIN (while_stmt, WHILE_BODY (while_stmt));
250 else
251 expand_end_loop ();
252 finish_stmt ();
253 }
254
255 /* Begin a do-statement. Returns a newly created DO_STMT if
256 appropriate. */
257
258 tree
259 begin_do_stmt ()
260 {
261 if (processing_template_decl)
262 {
263 tree r = build_min_nt (DO_STMT, NULL_TREE, NULL_TREE);
264 add_tree (r);
265 return r;
266 }
267 else
268 {
269 emit_nop ();
270 emit_line_note (input_filename, lineno);
271 expand_start_loop_continue_elsewhere (1);
272 return NULL_TREE;
273 }
274 }
275
276 /* Finish the body of a do-statement, which may be given by DO_STMT. */
277
278 void
279 finish_do_body (do_stmt)
280 tree do_stmt;
281 {
282 if (processing_template_decl)
283 RECHAIN_STMTS_FROM_CHAIN (do_stmt, DO_BODY (do_stmt));
284 else
285 expand_loop_continue_here ();
286 }
287
288 /* Finish a do-statement, which may be given by DO_STMT, and whose
289 COND is as indicated. */
290
291 void
292 finish_do_stmt (cond, do_stmt)
293 tree cond;
294 tree do_stmt;
295 {
296 if (processing_template_decl)
297 DO_COND (do_stmt) = copy_to_permanent (cond);
298 else
299 {
300 emit_line_note (input_filename, lineno);
301 expand_exit_loop_if_false (0, condition_conversion (cond));
302 expand_end_loop ();
303 }
304
305 clear_momentary ();
306 finish_stmt ();
307 }
308
309 /* Finish a return-statement. The EXPRESSION returned, if any, is as
310 indicated. */
311
312 void
313 finish_return_stmt (expr)
314 tree expr;
315 {
316 emit_line_note (input_filename, lineno);
317 c_expand_return (expr);
318 finish_stmt ();
319 }
320
321 /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
322
323 tree
324 begin_for_stmt ()
325 {
326 tree r;
327
328 if (processing_template_decl)
329 {
330 r = build_min_nt (FOR_STMT, NULL_TREE, NULL_TREE,
331 NULL_TREE, NULL_TREE);
332 add_tree (r);
333 }
334 else
335 r = NULL_TREE;
336
337 if (flag_new_for_scope > 0)
338 {
339 do_pushlevel ();
340 note_level_for_for ();
341 }
342
343 return r;
344 }
345
346 /* Finish the for-init-statement of a for-statement, which may be
347 given by FOR_STMT. */
348
349 void
350 finish_for_init_stmt (for_stmt)
351 tree for_stmt;
352 {
353 if (processing_template_decl)
354 {
355 if (last_tree != for_stmt)
356 RECHAIN_STMTS_FROM_CHAIN (for_stmt, FOR_INIT_STMT (for_stmt));
357 }
358 else
359 {
360 emit_nop ();
361 emit_line_note (input_filename, lineno);
362 expand_start_loop_continue_elsewhere (1);
363 }
364
365 do_pushlevel ();
366 }
367
368 /* Finish the COND of a for-statement, which may be given by
369 FOR_STMT. */
370
371 void
372 finish_for_cond (cond, for_stmt)
373 tree cond;
374 tree for_stmt;
375 {
376 if (processing_template_decl)
377 {
378 if (last_tree != for_stmt)
379 RECHAIN_STMTS_FROM_LAST (for_stmt, FOR_COND (for_stmt));
380 else
381 FOR_COND (for_stmt) = copy_to_permanent (cond);
382 }
383 else
384 {
385 emit_line_note (input_filename, lineno);
386 if (cond)
387 expand_exit_loop_if_false (0, condition_conversion (cond));
388 }
389
390 /* If the cond wasn't a declaration, clear out the
391 block we made for it and start a new one here so the
392 optimization in expand_end_loop will work. */
393 if (getdecls () == NULL_TREE)
394 {
395 do_poplevel ();
396 do_pushlevel ();
397 }
398 }
399
400 /* Finish the increment-EXPRESSION in a for-statement, which may be
401 given by FOR_STMT. */
402
403 void
404 finish_for_expr (expr, for_stmt)
405 tree expr;
406 tree for_stmt;
407 {
408 if (processing_template_decl)
409 FOR_EXPR (for_stmt) = expr;
410
411 /* Don't let the tree nodes for EXPR be discarded
412 by clear_momentary during the parsing of the next stmt. */
413 push_momentary ();
414 }
415
416 /* Finish the body of a for-statement, which may be given by
417 FOR_STMT. The increment-EXPR for the loop must be
418 provided. */
419
420 void
421 finish_for_stmt (expr, for_stmt)
422 tree expr;
423 tree for_stmt;
424 {
425 /* Pop the scope for the body of the loop. */
426 do_poplevel ();
427
428 if (processing_template_decl)
429 RECHAIN_STMTS_FROM_CHAIN (for_stmt, FOR_BODY (for_stmt));
430 else
431 {
432 emit_line_note (input_filename, lineno);
433 expand_loop_continue_here ();
434 if (expr)
435 cplus_expand_expr_stmt (expr);
436 expand_end_loop ();
437 }
438
439 pop_momentary ();
440
441 if (flag_new_for_scope > 0)
442 do_poplevel ();
443
444 finish_stmt ();
445 }
446
447 /* Finish a break-statement. */
448
449 void
450 finish_break_stmt ()
451 {
452 emit_line_note (input_filename, lineno);
453 if (processing_template_decl)
454 add_tree (build_min_nt (BREAK_STMT));
455 else if ( ! expand_exit_something ())
456 cp_error ("break statement not within loop or switch");
457 }
458
459 /* Finish a continue-statement. */
460
461 void
462 finish_continue_stmt ()
463 {
464 emit_line_note (input_filename, lineno);
465 if (processing_template_decl)
466 add_tree (build_min_nt (CONTINUE_STMT));
467 else if (! expand_continue_loop (0))
468 cp_error ("continue statement not within a loop");
469 }
470
471 /* Begin a switch-statement. */
472
473 void
474 begin_switch_stmt ()
475 {
476 do_pushlevel ();
477 }
478
479 /* Finish the cond of a switch-statement. Returns a new
480 SWITCH_STMT if appropriate. */
481
482 tree
483 finish_switch_cond (cond)
484 tree cond;
485 {
486 tree r;
487
488 if (processing_template_decl)
489 {
490 r = build_min_nt (SWITCH_STMT, cond, NULL_TREE);
491 add_tree (r);
492 }
493 else if (cond != error_mark_node)
494 {
495 emit_line_note (input_filename, lineno);
496 c_expand_start_case (cond);
497 r = NULL_TREE;
498 }
499 else
500 {
501 /* The code is in error, but we don't want expand_end_case to
502 crash. */
503 c_expand_start_case (boolean_false_node);
504 r = NULL_TREE;
505 }
506
507 push_switch ();
508
509 /* Don't let the tree nodes for COND be discarded by
510 clear_momentary during the parsing of the next stmt. */
511 push_momentary ();
512
513 return r;
514 }
515
516 /* Finish the body of a switch-statement, which may be given by
517 SWITCH_STMT. The COND to switch on is indicated. */
518
519 void
520 finish_switch_stmt (cond, switch_stmt)
521 tree cond;
522 tree switch_stmt;
523 {
524 if (processing_template_decl)
525 RECHAIN_STMTS_FROM_CHAIN (switch_stmt, SWITCH_BODY (switch_stmt));
526 else
527 expand_end_case (cond);
528 pop_momentary ();
529 pop_switch ();
530 do_poplevel ();
531 finish_stmt ();
532 }
533
534 /* Finish a case-label. */
535
536 void
537 finish_case_label (low_value, high_value)
538 tree low_value;
539 tree high_value;
540 {
541 do_case (low_value, high_value);
542 }
543
544
545 /* Finish a goto-statement. */
546
547 void
548 finish_goto_stmt (destination)
549 tree destination;
550 {
551 if (processing_template_decl)
552 add_tree (build_min_nt (GOTO_STMT, destination));
553 else
554 {
555 emit_line_note (input_filename, lineno);
556
557 if (TREE_CODE (destination) == IDENTIFIER_NODE)
558 {
559 tree decl = lookup_label (destination);
560 TREE_USED (decl) = 1;
561 expand_goto (decl);
562 }
563 else
564 expand_computed_goto (destination);
565 }
566 }
567
568 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
569 appropriate. */
570
571 tree
572 begin_try_block ()
573 {
574 if (processing_template_decl)
575 {
576 tree r = build_min_nt (TRY_BLOCK, NULL_TREE,
577 NULL_TREE);
578 add_tree (r);
579 return r;
580 }
581 else
582 {
583 emit_line_note (input_filename, lineno);
584 expand_start_try_stmts ();
585 return NULL_TREE;
586 }
587 }
588
589 /* Finish a try-block, which may be given by TRY_BLOCK. */
590
591 void
592 finish_try_block (try_block)
593 tree try_block;
594 {
595 if (processing_template_decl)
596 RECHAIN_STMTS_FROM_LAST (try_block, TRY_STMTS (try_block));
597 else
598 {
599 expand_start_all_catch ();
600 }
601 }
602
603 /* Finish a handler-sequence for a try-block, which may be given by
604 TRY_BLOCK. */
605
606 void
607 finish_handler_sequence (try_block)
608 tree try_block;
609 {
610 if (processing_template_decl)
611 RECHAIN_STMTS_FROM_CHAIN (try_block, TRY_HANDLERS (try_block));
612 else
613 {
614 expand_end_all_catch ();
615 }
616 }
617
618 /* Begin a handler. Returns a HANDLER if appropriate. */
619
620 tree
621 begin_handler ()
622 {
623 tree r;
624
625 if (processing_template_decl)
626 {
627 r = build_min_nt (HANDLER, NULL_TREE, NULL_TREE);
628 add_tree (r);
629 }
630 else
631 r = NULL_TREE;
632
633 do_pushlevel ();
634
635 return r;
636 }
637
638 /* Finish the handler-parameters for a handler, which may be given by
639 HANDLER. */
640
641 void
642 finish_handler_parms (handler)
643 tree handler;
644 {
645 if (processing_template_decl)
646 RECHAIN_STMTS_FROM_CHAIN (handler, HANDLER_PARMS (handler));
647 }
648
649 /* Finish a handler, which may be given by HANDLER. */
650
651 void
652 finish_handler (handler)
653 tree handler;
654 {
655 if (processing_template_decl)
656 RECHAIN_STMTS_FROM_CHAIN (handler, HANDLER_BODY (handler));
657 else
658 expand_end_catch_block ();
659
660 do_poplevel ();
661 }
662
663 /* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
664 compound-statement does not define a scope. Returns a new
665 COMPOUND_STMT if appropriate. */
666
667 tree
668 begin_compound_stmt (has_no_scope)
669 int has_no_scope;
670 {
671 tree r;
672
673 if (processing_template_decl)
674 {
675 r = build_min_nt (COMPOUND_STMT, NULL_TREE);
676 add_tree (r);
677 if (has_no_scope)
678 COMPOUND_STMT_NO_SCOPE (r) = 1;
679 }
680 else
681 r = NULL_TREE;
682
683 if (!has_no_scope)
684 do_pushlevel ();
685
686 return r;
687 }
688
689
690 /* Finish a compound-statement, which may be given by COMPOUND_STMT.
691 If HAS_NO_SCOPE is non-zero, the compound statement does not define
692 a scope. */
693
694 tree
695 finish_compound_stmt (has_no_scope, compound_stmt)
696 int has_no_scope;
697 tree compound_stmt;
698 {
699 tree r;
700
701 if (!has_no_scope)
702 r = do_poplevel ();
703 else
704 r = NULL_TREE;
705
706 if (processing_template_decl)
707 RECHAIN_STMTS_FROM_CHAIN (compound_stmt,
708 COMPOUND_BODY (compound_stmt));
709
710 finish_stmt ();
711
712 return r;
713 }
714
715 /* Finish an asm-statement, whose components are a CV_QUALIFIER, a
716 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
717 CLOBBERS. */
718
719 void
720 finish_asm_stmt (cv_qualifier, string, output_operands,
721 input_operands, clobbers)
722 tree cv_qualifier;
723 tree string;
724 tree output_operands;
725 tree input_operands;
726 tree clobbers;
727 {
728 if (TREE_CHAIN (string))
729 {
730 if (processing_template_decl)
731 {
732 /* We need to build the combined string on the permanent
733 obstack so that we can use it during instantiations. */
734 push_obstacks_nochange ();
735 end_temporary_allocation ();
736 }
737
738 string = combine_strings (string);
739
740 if (processing_template_decl)
741 pop_obstacks ();
742 }
743
744 if (processing_template_decl)
745 {
746 tree r = build_min_nt (ASM_STMT, cv_qualifier, string,
747 output_operands, input_operands,
748 clobbers);
749 add_tree (r);
750 }
751 else
752 {
753 emit_line_note (input_filename, lineno);
754 if (output_operands != NULL_TREE || input_operands != NULL_TREE
755 || clobbers != NULL_TREE)
756 {
757 tree t;
758
759 if (cv_qualifier != NULL_TREE
760 && cv_qualifier != ridpointers[(int) RID_VOLATILE])
761 cp_warning ("%s qualifier ignored on asm",
762 IDENTIFIER_POINTER (cv_qualifier));
763
764 for (t = input_operands; t; t = TREE_CHAIN (t))
765 TREE_VALUE (t) = decay_conversion (TREE_VALUE (t));
766
767 c_expand_asm_operands (string, output_operands,
768 input_operands,
769 clobbers,
770 cv_qualifier
771 == ridpointers[(int) RID_VOLATILE],
772 input_filename, lineno);
773 }
774 else
775 {
776 /* Don't warn about redundant specification of 'volatile' here. */
777 if (cv_qualifier != NULL_TREE
778 && cv_qualifier != ridpointers[(int) RID_VOLATILE])
779 cp_warning ("%s qualifier ignored on asm",
780 IDENTIFIER_POINTER (cv_qualifier));
781 expand_asm (string);
782 }
783
784 finish_stmt ();
785 }
786 }
787
788 /* Finish a parenthesized expression EXPR. */
789
790 tree
791 finish_parenthesized_expr (expr)
792 tree expr;
793 {
794 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr))))
795 /* This inhibits warnings in truthvalue_conversion. */
796 C_SET_EXP_ORIGINAL_CODE (expr, ERROR_MARK);
797
798 return expr;
799 }
800
801 /* Begin a statement-expression. The value returned must be passed to
802 finish_stmt_expr. */
803
804 tree
805 begin_stmt_expr ()
806 {
807 keep_next_level ();
808 /* If we're processing_template_decl, then the upcoming compound
809 statement will be chained onto the tree structure, starting at
810 last_tree. We return last_tree so that we can later unhook the
811 compound statement. */
812 return processing_template_decl ? last_tree : expand_start_stmt_expr();
813 }
814
815 /* Finish a statement-expression. RTL_EXPR should be the value
816 returned by the previous begin_stmt_expr; EXPR is the
817 statement-expression. Returns an expression representing the
818 statement-expression. */
819
820 tree
821 finish_stmt_expr (rtl_expr, expr)
822 tree rtl_expr;
823 tree expr;
824 {
825 tree result;
826
827 if (!processing_template_decl)
828 {
829 rtl_expr = expand_end_stmt_expr (rtl_expr);
830 /* The statements have side effects, so the group does. */
831 TREE_SIDE_EFFECTS (rtl_expr) = 1;
832 }
833
834 if (TREE_CODE (expr) == BLOCK)
835 {
836 /* Make a BIND_EXPR for the BLOCK already made. */
837 if (processing_template_decl)
838 result = build_min_nt (BIND_EXPR, NULL_TREE, last_tree,
839 NULL_TREE);
840 else
841 result = build (BIND_EXPR, TREE_TYPE (rtl_expr),
842 NULL_TREE, rtl_expr, expr);
843
844 /* Remove the block from the tree at this point.
845 It gets put back at the proper place
846 when the BIND_EXPR is expanded. */
847 delete_block (expr);
848 }
849 else
850 result = expr;
851
852 if (processing_template_decl)
853 {
854 /* Remove the compound statement from the tree structure; it is
855 now saved in the BIND_EXPR. */
856 last_tree = rtl_expr;
857 TREE_CHAIN (last_tree) = NULL_TREE;
858 }
859
860 return result;
861 }
862
863 /* Finish a call to FN with ARGS. Returns a representation of the
864 call. */
865
866 tree
867 finish_call_expr (fn, args, koenig)
868 tree fn;
869 tree args;
870 int koenig;
871 {
872 tree result;
873
874 if (koenig)
875 {
876 if (TREE_CODE (fn) == BIT_NOT_EXPR)
877 fn = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND (fn, 0));
878 else if (TREE_CODE (fn) != TEMPLATE_ID_EXPR)
879 fn = do_identifier (fn, 2, args);
880 }
881 result = build_x_function_call (fn, args, current_class_ref);
882
883 if (TREE_CODE (result) == CALL_EXPR
884 && (! TREE_TYPE (result)
885 || TREE_CODE (TREE_TYPE (result)) != VOID_TYPE))
886 result = require_complete_type (result);
887
888 return result;
889 }
890
891 /* Finish a call to a postfix increment or decrement or EXPR. (Which
892 is indicated by CODE, which should be POSTINCREMENT_EXPR or
893 POSTDECREMENT_EXPR.) */
894
895 tree
896 finish_increment_expr (expr, code)
897 tree expr;
898 enum tree_code code;
899 {
900 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
901 a COMPONENT_REF). This way if we've got, say, a reference to a
902 static member that's being operated on, we don't end up trying to
903 find a member operator for the class it's in. */
904
905 if (TREE_CODE (expr) == OFFSET_REF)
906 expr = resolve_offset_ref (expr);
907 return build_x_unary_op (code, expr);
908 }
909
910 /* Finish a use of `this'. Returns an expression for `this'. */
911
912 tree
913 finish_this_expr ()
914 {
915 tree result;
916
917 if (current_class_ptr)
918 {
919 #ifdef WARNING_ABOUT_CCD
920 TREE_USED (current_class_ptr) = 1;
921 #endif
922 result = current_class_ptr;
923 }
924 else if (current_function_decl
925 && DECL_STATIC_FUNCTION_P (current_function_decl))
926 {
927 error ("`this' is unavailable for static member functions");
928 result = error_mark_node;
929 }
930 else
931 {
932 if (current_function_decl)
933 error ("invalid use of `this' in non-member function");
934 else
935 error ("invalid use of `this' at top level");
936 result = error_mark_node;
937 }
938
939 return result;
940 }
941
942 /* Finish a member function call using OBJECT and ARGS as arguments to
943 FN. Returns an expression for the call. */
944
945 tree
946 finish_object_call_expr (fn, object, args)
947 tree fn;
948 tree object;
949 tree args;
950 {
951 #if 0
952 /* This is a future direction of this code, but because
953 build_x_function_call cannot always undo what is done in
954 build_component_ref entirely yet, we cannot do this. */
955
956 tree real_fn = build_component_ref (object, fn, NULL_TREE, 1);
957 return finish_call_expr (real_fn, args);
958 #else
959 if (TREE_CODE (fn) == TYPE_DECL)
960 {
961 if (processing_template_decl)
962 /* This can happen on code like:
963
964 class X;
965 template <class T> void f(T t) {
966 t.X();
967 }
968
969 We just grab the underlying IDENTIFIER. */
970 fn = DECL_NAME (fn);
971 else
972 {
973 cp_error ("calling type `%T' like a method", fn);
974 return error_mark_node;
975 }
976 }
977
978 return build_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL);
979 #endif
980 }
981
982 /* Finish a qualified member function call using OBJECT and ARGS as
983 arguments to FN. Returns an expressino for the call. */
984
985 tree
986 finish_qualified_object_call_expr (fn, object, args)
987 tree fn;
988 tree object;
989 tree args;
990 {
991 if (IS_SIGNATURE (TREE_OPERAND (fn, 0)))
992 {
993 warning ("signature name in scope resolution ignored");
994 return finish_object_call_expr (TREE_OPERAND (fn, 1), object, args);
995 }
996 else
997 return build_scoped_method_call (object, TREE_OPERAND (fn, 0),
998 TREE_OPERAND (fn, 1), args);
999 }
1000
1001 /* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1002 being the scope, if any, of DESTRUCTOR. Returns an expression for
1003 the call. */
1004
1005 tree
1006 finish_pseudo_destructor_call_expr (object, scope, destructor)
1007 tree object;
1008 tree scope;
1009 tree destructor;
1010 {
1011 if (scope && scope != destructor)
1012 cp_error ("destructor specifier `%T::~%T()' must have matching names",
1013 scope, destructor);
1014
1015 if ((scope == NULL_TREE || IDENTIFIER_GLOBAL_VALUE (destructor))
1016 && (TREE_CODE (TREE_TYPE (object)) !=
1017 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor)))))
1018 cp_error ("`%E' is not of type `%T'", object, destructor);
1019
1020 return cp_convert (void_type_node, object);
1021 }
1022
1023 /* Finish a call to a globally qualified member function FN using
1024 ARGS. Returns an expression for the call. */
1025
1026 tree
1027 finish_qualified_call_expr (fn, args)
1028 tree fn;
1029 tree args;
1030 {
1031 if (processing_template_decl)
1032 return build_min_nt (CALL_EXPR, copy_to_permanent (fn), args,
1033 NULL_TREE);
1034 else
1035 return build_member_call (TREE_OPERAND (fn, 0),
1036 TREE_OPERAND (fn, 1),
1037 args);
1038 }
1039
1040 /* Finish an expression taking the address of LABEL. Returns an
1041 expression for the address. */
1042
1043 tree
1044 finish_label_address_expr (label)
1045 tree label;
1046 {
1047 tree result;
1048
1049 label = lookup_label (label);
1050 if (label == NULL_TREE)
1051 result = null_pointer_node;
1052 else
1053 {
1054 TREE_USED (label) = 1;
1055 result = build1 (ADDR_EXPR, ptr_type_node, label);
1056 TREE_CONSTANT (result) = 1;
1057 }
1058
1059 return result;
1060 }
1061
1062 /* Finish an expression of the form CODE EXPR. */
1063
1064 tree
1065 finish_unary_op_expr (code, expr)
1066 enum tree_code code;
1067 tree expr;
1068 {
1069 tree result = build_x_unary_op (code, expr);
1070 if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST)
1071 TREE_NEGATED_INT (result) = 1;
1072 overflow_warning (result);
1073 return result;
1074 }
1075
1076 /* Finish an id-expression. */
1077
1078 tree
1079 finish_id_expr (expr)
1080 tree expr;
1081 {
1082 if (TREE_CODE (expr) == IDENTIFIER_NODE)
1083 expr = do_identifier (expr, 1, NULL_TREE);
1084
1085 return expr;
1086 }
1087
1088 /* Begin a new-placement. */
1089
1090 int
1091 begin_new_placement ()
1092 {
1093 /* The arguments to a placement new might be passed to a
1094 deallocation function, in the event that the allocation throws an
1095 exception. Since we don't expand exception handlers until the
1096 end of a function, we must make sure the arguments stay around
1097 that long. */
1098 return suspend_momentary ();
1099 }
1100
1101 /* Finish a new-placement. The ARGS are the placement arguments. The
1102 COOKIE is the value returned by the previous call to
1103 begin_new_placement. */
1104
1105 tree
1106 finish_new_placement (args, cookie)
1107 tree args;
1108 int cookie;
1109 {
1110 resume_momentary (cookie);
1111 return args;
1112 }
1113
1114 /* Begin a function defniition declared with DECL_SPECS and
1115 DECLARATOR. Returns non-zero if the function-declaration is
1116 legal. */
1117
1118 int
1119 begin_function_definition (decl_specs, declarator)
1120 tree decl_specs;
1121 tree declarator;
1122 {
1123 tree specs;
1124 tree attrs;
1125 split_specs_attrs (decl_specs, &specs, &attrs);
1126 if (!start_function (specs, declarator, attrs, 0))
1127 return 0;
1128
1129 reinit_parse_for_function ();
1130 /* The things we're about to see are not directly qualified by any
1131 template headers we've seen thus far. */
1132 reset_specialization ();
1133
1134 return 1;
1135 }
1136
1137 /* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1138 a SCOPE_REF. */
1139
1140 tree
1141 begin_constructor_declarator (scope, name)
1142 tree scope;
1143 tree name;
1144 {
1145 tree result = build_parse_node (SCOPE_REF, scope, name);
1146 enter_scope_of (result);
1147 return result;
1148 }
1149
1150 /* Finish an init-declarator. Returns a DECL. */
1151
1152 tree
1153 finish_declarator (declarator, declspecs, attributes,
1154 prefix_attributes, initialized)
1155 tree declarator;
1156 tree declspecs;
1157 tree attributes;
1158 tree prefix_attributes;
1159 int initialized;
1160 {
1161 return start_decl (declarator, declspecs, initialized, attributes,
1162 prefix_attributes);
1163 }
1164
1165 /* Finish a translation unit. */
1166
1167 void
1168 finish_translation_unit ()
1169 {
1170 /* In case there were missing closebraces,
1171 get us back to the global binding level. */
1172 while (! toplevel_bindings_p ())
1173 poplevel (0, 0, 0);
1174 while (current_namespace != global_namespace)
1175 pop_namespace ();
1176 finish_file ();
1177 }
1178
1179 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
1180 Returns the parameter. */
1181
1182 tree
1183 finish_template_type_parm (aggr, identifier)
1184 tree aggr;
1185 tree identifier;
1186 {
1187 if (aggr == signature_type_node)
1188 sorry ("signature as template type parameter");
1189 else if (aggr != class_type_node)
1190 {
1191 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1192 aggr = class_type_node;
1193 }
1194
1195 return build_tree_list (aggr, identifier);
1196 }
1197
1198 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
1199 Returns the parameter. */
1200
1201 tree
1202 finish_template_template_parm (aggr, identifier)
1203 tree aggr;
1204 tree identifier;
1205 {
1206 tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE);
1207 tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
1208 DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
1209 DECL_TEMPLATE_RESULT (tmpl) = decl;
1210 SET_DECL_ARTIFICIAL (decl);
1211 end_template_decl ();
1212
1213 return finish_template_type_parm (aggr, tmpl);
1214 }
1215
1216 /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1217 non-zero, the parameter list was terminated by a `...'. */
1218
1219 tree
1220 finish_parmlist (parms, ellipsis)
1221 tree parms;
1222 int ellipsis;
1223 {
1224 if (!ellipsis)
1225 chainon (parms, void_list_node);
1226 /* We mark the PARMS as a parmlist so that declarator processing can
1227 disambiguate certain constructs. */
1228 if (parms != NULL_TREE)
1229 TREE_PARMLIST (parms) = 1;
1230
1231 return parms;
1232 }
1233
1234 /* Begin a class definition, as indicated by T. */
1235
1236 tree
1237 begin_class_definition (t)
1238 tree t;
1239 {
1240 push_obstacks_nochange ();
1241 end_temporary_allocation ();
1242
1243 if (t == error_mark_node
1244 || ! IS_AGGR_TYPE (t))
1245 {
1246 t = make_lang_type (RECORD_TYPE);
1247 pushtag (make_anon_name (), t, 0);
1248 }
1249
1250 /* In a definition of a member class template, we will get here with an
1251 implicit typename, a TYPENAME_TYPE with a type. */
1252 if (TREE_CODE (t) == TYPENAME_TYPE)
1253 t = TREE_TYPE (t);
1254
1255 /* If we generated a partial instantiation of this type, but now
1256 we're seeing a real definition, we're actually looking at a
1257 partial specialization. Consider:
1258
1259 template <class T, class U>
1260 struct Y {};
1261
1262 template <class T>
1263 struct X {};
1264
1265 template <class T, class U>
1266 void f()
1267 {
1268 typename X<Y<T, U> >::A a;
1269 }
1270
1271 template <class T, class U>
1272 struct X<Y<T, U> >
1273 {
1274 };
1275
1276 We have to undo the effects of the previous partial
1277 instantiation. */
1278 if (PARTIAL_INSTANTIATION_P (t))
1279 {
1280 if (!pedantic)
1281 {
1282 /* Unfortunately, when we're not in pedantic mode, we
1283 attempt to actually fill in some of the fields of the
1284 partial instantiation, in order to support the implicit
1285 typename extension. Clear those fields now, in
1286 preparation for the definition here. The fields cleared
1287 here must match those set in instantiate_class_template.
1288 Look for a comment mentioning begin_class_definition
1289 there. */
1290 TYPE_BINFO_BASETYPES (t) = NULL_TREE;
1291 TYPE_FIELDS (t) = NULL_TREE;
1292 TYPE_METHODS (t) = NULL_TREE;
1293 CLASSTYPE_TAGS (t) = NULL_TREE;
1294 TYPE_SIZE (t) = NULL_TREE;
1295 }
1296
1297 /* This isn't a partial instantiation any more. */
1298 PARTIAL_INSTANTIATION_P (t) = 0;
1299 }
1300 /* If this type was already complete, and we see another definition,
1301 that's an error. */
1302 else if (TYPE_SIZE (t))
1303 duplicate_tag_error (t);
1304
1305 /* Update the location of the decl. */
1306 DECL_SOURCE_FILE (TYPE_NAME (t)) = input_filename;
1307 DECL_SOURCE_LINE (TYPE_NAME (t)) = lineno;
1308
1309 if (TYPE_BEING_DEFINED (t))
1310 {
1311 t = make_lang_type (TREE_CODE (t));
1312 pushtag (TYPE_IDENTIFIER (t), t, 0);
1313 }
1314 maybe_process_partial_specialization (t);
1315 pushclass (t, 1);
1316 TYPE_BEING_DEFINED (t) = 1;
1317 /* Reset the interface data, at the earliest possible
1318 moment, as it might have been set via a class foo;
1319 before. */
1320 /* Don't change signatures. */
1321 if (! IS_SIGNATURE (t))
1322 {
1323 int needs_writing;
1324 tree name = TYPE_IDENTIFIER (t);
1325
1326 if (! ANON_AGGRNAME_P (name))
1327 {
1328 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
1329 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1330 (t, interface_unknown);
1331 }
1332
1333 /* Only leave this bit clear if we know this
1334 class is part of an interface-only specification. */
1335 if (! CLASSTYPE_INTERFACE_KNOWN (t)
1336 || ! CLASSTYPE_INTERFACE_ONLY (t))
1337 CLASSTYPE_VTABLE_NEEDS_WRITING (t) = 1;
1338 }
1339 #if 0
1340 tmp = TYPE_IDENTIFIER ($<ttype>0);
1341 if (tmp && IDENTIFIER_TEMPLATE (tmp))
1342 overload_template_name (tmp, 1);
1343 #endif
1344 reset_specialization();
1345
1346 /* In case this is a local class within a template
1347 function, we save the current tree structure so
1348 that we can get it back later. */
1349 begin_tree ();
1350
1351 /* Make a declaration for this class in its own scope. */
1352 build_self_reference ();
1353
1354 return t;
1355 }
1356
1357 /* Finish the member declaration given by DECL. */
1358
1359 void
1360 finish_member_declaration (decl)
1361 tree decl;
1362 {
1363 if (decl == error_mark_node || decl == NULL_TREE)
1364 return;
1365
1366 if (decl == void_type_node)
1367 /* The COMPONENT was a friend, not a member, and so there's
1368 nothing for us to do. */
1369 return;
1370
1371 /* We should see only one DECL at a time. */
1372 my_friendly_assert (TREE_CHAIN (decl) == NULL_TREE, 0);
1373
1374 /* Set up access control for DECL. */
1375 TREE_PRIVATE (decl)
1376 = (current_access_specifier == access_private_node);
1377 TREE_PROTECTED (decl)
1378 = (current_access_specifier == access_protected_node);
1379 if (TREE_CODE (decl) == TEMPLATE_DECL)
1380 {
1381 TREE_PRIVATE (DECL_RESULT (decl)) = TREE_PRIVATE (decl);
1382 TREE_PROTECTED (DECL_RESULT (decl)) = TREE_PROTECTED (decl);
1383 }
1384
1385 /* Mark the DECL as a member of the current class. */
1386 if (TREE_CODE (decl) == FUNCTION_DECL
1387 || DECL_FUNCTION_TEMPLATE_P (decl))
1388 /* Historically, DECL_CONTEXT was not set for a FUNCTION_DECL in
1389 finish_struct. Presumably it is already set as the function is
1390 parsed. Perhaps DECL_CLASS_CONTEXT is already set, too? */
1391 DECL_CLASS_CONTEXT (decl) = current_class_type;
1392 else
1393 DECL_CONTEXT (decl) = current_class_type;
1394
1395 /* Put functions on the TYPE_METHODS list and everything else on the
1396 TYPE_FIELDS list. Note that these are built up in reverse order.
1397 We reverse them (to obtain declaration order) in finish_struct. */
1398 if (TREE_CODE (decl) == FUNCTION_DECL
1399 || DECL_FUNCTION_TEMPLATE_P (decl))
1400 {
1401 /* We also need to add this function to the
1402 CLASSTYPE_METHOD_VEC. */
1403 add_method (current_class_type, 0, decl);
1404
1405 TREE_CHAIN (decl) = TYPE_METHODS (current_class_type);
1406 TYPE_METHODS (current_class_type) = decl;
1407 }
1408 else
1409 {
1410 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
1411 go at the beginning. The reason is that lookup_field_1
1412 searches the list in order, and we want a field name to
1413 override a type name so that the "struct stat hack" will
1414 work. In particular:
1415
1416 struct S { enum E { }; int E } s;
1417 s.E = 3;
1418
1419 is legal. In addition, the FIELD_DECLs must be maintained in
1420 declaration order so that class layout works as expected.
1421 However, we don't need that order until class layout, so we
1422 save a little time by putting FIELD_DECLs on in reverse order
1423 here, and then reversing them in finish_struct_1. (We could
1424 also keep a pointer to the correct insertion points in the
1425 list.) */
1426
1427 if (TREE_CODE (decl) == TYPE_DECL)
1428 TYPE_FIELDS (current_class_type)
1429 = chainon (TYPE_FIELDS (current_class_type), decl);
1430 else
1431 {
1432 TREE_CHAIN (decl) = TYPE_FIELDS (current_class_type);
1433 TYPE_FIELDS (current_class_type) = decl;
1434 }
1435
1436 /* Enter the DECL into the scope of the class. */
1437 if (TREE_CODE (decl) != USING_DECL)
1438 pushdecl_class_level (decl);
1439 }
1440 }
1441
1442 /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
1443 the definition is immediately followed by a semicolon. Returns the
1444 type. */
1445
1446 tree
1447 finish_class_definition (t, attributes, semi, pop_scope_p)
1448 tree t;
1449 tree attributes;
1450 int semi;
1451 int pop_scope_p;
1452 {
1453 /* finish_struct nukes this anyway; if finish_exception does too,
1454 then it can go. */
1455 if (semi)
1456 note_got_semicolon (t);
1457
1458 /* If we got any attributes in class_head, xref_tag will stick them in
1459 TREE_TYPE of the type. Grab them now. */
1460 attributes = chainon (TREE_TYPE (t), attributes);
1461 TREE_TYPE (t) = NULL_TREE;
1462
1463 if (TREE_CODE (t) == ENUMERAL_TYPE)
1464 ;
1465 else
1466 {
1467 t = finish_struct (t, attributes, semi);
1468 if (semi)
1469 note_got_semicolon (t);
1470 }
1471
1472 pop_obstacks ();
1473
1474 if (! semi)
1475 check_for_missing_semicolon (t);
1476 if (pop_scope_p)
1477 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t)));
1478 if (current_scope () == current_function_decl)
1479 do_pending_defargs ();
1480
1481 return t;
1482 }
1483
1484 /* Finish processing the default argument expressions cached during
1485 the processing of a class definition. */
1486
1487 void
1488 begin_inline_definitions ()
1489 {
1490 if (pending_inlines
1491 && current_scope () == current_function_decl)
1492 do_pending_inlines ();
1493 }
1494
1495 /* Finish processing the inline function definitions cached during the
1496 processing of a class definition. */
1497
1498 void
1499 finish_inline_definitions ()
1500 {
1501 if (current_class_type == NULL_TREE)
1502 clear_inline_text_obstack ();
1503
1504 /* Undo the begin_tree in begin_class_definition. */
1505 end_tree ();
1506 }
1507
1508 /* Finish processing the declaration of a member class template
1509 TYPES whose template parameters are given by PARMS. */
1510
1511 tree
1512 finish_member_class_template (types)
1513 tree types;
1514 {
1515 tree t;
1516
1517 /* If there are declared, but undefined, partial specializations
1518 mixed in with the typespecs they will not yet have passed through
1519 maybe_process_partial_specialization, so we do that here. */
1520 for (t = types; t != NULL_TREE; t = TREE_CHAIN (t))
1521 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t))))
1522 maybe_process_partial_specialization (TREE_VALUE (t));
1523
1524 note_list_got_semicolon (types);
1525 grok_x_components (types);
1526 if (TYPE_CONTEXT (TREE_VALUE (types)) != current_class_type)
1527 /* The component was in fact a friend declaration. We avoid
1528 finish_member_template_decl performing certain checks by
1529 unsetting TYPES. */
1530 types = NULL_TREE;
1531
1532 finish_member_template_decl (types);
1533
1534 /* As with other component type declarations, we do
1535 not store the new DECL on the list of
1536 component_decls. */
1537 return NULL_TREE;
1538 }
1539
1540 /* Finish processsing a complete template declaration. The PARMS are
1541 the template parameters. */
1542
1543 void
1544 finish_template_decl (parms)
1545 tree parms;
1546 {
1547 if (parms)
1548 end_template_decl ();
1549 else
1550 end_specialization ();
1551 }
1552
1553 /* Finish processing a a template-id (which names a type) of the form
1554 NAME < ARGS >. Return the TYPE_DECL for the type named by the
1555 template-id. If ENTERING_SCOPE is non-zero we are about to enter
1556 the scope of template-id indicated. */
1557
1558 tree
1559 finish_template_type (name, args, entering_scope)
1560 tree name;
1561 tree args;
1562 int entering_scope;
1563 {
1564 tree decl;
1565
1566 decl = lookup_template_class (name, args,
1567 NULL_TREE, NULL_TREE, entering_scope);
1568 if (decl != error_mark_node)
1569 decl = TYPE_STUB_DECL (decl);
1570
1571 return decl;
1572 }
1573
1574 /* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
1575 namespace scope or a class scope. */
1576
1577 void
1578 enter_scope_of (sr)
1579 tree sr;
1580 {
1581 tree scope = TREE_OPERAND (sr, 0);
1582
1583 if (TREE_CODE (scope) == NAMESPACE_DECL)
1584 {
1585 push_decl_namespace (scope);
1586 TREE_COMPLEXITY (sr) = -1;
1587 }
1588 else if (scope != current_class_type)
1589 {
1590 if (TREE_CODE (scope) == TYPENAME_TYPE)
1591 {
1592 /* In a declarator for a template class member, the scope will
1593 get here as an implicit typename, a TYPENAME_TYPE with a type. */
1594 scope = TREE_TYPE (scope);
1595 TREE_OPERAND (sr, 0) = scope;
1596 }
1597 push_nested_class (scope, 3);
1598 TREE_COMPLEXITY (sr) = current_class_depth;
1599 }
1600 }
1601
1602 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
1603 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
1604 BASE_CLASS, or NULL_TREE if an error occurred. The
1605 ACCESSS_SPECIFIER is one of
1606 access_{default,public,protected_private}[_virtual]_node.*/
1607
1608 tree
1609 finish_base_specifier (access_specifier, base_class,
1610 current_aggr_is_signature)
1611 tree access_specifier;
1612 tree base_class;
1613 int current_aggr_is_signature;
1614 {
1615 tree type;
1616 tree result;
1617
1618 if (base_class == NULL_TREE)
1619 {
1620 error ("invalid base class");
1621 type = error_mark_node;
1622 }
1623 else
1624 type = TREE_TYPE (base_class);
1625 if (current_aggr_is_signature && access_specifier)
1626 error ("access and source specifiers not allowed in signature");
1627 if (! is_aggr_type (type, 1))
1628 result = NULL_TREE;
1629 else if (current_aggr_is_signature
1630 && (! type) && (! IS_SIGNATURE (type)))
1631 {
1632 error ("class name not allowed as base signature");
1633 result = NULL_TREE;
1634 }
1635 else if (current_aggr_is_signature)
1636 {
1637 sorry ("signature inheritance, base type `%s' ignored",
1638 IDENTIFIER_POINTER (access_specifier));
1639 result = build_tree_list (access_public_node, type);
1640 }
1641 else if (type && IS_SIGNATURE (type))
1642 {
1643 error ("signature name not allowed as base class");
1644 result = NULL_TREE;
1645 }
1646 else
1647 result = build_tree_list (access_specifier, type);
1648
1649 return result;
1650 }
1651
1652 /* Called when multiple declarators are processed. If that is not
1653 premitted in this context, an error is issued. */
1654
1655 void
1656 check_multiple_declarators ()
1657 {
1658 /* [temp]
1659
1660 In a template-declaration, explicit specialization, or explicit
1661 instantiation the init-declarator-list in the declaration shall
1662 contain at most one declarator.
1663
1664 We don't just use PROCESSING_TEMPLATE_DECL for the first
1665 condition since that would disallow the perfectly legal code,
1666 like `template <class T> struct S { int i, j; };'. */
1667 tree scope = current_scope ();
1668
1669 if (scope && TREE_CODE (scope) == FUNCTION_DECL)
1670 /* It's OK to write `template <class T> void f() { int i, j;}'. */
1671 return;
1672
1673 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
1674 || processing_explicit_instantiation
1675 || processing_specialization)
1676 cp_error ("multiple declarators in template declaration");
1677 }
1678
1679 tree
1680 finish_typeof (expr)
1681 tree expr;
1682 {
1683 if (processing_template_decl)
1684 {
1685 tree t;
1686
1687 push_obstacks_nochange ();
1688 end_temporary_allocation ();
1689
1690 t = make_lang_type (TYPEOF_TYPE);
1691 TYPE_FIELDS (t) = expr;
1692
1693 pop_obstacks ();
1694
1695 return t;
1696 }
1697
1698 return TREE_TYPE (expr);
1699 }