]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cp/semantics.c
Makefile.am: Add rule for .S files to fix bootstrap on solaris and alpha.
[thirdparty/gcc.git] / gcc / cp / semantics.c
CommitLineData
ad321293
MM
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
dbbf88d1 6 Copyright (C) 1998, 1999, 2000, 2001, 2002,
572c2b17 7 2003, 2004 Free Software Foundation, Inc.
ad321293
MM
8 Written by Mark Mitchell (mmitchell@usa.net) based on code found
9 formerly in parse.y and pt.c.
10
f5adbb8d 11 This file is part of GCC.
ad321293 12
f5adbb8d 13 GCC is free software; you can redistribute it and/or modify it
ad321293
MM
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2, or (at your option)
16 any later version.
17
f5adbb8d 18 GCC is distributed in the hope that it will be useful, but
ad321293
MM
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
f5adbb8d 24 along with GCC; see the file COPYING. If not, write to the Free
ad321293
MM
25 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 02111-1307, USA. */
27
28#include "config.h"
8d052bc7 29#include "system.h"
4977bab6
ZW
30#include "coretypes.h"
31#include "tm.h"
ad321293
MM
32#include "tree.h"
33#include "cp-tree.h"
25af8512 34#include "tree-inline.h"
6de9cd9a 35#include "tree-mudflap.h"
ad321293
MM
36#include "except.h"
37#include "lex.h"
12027a89 38#include "toplev.h"
84df082b 39#include "flags.h"
d9b2d9da 40#include "rtl.h"
d6684bc8 41#include "expr.h"
225ff119 42#include "output.h"
ea11ca7e 43#include "timevar.h"
2b85879e 44#include "debug.h"
6de9cd9a 45#include "diagnostic.h"
8cd2462c 46#include "cgraph.h"
325c3691 47#include "tree-iterator.h"
ad321293
MM
48
49/* There routines provide a modular interface to perform many parsing
50 operations. They may therefore be used during actual parsing, or
51 during template instantiation, which may be regarded as a
52 degenerate form of parsing. Since the current g++ parser is
53 lacking in several respects, and will be reimplemented, we are
54 attempting to move most code that is not directly related to
55 parsing into this file; that will make implementing the new parser
56 much easier since it will be able to make use of these routines. */
57
3a978d72
NN
58static tree maybe_convert_cond (tree);
59static tree simplify_aggr_init_exprs_r (tree *, int *, void *);
60static void emit_associated_thunks (tree);
6de9cd9a 61static tree finalize_nrv_r (tree *, int *, void *);
4985cde3 62
558475f0 63
8d241e0b
KL
64/* Deferred Access Checking Overview
65 ---------------------------------
66
67 Most C++ expressions and declarations require access checking
68 to be performed during parsing. However, in several cases,
69 this has to be treated differently.
70
71 For member declarations, access checking has to be deferred
72 until more information about the declaration is known. For
73 example:
74
75 class A {
76 typedef int X;
77 public:
78 X f();
79 };
80
81 A::X A::f();
82 A::X g();
83
84 When we are parsing the function return type `A::X', we don't
85 really know if this is allowed until we parse the function name.
86
87 Furthermore, some contexts require that access checking is
88 never performed at all. These include class heads, and template
89 instantiations.
90
91 Typical use of access checking functions is described here:
92
93 1. When we enter a context that requires certain access checking
94 mode, the function `push_deferring_access_checks' is called with
95 DEFERRING argument specifying the desired mode. Access checking
96 may be performed immediately (dk_no_deferred), deferred
97 (dk_deferred), or not performed (dk_no_check).
98
99 2. When a declaration such as a type, or a variable, is encountered,
100 the function `perform_or_defer_access_check' is called. It
101 maintains a TREE_LIST of all deferred checks.
102
103 3. The global `current_class_type' or `current_function_decl' is then
104 setup by the parser. `enforce_access' relies on these information
105 to check access.
106
107 4. Upon exiting the context mentioned in step 1,
108 `perform_deferred_access_checks' is called to check all declaration
109 stored in the TREE_LIST. `pop_deferring_access_checks' is then
110 called to restore the previous access checking mode.
111
112 In case of parsing error, we simply call `pop_deferring_access_checks'
113 without `perform_deferred_access_checks'. */
114
cf22909c
KL
115/* Data for deferred access checking. */
116static GTY(()) deferred_access *deferred_access_stack;
117static GTY(()) deferred_access *deferred_access_free_list;
118
119/* Save the current deferred access states and start deferred
120 access checking iff DEFER_P is true. */
121
572c2b17
AP
122void
123push_deferring_access_checks (deferring_kind deferring)
cf22909c
KL
124{
125 deferred_access *d;
126
78757caa
KL
127 /* For context like template instantiation, access checking
128 disabling applies to all nested context. */
129 if (deferred_access_stack
130 && deferred_access_stack->deferring_access_checks_kind == dk_no_check)
131 deferring = dk_no_check;
132
cf22909c
KL
133 /* Recycle previously used free store if available. */
134 if (deferred_access_free_list)
135 {
136 d = deferred_access_free_list;
137 deferred_access_free_list = d->next;
138 }
139 else
c68b0a84 140 d = ggc_alloc (sizeof (deferred_access));
cf22909c
KL
141
142 d->next = deferred_access_stack;
143 d->deferred_access_checks = NULL_TREE;
8d241e0b 144 d->deferring_access_checks_kind = deferring;
cf22909c
KL
145 deferred_access_stack = d;
146}
147
148/* Resume deferring access checks again after we stopped doing
149 this previously. */
150
572c2b17
AP
151void
152resume_deferring_access_checks (void)
cf22909c 153{
8d241e0b
KL
154 if (deferred_access_stack->deferring_access_checks_kind == dk_no_deferred)
155 deferred_access_stack->deferring_access_checks_kind = dk_deferred;
cf22909c
KL
156}
157
158/* Stop deferring access checks. */
159
572c2b17
AP
160void
161stop_deferring_access_checks (void)
cf22909c 162{
8d241e0b
KL
163 if (deferred_access_stack->deferring_access_checks_kind == dk_deferred)
164 deferred_access_stack->deferring_access_checks_kind = dk_no_deferred;
cf22909c
KL
165}
166
167/* Discard the current deferred access checks and restore the
168 previous states. */
169
572c2b17
AP
170void
171pop_deferring_access_checks (void)
cf22909c
KL
172{
173 deferred_access *d = deferred_access_stack;
174 deferred_access_stack = d->next;
175
176 /* Remove references to access checks TREE_LIST. */
177 d->deferred_access_checks = NULL_TREE;
178
179 /* Store in free list for later use. */
180 d->next = deferred_access_free_list;
181 deferred_access_free_list = d;
182}
183
184/* Returns a TREE_LIST representing the deferred checks.
185 The TREE_PURPOSE of each node is the type through which the
186 access occurred; the TREE_VALUE is the declaration named.
187 */
188
572c2b17
AP
189tree
190get_deferred_access_checks (void)
cf22909c
KL
191{
192 return deferred_access_stack->deferred_access_checks;
193}
194
195/* Take current deferred checks and combine with the
196 previous states if we also defer checks previously.
197 Otherwise perform checks now. */
198
572c2b17
AP
199void
200pop_to_parent_deferring_access_checks (void)
cf22909c
KL
201{
202 tree deferred_check = get_deferred_access_checks ();
203 deferred_access *d1 = deferred_access_stack;
204 deferred_access *d2 = deferred_access_stack->next;
205 deferred_access *d3 = deferred_access_stack->next->next;
206
207 /* Temporary swap the order of the top two states, just to make
208 sure the garbage collector will not reclaim the memory during
209 processing below. */
210 deferred_access_stack = d2;
211 d2->next = d1;
212 d1->next = d3;
213
214 for ( ; deferred_check; deferred_check = TREE_CHAIN (deferred_check))
215 /* Perform deferred check if required. */
216 perform_or_defer_access_check (TREE_PURPOSE (deferred_check),
217 TREE_VALUE (deferred_check));
218
219 deferred_access_stack = d1;
220 d1->next = d2;
221 d2->next = d3;
222 pop_deferring_access_checks ();
223}
224
25903d03
KL
225/* Perform the deferred access checks.
226
227 After performing the checks, we still have to keep the list
228 `deferred_access_stack->deferred_access_checks' since we may want
229 to check access for them again later in a different context.
230 For example:
231
232 class A {
233 typedef int X;
234 static X a;
235 };
236 A::X A::a, x; // No error for `A::a', error for `x'
237
238 We have to perform deferred access of `A::X', first with `A::a',
239 next with `x'. */
cf22909c 240
572c2b17
AP
241void
242perform_deferred_access_checks (void)
cf22909c
KL
243{
244 tree deferred_check;
245 for (deferred_check = deferred_access_stack->deferred_access_checks;
246 deferred_check;
247 deferred_check = TREE_CHAIN (deferred_check))
248 /* Check access. */
249 enforce_access (TREE_PURPOSE (deferred_check),
250 TREE_VALUE (deferred_check));
cf22909c
KL
251}
252
253/* Defer checking the accessibility of DECL, when looked up in
6df5158a 254 BINFO. */
cf22909c 255
572c2b17
AP
256void
257perform_or_defer_access_check (tree binfo, tree decl)
cf22909c
KL
258{
259 tree check;
260
6df5158a
NS
261 my_friendly_assert (TREE_CODE (binfo) == TREE_VEC, 20030623);
262
cf22909c 263 /* If we are not supposed to defer access checks, just check now. */
8d241e0b 264 if (deferred_access_stack->deferring_access_checks_kind == dk_no_deferred)
cf22909c 265 {
6df5158a 266 enforce_access (binfo, decl);
cf22909c
KL
267 return;
268 }
8d241e0b
KL
269 /* Exit if we are in a context that no access checking is performed. */
270 else if (deferred_access_stack->deferring_access_checks_kind == dk_no_check)
271 return;
cf22909c
KL
272
273 /* See if we are already going to perform this check. */
274 for (check = deferred_access_stack->deferred_access_checks;
275 check;
276 check = TREE_CHAIN (check))
6df5158a 277 if (TREE_VALUE (check) == decl && TREE_PURPOSE (check) == binfo)
cf22909c
KL
278 return;
279 /* If not, record the check. */
280 deferred_access_stack->deferred_access_checks
6df5158a 281 = tree_cons (binfo, decl,
cf22909c
KL
282 deferred_access_stack->deferred_access_checks);
283}
284
838dfd8a 285/* Returns nonzero if the current statement is a full expression,
f2c5f623
BC
286 i.e. temporaries created during that statement should be destroyed
287 at the end of the statement. */
35b1567d 288
f2c5f623 289int
3a978d72 290stmts_are_full_exprs_p (void)
f2c5f623 291{
ae499cce
MM
292 return current_stmt_tree ()->stmts_are_full_exprs_p;
293}
294
295/* Returns the stmt_tree (if any) to which statements are currently
296 being added. If there is no active statement-tree, NULL is
297 returned. */
298
299stmt_tree
3a978d72 300current_stmt_tree (void)
ae499cce
MM
301{
302 return (cfun
e2500fed 303 ? &cfun->language->base.x_stmt_tree
ae499cce 304 : &scope_chain->x_stmt_tree);
f2c5f623 305}
35b1567d 306
f2c5f623
BC
307/* Nonzero if TYPE is an anonymous union or struct type. We have to use a
308 flag for this because "A union for which objects or pointers are
309 declared is not an anonymous union" [class.union]. */
35b1567d 310
f2c5f623 311int
3a978d72 312anon_aggr_type_p (tree node)
35b1567d 313{
e2500fed 314 return ANON_AGGR_TYPE_P (node);
35b1567d
BC
315}
316
f2c5f623 317/* Finish a scope. */
35b1567d 318
325c3691
RH
319static tree
320do_poplevel (tree stmt_list)
35b1567d 321{
325c3691 322 tree block = NULL;
35b1567d 323
f2c5f623 324 if (stmts_are_full_exprs_p ())
325c3691 325 block = poplevel (kept_level_p (), 1, 0);
f2c5f623 326
325c3691
RH
327 stmt_list = pop_stmt_list (stmt_list);
328
329 if (!processing_template_decl)
330 {
331 stmt_list = c_build_bind_expr (block, stmt_list);
332 /* ??? See c_end_compound_stmt re statement expressions. */
35b1567d
BC
333 }
334
325c3691 335 return stmt_list;
35b1567d
BC
336}
337
f2c5f623 338/* Begin a new scope. */
35b1567d 339
325c3691 340static tree
92bc1323 341do_pushlevel (scope_kind sk)
35b1567d 342{
325c3691 343 tree ret = push_stmt_list ();
f2c5f623 344 if (stmts_are_full_exprs_p ())
325c3691
RH
345 begin_scope (sk, NULL);
346 return ret;
347}
348
caf2523d
RH
349/* Begin a conditional that might contain a declaration. When generating
350 normal code, we want the declaration to appear before the statement
351 containing the conditional. When generating template code, we want the
352 conditional to be rendered as the raw DECL_STMT. */
325c3691
RH
353
354static void
caf2523d 355begin_cond (tree *cond_p)
325c3691 356{
caf2523d
RH
357 if (processing_template_decl)
358 *cond_p = push_stmt_list ();
359}
360
361/* Finish such a conditional. */
362
363static void
364finish_cond (tree *cond_p, tree expr)
365{
366 if (processing_template_decl)
35b1567d 367 {
caf2523d
RH
368 tree cond = pop_stmt_list (*cond_p);
369 if (TREE_CODE (cond) == DECL_STMT)
370 expr = cond;
35b1567d 371 }
caf2523d 372 *cond_p = expr;
35b1567d
BC
373}
374
325c3691
RH
375/* If *COND_P specifies a conditional with a declaration, transform the
376 loop such that
caf2523d
RH
377 while (A x = 42) { }
378 for (; A x = 42;) { }
325c3691 379 becomes
caf2523d
RH
380 while (true) { A x = 42; if (!x) break; }
381 for (;;) { A x = 42; if (!x) break; }
382 The statement list for BODY will be empty if the conditional did
383 not declare anything. */
384
325c3691 385static void
caf2523d 386simplify_loop_decl_cond (tree *cond_p, tree body)
325c3691 387{
caf2523d 388 tree cond, if_stmt;
325c3691 389
caf2523d
RH
390 if (!TREE_SIDE_EFFECTS (body))
391 return;
325c3691 392
caf2523d
RH
393 cond = *cond_p;
394 *cond_p = boolean_true_node;
395
396 if_stmt = begin_if_stmt ();
397 cond = build_unary_op (TRUTH_NOT_EXPR, cond, 0);
398 finish_if_stmt_cond (cond, if_stmt);
399 finish_break_stmt ();
400 finish_then_clause (if_stmt);
401 finish_if_stmt (if_stmt);
402}
325c3691 403
35b1567d
BC
404/* Finish a goto-statement. */
405
3e4d04a1 406tree
3a978d72 407finish_goto_stmt (tree destination)
35b1567d
BC
408{
409 if (TREE_CODE (destination) == IDENTIFIER_NODE)
410 destination = lookup_label (destination);
411
412 /* We warn about unused labels with -Wunused. That means we have to
413 mark the used labels as used. */
414 if (TREE_CODE (destination) == LABEL_DECL)
415 TREE_USED (destination) = 1;
fc2b8477
MM
416 else
417 {
418 /* The DESTINATION is being used as an rvalue. */
419 if (!processing_template_decl)
420 destination = decay_conversion (destination);
421 /* We don't inline calls to functions with computed gotos.
422 Those functions are typically up to some funny business,
423 and may be depending on the labels being at particular
424 addresses, or some such. */
425 DECL_UNINLINABLE (current_function_decl) = 1;
426 }
35b1567d
BC
427
428 check_goto (destination);
429
9e14e18f 430 return add_stmt (build_stmt (GOTO_EXPR, destination));
35b1567d
BC
431}
432
ed5511d9
MM
433/* COND is the condition-expression for an if, while, etc.,
434 statement. Convert it to a boolean value, if appropriate. */
435
8ce33230 436static tree
3a978d72 437maybe_convert_cond (tree cond)
ed5511d9
MM
438{
439 /* Empty conditions remain empty. */
440 if (!cond)
441 return NULL_TREE;
442
443 /* Wait until we instantiate templates before doing conversion. */
444 if (processing_template_decl)
445 return cond;
446
447 /* Do the conversion. */
448 cond = convert_from_reference (cond);
449 return condition_conversion (cond);
450}
451
9bfadf57 452/* Finish an expression-statement, whose EXPRESSION is as indicated. */
a7e4cfa0 453
3e4d04a1 454tree
3a978d72 455finish_expr_stmt (tree expr)
ad321293 456{
3e4d04a1
RH
457 tree r = NULL_TREE;
458
ce4a0391 459 if (expr != NULL_TREE)
ad321293 460 {
a5bcc582 461 if (!processing_template_decl)
35b1567d 462 expr = convert_to_void (expr, "statement");
47d4c811
NS
463 else if (!type_dependent_expression_p (expr))
464 convert_to_void (build_non_dependent_expr (expr), "statement");
325c3691
RH
465
466 /* Simplification of inner statement expressions, compound exprs,
467 etc can result in the us already having an EXPR_STMT. */
468 if (TREE_CODE (expr) != EXPR_STMT)
469 expr = build_stmt (EXPR_STMT, expr);
470 r = add_stmt (expr);
35b1567d 471 }
364460b6 472
35b1567d 473 finish_stmt ();
558475f0 474
3e4d04a1 475 return r;
35b1567d
BC
476}
477
35b1567d 478
ad321293
MM
479/* Begin an if-statement. Returns a newly created IF_STMT if
480 appropriate. */
481
482tree
3a978d72 483begin_if_stmt (void)
ad321293 484{
325c3691
RH
485 tree r, scope;
486 scope = do_pushlevel (sk_block);
0dfdeca6 487 r = build_stmt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
325c3691 488 TREE_CHAIN (r) = scope;
caf2523d 489 begin_cond (&IF_COND (r));
ad321293
MM
490 return r;
491}
492
493/* Process the COND of an if-statement, which may be given by
494 IF_STMT. */
495
496void
3a978d72 497finish_if_stmt_cond (tree cond, tree if_stmt)
ad321293 498{
caf2523d
RH
499 finish_cond (&IF_COND (if_stmt), maybe_convert_cond (cond));
500 add_stmt (if_stmt);
325c3691 501 THEN_CLAUSE (if_stmt) = push_stmt_list ();
ad321293
MM
502}
503
504/* Finish the then-clause of an if-statement, which may be given by
505 IF_STMT. */
506
507tree
3a978d72 508finish_then_clause (tree if_stmt)
ad321293 509{
325c3691 510 THEN_CLAUSE (if_stmt) = pop_stmt_list (THEN_CLAUSE (if_stmt));
35b1567d 511 return if_stmt;
ad321293
MM
512}
513
514/* Begin the else-clause of an if-statement. */
515
325c3691
RH
516void
517begin_else_clause (tree if_stmt)
ad321293 518{
325c3691 519 ELSE_CLAUSE (if_stmt) = push_stmt_list ();
ad321293
MM
520}
521
522/* Finish the else-clause of an if-statement, which may be given by
523 IF_STMT. */
524
525void
3a978d72 526finish_else_clause (tree if_stmt)
ad321293 527{
325c3691 528 ELSE_CLAUSE (if_stmt) = pop_stmt_list (ELSE_CLAUSE (if_stmt));
ad321293
MM
529}
530
dfbb4f34 531/* Finish an if-statement. */
ad321293
MM
532
533void
325c3691 534finish_if_stmt (tree if_stmt)
ad321293 535{
325c3691
RH
536 tree scope = TREE_CHAIN (if_stmt);
537 TREE_CHAIN (if_stmt) = NULL;
538 add_stmt (do_poplevel (scope));
ad321293 539 finish_stmt ();
35b1567d
BC
540}
541
ad321293
MM
542/* Begin a while-statement. Returns a newly created WHILE_STMT if
543 appropriate. */
544
545tree
3a978d72 546begin_while_stmt (void)
ad321293
MM
547{
548 tree r;
0dfdeca6 549 r = build_stmt (WHILE_STMT, NULL_TREE, NULL_TREE);
ae499cce 550 add_stmt (r);
325c3691 551 WHILE_BODY (r) = do_pushlevel (sk_block);
caf2523d 552 begin_cond (&WHILE_COND (r));
ad321293
MM
553 return r;
554}
555
27d26ee7 556/* Process the COND of a while-statement, which may be given by
ad321293
MM
557 WHILE_STMT. */
558
559void
3a978d72 560finish_while_stmt_cond (tree cond, tree while_stmt)
ad321293 561{
caf2523d
RH
562 finish_cond (&WHILE_COND (while_stmt), maybe_convert_cond (cond));
563 simplify_loop_decl_cond (&WHILE_COND (while_stmt), WHILE_BODY (while_stmt));
ad321293
MM
564}
565
566/* Finish a while-statement, which may be given by WHILE_STMT. */
567
568void
3a978d72 569finish_while_stmt (tree while_stmt)
ad321293 570{
325c3691 571 WHILE_BODY (while_stmt) = do_poplevel (WHILE_BODY (while_stmt));
ad321293
MM
572 finish_stmt ();
573}
574
575/* Begin a do-statement. Returns a newly created DO_STMT if
576 appropriate. */
577
578tree
3a978d72 579begin_do_stmt (void)
ad321293 580{
0dfdeca6 581 tree r = build_stmt (DO_STMT, NULL_TREE, NULL_TREE);
ae499cce 582 add_stmt (r);
325c3691 583 DO_BODY (r) = push_stmt_list ();
35b1567d 584 return r;
ad321293
MM
585}
586
587/* Finish the body of a do-statement, which may be given by DO_STMT. */
588
589void
3a978d72 590finish_do_body (tree do_stmt)
ad321293 591{
325c3691 592 DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt));
ad321293
MM
593}
594
595/* Finish a do-statement, which may be given by DO_STMT, and whose
596 COND is as indicated. */
597
598void
3a978d72 599finish_do_stmt (tree cond, tree do_stmt)
ad321293 600{
ed5511d9 601 cond = maybe_convert_cond (cond);
35b1567d
BC
602 DO_COND (do_stmt) = cond;
603 finish_stmt ();
604}
ed5511d9 605
ad321293
MM
606/* Finish a return-statement. The EXPRESSION returned, if any, is as
607 indicated. */
608
3e4d04a1 609tree
3a978d72 610finish_return_stmt (tree expr)
ad321293 611{
3e4d04a1
RH
612 tree r;
613
efc7052d 614 expr = check_return_expr (expr);
35b1567d 615 if (!processing_template_decl)
efee38a9 616 {
a0de9d20 617 if (DECL_DESTRUCTOR_P (current_function_decl))
efee38a9
MM
618 {
619 /* Similarly, all destructors must run destructors for
620 base-classes before returning. So, all returns in a
dfbb4f34 621 destructor get sent to the DTOR_LABEL; finish_function emits
efee38a9 622 code to return a value there. */
3e4d04a1 623 return finish_goto_stmt (dtor_label);
efee38a9
MM
624 }
625 }
3e4d04a1 626 r = add_stmt (build_stmt (RETURN_STMT, expr));
35b1567d 627 finish_stmt ();
3e4d04a1
RH
628
629 return r;
35b1567d 630}
efee38a9 631
ad321293
MM
632/* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
633
634tree
3a978d72 635begin_for_stmt (void)
ad321293
MM
636{
637 tree r;
638
0dfdeca6
BC
639 r = build_stmt (FOR_STMT, NULL_TREE, NULL_TREE,
640 NULL_TREE, NULL_TREE);
325c3691
RH
641
642 if (flag_new_for_scope > 0)
643 TREE_CHAIN (r) = do_pushlevel (sk_for);
ad321293 644
894ca2c9
RH
645 if (processing_template_decl)
646 FOR_INIT_STMT (r) = push_stmt_list ();
647
ad321293
MM
648 return r;
649}
650
651/* Finish the for-init-statement of a for-statement, which may be
652 given by FOR_STMT. */
653
654void
3a978d72 655finish_for_init_stmt (tree for_stmt)
ad321293 656{
894ca2c9
RH
657 if (processing_template_decl)
658 FOR_INIT_STMT (for_stmt) = pop_stmt_list (FOR_INIT_STMT (for_stmt));
325c3691
RH
659 add_stmt (for_stmt);
660 FOR_BODY (for_stmt) = do_pushlevel (sk_block);
caf2523d 661 begin_cond (&FOR_COND (for_stmt));
ad321293
MM
662}
663
664/* Finish the COND of a for-statement, which may be given by
665 FOR_STMT. */
666
667void
3a978d72 668finish_for_cond (tree cond, tree for_stmt)
ad321293 669{
caf2523d
RH
670 finish_cond (&FOR_COND (for_stmt), maybe_convert_cond (cond));
671 simplify_loop_decl_cond (&FOR_COND (for_stmt), FOR_BODY (for_stmt));
ad321293
MM
672}
673
674/* Finish the increment-EXPRESSION in a for-statement, which may be
675 given by FOR_STMT. */
676
677void
3a978d72 678finish_for_expr (tree expr, tree for_stmt)
ad321293 679{
6f69173e
MM
680 /* If EXPR is an overloaded function, issue an error; there is no
681 context available to use to perform overload resolution. */
682 if (expr && type_unknown_p (expr))
683 {
684 cxx_incomplete_type_error (expr, TREE_TYPE (expr));
685 expr = error_mark_node;
686 }
35b1567d 687 FOR_EXPR (for_stmt) = expr;
ad321293
MM
688}
689
690/* Finish the body of a for-statement, which may be given by
691 FOR_STMT. The increment-EXPR for the loop must be
692 provided. */
693
694void
3a978d72 695finish_for_stmt (tree for_stmt)
ad321293 696{
325c3691
RH
697 FOR_BODY (for_stmt) = do_poplevel (FOR_BODY (for_stmt));
698
ad321293 699 /* Pop the scope for the body of the loop. */
325c3691
RH
700 if (flag_new_for_scope > 0)
701 {
702 tree scope = TREE_CHAIN (for_stmt);
703 TREE_CHAIN (for_stmt) = NULL;
704 add_stmt (do_poplevel (scope));
705 }
706
ad321293
MM
707 finish_stmt ();
708}
709
710/* Finish a break-statement. */
711
3e4d04a1 712tree
3a978d72 713finish_break_stmt (void)
ad321293 714{
3e4d04a1 715 return add_stmt (build_break_stmt ());
35b1567d
BC
716}
717
ad321293
MM
718/* Finish a continue-statement. */
719
3e4d04a1 720tree
3a978d72 721finish_continue_stmt (void)
ad321293 722{
3e4d04a1 723 return add_stmt (build_continue_stmt ());
ad321293
MM
724}
725
35b1567d
BC
726/* Begin a switch-statement. Returns a new SWITCH_STMT if
727 appropriate. */
728
729tree
3a978d72 730begin_switch_stmt (void)
35b1567d 731{
325c3691
RH
732 tree r, scope;
733
6f9fdf4d 734 r = build_stmt (SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
325c3691
RH
735
736 scope = do_pushlevel (sk_block);
737 TREE_CHAIN (r) = scope;
caf2523d 738 begin_cond (&SWITCH_COND (r));
325c3691 739
527f0080 740 return r;
ad321293
MM
741}
742
527f0080 743/* Finish the cond of a switch-statement. */
ad321293 744
527f0080 745void
3a978d72 746finish_switch_cond (tree cond, tree switch_stmt)
ad321293 747{
6f9fdf4d 748 tree orig_type = NULL;
35b1567d 749 if (!processing_template_decl)
373eb3b3 750 {
56cb9733
MM
751 tree index;
752
35b1567d 753 /* Convert the condition to an integer or enumeration type. */
b746c5dc 754 cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true);
35b1567d 755 if (cond == NULL_TREE)
373eb3b3 756 {
35b1567d
BC
757 error ("switch quantity not an integer");
758 cond = error_mark_node;
759 }
6f9fdf4d 760 orig_type = TREE_TYPE (cond);
35b1567d
BC
761 if (cond != error_mark_node)
762 {
0a72704b
MM
763 /* [stmt.switch]
764
765 Integral promotions are performed. */
766 cond = perform_integral_promotions (cond);
2bb5d995 767 cond = fold (build1 (CLEANUP_POINT_EXPR, TREE_TYPE (cond), cond));
373eb3b3 768 }
56cb9733 769
25c8b645
JJ
770 if (cond != error_mark_node)
771 {
772 index = get_unwidened (cond, NULL_TREE);
773 /* We can't strip a conversion from a signed type to an unsigned,
774 because if we did, int_fits_type_p would do the wrong thing
775 when checking case values for being in range,
776 and it's too hard to do the right thing. */
8df83eae
RK
777 if (TYPE_UNSIGNED (TREE_TYPE (cond))
778 == TYPE_UNSIGNED (TREE_TYPE (index)))
25c8b645
JJ
779 cond = index;
780 }
ad321293 781 }
caf2523d 782 finish_cond (&SWITCH_COND (switch_stmt), cond);
6f9fdf4d 783 SWITCH_TYPE (switch_stmt) = orig_type;
caf2523d 784 add_stmt (switch_stmt);
56cb9733 785 push_switch (switch_stmt);
325c3691 786 SWITCH_BODY (switch_stmt) = push_stmt_list ();
ad321293
MM
787}
788
789/* Finish the body of a switch-statement, which may be given by
790 SWITCH_STMT. The COND to switch on is indicated. */
791
792void
3a978d72 793finish_switch_stmt (tree switch_stmt)
ad321293 794{
325c3691
RH
795 tree scope;
796
797 SWITCH_BODY (switch_stmt) = pop_stmt_list (SWITCH_BODY (switch_stmt));
ad321293 798 pop_switch ();
ad321293 799 finish_stmt ();
325c3691
RH
800
801 scope = TREE_CHAIN (switch_stmt);
802 TREE_CHAIN (switch_stmt) = NULL;
803 add_stmt (do_poplevel (scope));
ad321293
MM
804}
805
ad321293
MM
806/* Begin a try-block. Returns a newly-created TRY_BLOCK if
807 appropriate. */
808
809tree
3a978d72 810begin_try_block (void)
ad321293 811{
0dfdeca6 812 tree r = build_stmt (TRY_BLOCK, NULL_TREE, NULL_TREE);
ae499cce 813 add_stmt (r);
325c3691 814 TRY_STMTS (r) = push_stmt_list ();
35b1567d 815 return r;
ad321293
MM
816}
817
0dde4175
JM
818/* Likewise, for a function-try-block. */
819
820tree
3a978d72 821begin_function_try_block (void)
0dde4175 822{
325c3691 823 tree r = begin_try_block ();
35b1567d 824 FN_TRY_BLOCK_P (r) = 1;
35b1567d 825 return r;
0dde4175
JM
826}
827
ad321293
MM
828/* Finish a try-block, which may be given by TRY_BLOCK. */
829
830void
3a978d72 831finish_try_block (tree try_block)
ad321293 832{
325c3691
RH
833 TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
834 TRY_HANDLERS (try_block) = push_stmt_list ();
ad321293
MM
835}
836
efa8eda3
MM
837/* Finish the body of a cleanup try-block, which may be given by
838 TRY_BLOCK. */
839
62409b39 840void
3a978d72 841finish_cleanup_try_block (tree try_block)
62409b39 842{
325c3691 843 TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
62409b39
MM
844}
845
f1dedc31
MM
846/* Finish an implicitly generated try-block, with a cleanup is given
847 by CLEANUP. */
848
849void
3a978d72 850finish_cleanup (tree cleanup, tree try_block)
f1dedc31 851{
35b1567d
BC
852 TRY_HANDLERS (try_block) = cleanup;
853 CLEANUP_P (try_block) = 1;
f1dedc31
MM
854}
855
0dde4175
JM
856/* Likewise, for a function-try-block. */
857
858void
3a978d72 859finish_function_try_block (tree try_block)
0dde4175 860{
325c3691
RH
861 finish_try_block (try_block);
862 /* FIXME : something queer about CTOR_INITIALIZER somehow following
863 the try block, but moving it inside. */
b35d4555 864 in_function_try_handler = 1;
0dde4175
JM
865}
866
ad321293
MM
867/* Finish a handler-sequence for a try-block, which may be given by
868 TRY_BLOCK. */
869
870void
3a978d72 871finish_handler_sequence (tree try_block)
ad321293 872{
325c3691 873 TRY_HANDLERS (try_block) = pop_stmt_list (TRY_HANDLERS (try_block));
35b1567d 874 check_handlers (TRY_HANDLERS (try_block));
ad321293
MM
875}
876
0dde4175
JM
877/* Likewise, for a function-try-block. */
878
879void
3a978d72 880finish_function_handler_sequence (tree try_block)
0dde4175 881{
b35d4555 882 in_function_try_handler = 0;
325c3691 883 finish_handler_sequence (try_block);
35b1567d
BC
884}
885
ad321293
MM
886/* Begin a handler. Returns a HANDLER if appropriate. */
887
888tree
3a978d72 889begin_handler (void)
ad321293
MM
890{
891 tree r;
325c3691 892
0dfdeca6 893 r = build_stmt (HANDLER, NULL_TREE, NULL_TREE);
ae499cce 894 add_stmt (r);
325c3691 895
1a6025b4
JM
896 /* Create a binding level for the eh_info and the exception object
897 cleanup. */
325c3691
RH
898 HANDLER_BODY (r) = do_pushlevel (sk_catch);
899
ad321293
MM
900 return r;
901}
902
903/* Finish the handler-parameters for a handler, which may be given by
b35d4555
MM
904 HANDLER. DECL is the declaration for the catch parameter, or NULL
905 if this is a `catch (...)' clause. */
ad321293 906
1a6025b4 907void
3a978d72 908finish_handler_parms (tree decl, tree handler)
b35d4555 909{
1a6025b4 910 tree type = NULL_TREE;
b35d4555
MM
911 if (processing_template_decl)
912 {
913 if (decl)
914 {
915 decl = pushdecl (decl);
916 decl = push_template_decl (decl);
325c3691 917 HANDLER_PARMS (handler) = decl;
1a6025b4 918 type = TREE_TYPE (decl);
b35d4555
MM
919 }
920 }
35b1567d 921 else
1a6025b4 922 type = expand_start_catch_block (decl);
35b1567d 923
1a6025b4 924 HANDLER_TYPE (handler) = type;
b80cfdcd 925 if (!processing_template_decl && type)
6cad4e17 926 mark_used (eh_type_info (type));
35b1567d
BC
927}
928
929/* Finish a handler, which may be given by HANDLER. The BLOCKs are
930 the return value from the matching call to finish_handler_parms. */
931
932void
3a978d72 933finish_handler (tree handler)
35b1567d
BC
934{
935 if (!processing_template_decl)
1a6025b4 936 expand_end_catch_block ();
325c3691 937 HANDLER_BODY (handler) = do_poplevel (HANDLER_BODY (handler));
35b1567d
BC
938}
939
5882f0f3
RH
940/* Begin a compound statement. FLAGS contains some bits that control the
941 behaviour and context. If BCS_NO_SCOPE is set, the compound statement
942 does not define a scope. If BCS_FN_BODY is set, this is the outermost
943 block of a function. If BCS_TRY_BLOCK is set, this is the block
944 created on behalf of a TRY statement. Returns a token to be passed to
945 finish_compound_stmt. */
ad321293
MM
946
947tree
325c3691 948begin_compound_stmt (unsigned int flags)
ad321293 949{
325c3691 950 tree r;
558475f0 951
325c3691
RH
952 if (flags & BCS_NO_SCOPE)
953 {
954 r = push_stmt_list ();
955 STATEMENT_LIST_NO_SCOPE (r) = 1;
956
957 /* Normally, we try hard to keep the BLOCK for a statement-expression.
958 But, if it's a statement-expression with a scopeless block, there's
959 nothing to keep, and we don't want to accidentally keep a block
960 *inside* the scopeless block. */
961 keep_next_level (false);
962 }
f1dedc31 963 else
325c3691
RH
964 r = do_pushlevel (flags & BCS_TRY_BLOCK ? sk_try : sk_block);
965
5882f0f3
RH
966 /* When processing a template, we need to remember where the braces were,
967 so that we can set up identical scopes when instantiating the template
968 later. BIND_EXPR is a handy candidate for this.
969 Note that do_poplevel won't create a BIND_EXPR itself here (and thus
970 result in nested BIND_EXPRs), since we don't build BLOCK nodes when
971 processing templates. */
972 if (processing_template_decl)
325c3691 973 {
5882f0f3
RH
974 r = build (BIND_EXPR, NULL, NULL, r, NULL);
975 BIND_EXPR_TRY_BLOCK (r) = (flags & BCS_TRY_BLOCK) != 0;
976 BIND_EXPR_BODY_BLOCK (r) = (flags & BCS_FN_BODY) != 0;
325c3691
RH
977 TREE_SIDE_EFFECTS (r) = 1;
978 }
ad321293
MM
979
980 return r;
981}
982
5882f0f3 983/* Finish a compound-statement, which is given by STMT. */
ad321293 984
325c3691
RH
985void
986finish_compound_stmt (tree stmt)
ad321293 987{
5882f0f3
RH
988 if (TREE_CODE (stmt) == BIND_EXPR)
989 BIND_EXPR_BODY (stmt) = do_poplevel (BIND_EXPR_BODY (stmt));
325c3691
RH
990 else if (STATEMENT_LIST_NO_SCOPE (stmt))
991 stmt = pop_stmt_list (stmt);
7a3397c7 992 else
325c3691 993 stmt = do_poplevel (stmt);
ad321293 994
325c3691
RH
995 /* ??? See c_end_compound_stmt wrt statement expressions. */
996 add_stmt (stmt);
ad321293 997 finish_stmt ();
ad321293
MM
998}
999
6de9cd9a
DN
1000/* Finish an asm-statement, whose components are a STRING, some
1001 OUTPUT_OPERANDS, some INPUT_OPERANDS, and some CLOBBERS. Also note
1002 whether the asm-statement should be considered volatile. */
7dc5bd62 1003
3e4d04a1 1004tree
6de9cd9a
DN
1005finish_asm_stmt (int volatile_p, tree string, tree output_operands,
1006 tree input_operands, tree clobbers)
35b1567d
BC
1007{
1008 tree r;
abfc8a36
MM
1009 tree t;
1010
abfc8a36 1011 if (!processing_template_decl)
40b18c0a
MM
1012 {
1013 int i;
1014 int ninputs;
1015 int noutputs;
1016
1017 for (t = input_operands; t; t = TREE_CHAIN (t))
1018 {
1019 tree converted_operand
1020 = decay_conversion (TREE_VALUE (t));
1021
1022 /* If the type of the operand hasn't been determined (e.g.,
1023 because it involves an overloaded function), then issue
1024 an error message. There's no context available to
1025 resolve the overloading. */
1026 if (TREE_TYPE (converted_operand) == unknown_type_node)
1027 {
33bd39a2 1028 error ("type of asm operand `%E' could not be determined",
40b18c0a
MM
1029 TREE_VALUE (t));
1030 converted_operand = error_mark_node;
1031 }
1032 TREE_VALUE (t) = converted_operand;
1033 }
1034
1035 ninputs = list_length (input_operands);
1036 noutputs = list_length (output_operands);
1037
1038 for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i)
1039 {
1040 bool allows_mem;
1041 bool allows_reg;
1042 bool is_inout;
1043 const char *constraint;
1044 tree operand;
1045
84b72302 1046 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
28c56d25 1047 operand = TREE_VALUE (t);
40b18c0a
MM
1048
1049 if (!parse_output_constraint (&constraint,
1050 i, ninputs, noutputs,
1051 &allows_mem,
1052 &allows_reg,
1053 &is_inout))
1054 {
a723baf1
MM
1055 /* By marking this operand as erroneous, we will not try
1056 to process this operand again in expand_asm_operands. */
1057 TREE_VALUE (t) = error_mark_node;
40b18c0a
MM
1058 continue;
1059 }
1060
1061 /* If the operand is a DECL that is going to end up in
1062 memory, assume it is addressable. This is a bit more
1063 conservative than it would ideally be; the exact test is
1064 buried deep in expand_asm_operands and depends on the
1065 DECL_RTL for the OPERAND -- which we don't have at this
1066 point. */
1067 if (!allows_reg && DECL_P (operand))
dffd7eb6 1068 cxx_mark_addressable (operand);
40b18c0a
MM
1069 }
1070 }
abfc8a36 1071
e130a54b 1072 r = build_stmt (ASM_EXPR, string,
0dfdeca6
BC
1073 output_operands, input_operands,
1074 clobbers);
6de9cd9a 1075 ASM_VOLATILE_P (r) = volatile_p;
3e4d04a1 1076 return add_stmt (r);
ad321293 1077}
b4c4a9ec 1078
f01b0acb
MM
1079/* Finish a label with the indicated NAME. */
1080
a723baf1 1081tree
3a978d72 1082finish_label_stmt (tree name)
f01b0acb 1083{
5b030314 1084 tree decl = define_label (input_location, name);
9e14e18f 1085 return add_stmt (build_stmt (LABEL_EXPR, decl));
f01b0acb
MM
1086}
1087
acef433b
MM
1088/* Finish a series of declarations for local labels. G++ allows users
1089 to declare "local" labels, i.e., labels with scope. This extension
1090 is useful when writing code involving statement-expressions. */
1091
1092void
3a978d72 1093finish_label_decl (tree name)
acef433b
MM
1094{
1095 tree decl = declare_local_label (name);
35b1567d 1096 add_decl_stmt (decl);
acef433b
MM
1097}
1098
659e5a7a 1099/* When DECL goes out of scope, make sure that CLEANUP is executed. */
f1dedc31
MM
1100
1101void
3a978d72 1102finish_decl_cleanup (tree decl, tree cleanup)
f1dedc31 1103{
325c3691 1104 push_cleanup (decl, cleanup, false);
35b1567d
BC
1105}
1106
659e5a7a 1107/* If the current scope exits with an exception, run CLEANUP. */
24bef158 1108
659e5a7a 1109void
3a978d72 1110finish_eh_cleanup (tree cleanup)
24bef158 1111{
325c3691 1112 push_cleanup (NULL, cleanup, true);
35b1567d
BC
1113}
1114
2282d28d
MM
1115/* The MEM_INITS is a list of mem-initializers, in reverse of the
1116 order they were written by the user. Each node is as for
1117 emit_mem_initializers. */
bf3428d0
MM
1118
1119void
2282d28d 1120finish_mem_initializers (tree mem_inits)
bf3428d0 1121{
2282d28d
MM
1122 /* Reorder the MEM_INITS so that they are in the order they appeared
1123 in the source program. */
1124 mem_inits = nreverse (mem_inits);
bf3428d0 1125
a0de9d20 1126 if (processing_template_decl)
2282d28d 1127 add_stmt (build_min_nt (CTOR_INITIALIZER, mem_inits));
cdd2559c 1128 else
2282d28d 1129 emit_mem_initializers (mem_inits);
558475f0
MM
1130}
1131
b4c4a9ec
MM
1132/* Finish a parenthesized expression EXPR. */
1133
1134tree
3a978d72 1135finish_parenthesized_expr (tree expr)
b4c4a9ec
MM
1136{
1137 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr))))
78ef5b89 1138 /* This inhibits warnings in c_common_truthvalue_conversion. */
b4c4a9ec
MM
1139 C_SET_EXP_ORIGINAL_CODE (expr, ERROR_MARK);
1140
19420d00
NS
1141 if (TREE_CODE (expr) == OFFSET_REF)
1142 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
1143 enclosed in parentheses. */
1144 PTRMEM_OK_P (expr) = 0;
b4c4a9ec
MM
1145 return expr;
1146}
1147
a723baf1
MM
1148/* Finish a reference to a non-static data member (DECL) that is not
1149 preceded by `.' or `->'. */
1150
1151tree
a3f10e50 1152finish_non_static_data_member (tree decl, tree object, tree qualifying_scope)
a723baf1
MM
1153{
1154 my_friendly_assert (TREE_CODE (decl) == FIELD_DECL, 20020909);
1155
a3f10e50 1156 if (!object)
a723baf1
MM
1157 {
1158 if (current_function_decl
1159 && DECL_STATIC_FUNCTION_P (current_function_decl))
1160 cp_error_at ("invalid use of member `%D' in static member function",
1161 decl);
1162 else
1163 cp_error_at ("invalid use of non-static data member `%D'", decl);
1164 error ("from this location");
1165
1166 return error_mark_node;
1167 }
1168 TREE_USED (current_class_ptr) = 1;
58e1d54c 1169 if (processing_template_decl && !qualifying_scope)
a723baf1 1170 {
a3f10e50 1171 tree type = TREE_TYPE (decl);
a723baf1 1172
a3f10e50
NS
1173 if (TREE_CODE (type) == REFERENCE_TYPE)
1174 type = TREE_TYPE (type);
1175 else
1176 {
f4f206f4 1177 /* Set the cv qualifiers. */
a3f10e50
NS
1178 int quals = cp_type_quals (TREE_TYPE (current_class_ref));
1179
1180 if (DECL_MUTABLE_P (decl))
1181 quals &= ~TYPE_QUAL_CONST;
9e95d15f 1182
a3f10e50
NS
1183 quals |= cp_type_quals (TREE_TYPE (decl));
1184 type = cp_build_qualified_type (type, quals);
1185 }
9e95d15f 1186
a3f10e50
NS
1187 return build_min (COMPONENT_REF, type, object, decl);
1188 }
1189 else
1190 {
1191 tree access_type = TREE_TYPE (object);
1192 tree lookup_context = context_for_name_lookup (decl);
1193
1194 while (!DERIVED_FROM_P (lookup_context, access_type))
a723baf1
MM
1195 {
1196 access_type = TYPE_CONTEXT (access_type);
9f01ded6 1197 while (access_type && DECL_P (access_type))
a723baf1 1198 access_type = DECL_CONTEXT (access_type);
a723baf1 1199
a3f10e50
NS
1200 if (!access_type)
1201 {
1202 cp_error_at ("object missing in reference to `%D'", decl);
1203 error ("from this location");
1204 return error_mark_node;
1205 }
9f01ded6
KL
1206 }
1207
5c425df5 1208 /* If PROCESSING_TEMPLATE_DECL is nonzero here, then
58e1d54c
KL
1209 QUALIFYING_SCOPE is also non-null. Wrap this in a SCOPE_REF
1210 for now. */
1211 if (processing_template_decl)
1212 return build_min (SCOPE_REF, TREE_TYPE (decl),
1213 qualifying_scope, DECL_NAME (decl));
1214
6df5158a 1215 perform_or_defer_access_check (TYPE_BINFO (access_type), decl);
a723baf1
MM
1216
1217 /* If the data member was named `C::M', convert `*this' to `C'
1218 first. */
1219 if (qualifying_scope)
1220 {
1221 tree binfo = NULL_TREE;
1222 object = build_scoped_ref (object, qualifying_scope,
1223 &binfo);
1224 }
1225
1226 return build_class_member_access_expr (object, decl,
1227 /*access_path=*/NULL_TREE,
1228 /*preserve_reference=*/false);
1229 }
1230}
1231
ee76b931
MM
1232/* DECL was the declaration to which a qualified-id resolved. Issue
1233 an error message if it is not accessible. If OBJECT_TYPE is
1234 non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the
1235 type of `*x', or `x', respectively. If the DECL was named as
1236 `A::B' then NESTED_NAME_SPECIFIER is `A'. */
1237
1238void
1239check_accessibility_of_qualified_id (tree decl,
1240 tree object_type,
1241 tree nested_name_specifier)
1242{
1243 tree scope;
1244 tree qualifying_type = NULL_TREE;
1245
1246 /* Determine the SCOPE of DECL. */
1247 scope = context_for_name_lookup (decl);
1248 /* If the SCOPE is not a type, then DECL is not a member. */
1249 if (!TYPE_P (scope))
1250 return;
1251 /* Compute the scope through which DECL is being accessed. */
1252 if (object_type
1253 /* OBJECT_TYPE might not be a class type; consider:
1254
1255 class A { typedef int I; };
1256 I *p;
1257 p->A::I::~I();
1258
1259 In this case, we will have "A::I" as the DECL, but "I" as the
1260 OBJECT_TYPE. */
1261 && CLASS_TYPE_P (object_type)
1262 && DERIVED_FROM_P (scope, object_type))
1263 /* If we are processing a `->' or `.' expression, use the type of the
1264 left-hand side. */
1265 qualifying_type = object_type;
1266 else if (nested_name_specifier)
1267 {
1268 /* If the reference is to a non-static member of the
1269 current class, treat it as if it were referenced through
1270 `this'. */
1271 if (DECL_NONSTATIC_MEMBER_P (decl)
1272 && current_class_ptr
1273 && DERIVED_FROM_P (scope, current_class_type))
1274 qualifying_type = current_class_type;
1275 /* Otherwise, use the type indicated by the
1276 nested-name-specifier. */
1277 else
1278 qualifying_type = nested_name_specifier;
1279 }
1280 else
1281 /* Otherwise, the name must be from the current class or one of
1282 its bases. */
1283 qualifying_type = currently_open_derived_class (scope);
1284
1285 if (qualifying_type)
1286 perform_or_defer_access_check (TYPE_BINFO (qualifying_type), decl);
1287}
1288
1289/* EXPR is the result of a qualified-id. The QUALIFYING_CLASS was the
1290 class named to the left of the "::" operator. DONE is true if this
1291 expression is a complete postfix-expression; it is false if this
1292 expression is followed by '->', '[', '(', etc. ADDRESS_P is true
1293 iff this expression is the operand of '&'. */
1294
1295tree
1296finish_qualified_id_expr (tree qualifying_class, tree expr, bool done,
1297 bool address_p)
1298{
5e08432e
MM
1299 if (error_operand_p (expr))
1300 return error_mark_node;
1301
ee76b931
MM
1302 /* If EXPR occurs as the operand of '&', use special handling that
1303 permits a pointer-to-member. */
1304 if (address_p && done)
1305 {
1306 if (TREE_CODE (expr) == SCOPE_REF)
1307 expr = TREE_OPERAND (expr, 1);
a5ac359a
MM
1308 expr = build_offset_ref (qualifying_class, expr,
1309 /*address_p=*/true);
ee76b931
MM
1310 return expr;
1311 }
1312
1313 if (TREE_CODE (expr) == FIELD_DECL)
a3f10e50
NS
1314 expr = finish_non_static_data_member (expr, current_class_ref,
1315 qualifying_class);
ee76b931
MM
1316 else if (BASELINK_P (expr) && !processing_template_decl)
1317 {
1318 tree fn;
1319 tree fns;
1320
1321 /* See if any of the functions are non-static members. */
1322 fns = BASELINK_FUNCTIONS (expr);
1323 if (TREE_CODE (fns) == TEMPLATE_ID_EXPR)
1324 fns = TREE_OPERAND (fns, 0);
1325 for (fn = fns; fn; fn = OVL_NEXT (fn))
1326 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
1327 break;
1328 /* If so, the expression may be relative to the current
1329 class. */
1330 if (fn && current_class_type
1331 && DERIVED_FROM_P (qualifying_class, current_class_type))
1332 expr = (build_class_member_access_expr
1333 (maybe_dummy_object (qualifying_class, NULL),
1334 expr,
1335 BASELINK_ACCESS_BINFO (expr),
1336 /*preserve_reference=*/false));
1337 else if (done)
a5ac359a
MM
1338 /* The expression is a qualified name whose address is not
1339 being taken. */
1340 expr = build_offset_ref (qualifying_class, expr, /*address_p=*/false);
ee76b931
MM
1341 }
1342
1343 return expr;
1344}
1345
b69b1501
MM
1346/* Begin a statement-expression. The value returned must be passed to
1347 finish_stmt_expr. */
b4c4a9ec
MM
1348
1349tree
3a978d72 1350begin_stmt_expr (void)
b4c4a9ec 1351{
325c3691 1352 return push_stmt_list ();
35b1567d
BC
1353}
1354
a5bcc582
NS
1355/* Process the final expression of a statement expression. EXPR can be
1356 NULL, if the final expression is empty. Build up a TARGET_EXPR so
1357 that the result value can be safely returned to the enclosing
1358 expression. */
1359
1360tree
325c3691 1361finish_stmt_expr_expr (tree expr, tree stmt_expr)
a5bcc582
NS
1362{
1363 tree result = NULL_TREE;
a5bcc582
NS
1364
1365 if (expr)
1366 {
a5bcc582
NS
1367 if (!processing_template_decl && !VOID_TYPE_P (TREE_TYPE (expr)))
1368 {
2692eb7d
JM
1369 tree type = TREE_TYPE (expr);
1370
a5bcc582
NS
1371 if (TREE_CODE (type) == ARRAY_TYPE
1372 || TREE_CODE (type) == FUNCTION_TYPE)
1373 expr = decay_conversion (expr);
1374
1375 expr = convert_from_reference (expr);
1376 expr = require_complete_type (expr);
1377
2692eb7d
JM
1378 type = TREE_TYPE (expr);
1379
a5bcc582
NS
1380 /* Build a TARGET_EXPR for this aggregate. finish_stmt_expr
1381 will then pull it apart so the lifetime of the target is
cd0be382 1382 within the scope of the expression containing this statement
a5bcc582
NS
1383 expression. */
1384 if (TREE_CODE (expr) == TARGET_EXPR)
1385 ;
1386 else if (!IS_AGGR_TYPE (type) || TYPE_HAS_TRIVIAL_INIT_REF (type))
1387 expr = build_target_expr_with_type (expr, type);
1388 else
1389 {
1390 /* Copy construct. */
1391 expr = build_special_member_call
1392 (NULL_TREE, complete_ctor_identifier,
1393 build_tree_list (NULL_TREE, expr),
1394 TYPE_BINFO (type), LOOKUP_NORMAL);
1395 expr = build_cplus_new (type, expr);
1396 my_friendly_assert (TREE_CODE (expr) == TARGET_EXPR, 20030729);
1397 }
1398 }
1399
1400 if (expr != error_mark_node)
1401 {
1402 result = build_stmt (EXPR_STMT, expr);
325c3691 1403 EXPR_STMT_STMT_EXPR_RESULT (result) = 1;
a5bcc582
NS
1404 add_stmt (result);
1405 }
1406 }
1407
1408 finish_stmt ();
1409
325c3691
RH
1410 /* Remember the last expression so that finish_stmt_expr
1411 can pull it apart. */
1412 TREE_TYPE (stmt_expr) = result;
a5bcc582
NS
1413
1414 return result;
1415}
1416
303b7406
NS
1417/* Finish a statement-expression. EXPR should be the value returned
1418 by the previous begin_stmt_expr. Returns an expression
1419 representing the statement-expression. */
b4c4a9ec
MM
1420
1421tree
325c3691 1422finish_stmt_expr (tree stmt_expr, bool has_no_scope)
b4c4a9ec 1423{
325c3691
RH
1424 tree result, result_stmt, type;
1425 tree *result_stmt_p = NULL;
1426
1427 result_stmt = TREE_TYPE (stmt_expr);
1428 TREE_TYPE (stmt_expr) = void_type_node;
1429 result = pop_stmt_list (stmt_expr);
1430
1431 if (!result_stmt || VOID_TYPE_P (result_stmt))
a5bcc582
NS
1432 type = void_type_node;
1433 else
1434 {
325c3691
RH
1435 /* We need to search the statement expression for the result_stmt,
1436 since we'll need to replace it entirely. */
1437 tree t;
1438 result_stmt_p = &result;
1439 while (1)
a5bcc582 1440 {
325c3691
RH
1441 t = *result_stmt_p;
1442 if (t == result_stmt)
1443 break;
1444
1445 switch (TREE_CODE (t))
1446 {
1447 case STATEMENT_LIST:
1448 {
1449 tree_stmt_iterator i = tsi_last (t);
1450 result_stmt_p = tsi_stmt_ptr (i);
1451 break;
1452 }
1453 case BIND_EXPR:
1454 result_stmt_p = &BIND_EXPR_BODY (t);
1455 break;
325c3691
RH
1456 case TRY_FINALLY_EXPR:
1457 case TRY_CATCH_EXPR:
1458 case CLEANUP_STMT:
1459 result_stmt_p = &TREE_OPERAND (t, 0);
1460 break;
1461 default:
1462 abort ();
1463 }
a5bcc582 1464 }
325c3691 1465 type = TREE_TYPE (EXPR_STMT_EXPR (result_stmt));
a5bcc582 1466 }
6f80451c 1467
a5bcc582 1468 if (processing_template_decl)
325c3691
RH
1469 {
1470 result = build_min (STMT_EXPR, type, result);
1471 TREE_SIDE_EFFECTS (result) = 1;
1472 STMT_EXPR_NO_SCOPE (result) = has_no_scope;
1473 }
1474 else if (!VOID_TYPE_P (type))
a5bcc582
NS
1475 {
1476 /* Pull out the TARGET_EXPR that is the final expression. Put
1477 the target's init_expr as the final expression and then put
1478 the statement expression itself as the target's init
1479 expr. Finally, return the target expression. */
2692eb7d
JM
1480 tree init, target_expr = EXPR_STMT_EXPR (result_stmt);
1481 my_friendly_assert (TREE_CODE (target_expr) == TARGET_EXPR, 20030729);
1482
1483 /* The initializer will be void if the initialization is done by
1484 AGGR_INIT_EXPR; propagate that out to the statement-expression as
1485 a whole. */
1486 init = TREE_OPERAND (target_expr, 1);
1487 type = TREE_TYPE (init);
1488
1489 if (stmts_are_full_exprs_p ())
1490 init = fold (build1 (CLEANUP_POINT_EXPR, type, init));
1491 *result_stmt_p = init;
1492
1493 if (VOID_TYPE_P (type))
1494 /* No frobbing needed. */;
1495 else if (TREE_CODE (result) == BIND_EXPR)
325c3691 1496 {
2692eb7d
JM
1497 /* The BIND_EXPR created in finish_compound_stmt is void; if we're
1498 returning a value directly, give it the appropriate type. */
325c3691 1499 if (VOID_TYPE_P (TREE_TYPE (result)))
2692eb7d
JM
1500 TREE_TYPE (result) = type;
1501 else if (same_type_p (TREE_TYPE (result), type))
325c3691
RH
1502 ;
1503 else
1504 abort ();
1505 }
1506 else if (TREE_CODE (result) == STATEMENT_LIST)
2692eb7d
JM
1507 /* We need to wrap a STATEMENT_LIST in a BIND_EXPR so it can have a
1508 type other than void. FIXME why can't we just return a value
1509 from STATEMENT_LIST? */
1510 result = build3 (BIND_EXPR, type, NULL, result, NULL);
325c3691 1511
2692eb7d
JM
1512 TREE_OPERAND (target_expr, 1) = result;
1513 result = target_expr;
a5bcc582 1514 }
325c3691 1515
b4c4a9ec
MM
1516 return result;
1517}
1518
b3445994 1519/* Perform Koenig lookup. FN is the postfix-expression representing
fa531100
MM
1520 the function (or functions) to call; ARGS are the arguments to the
1521 call. Returns the functions to be considered by overload
1522 resolution. */
b3445994
MM
1523
1524tree
1525perform_koenig_lookup (tree fn, tree args)
1526{
1527 tree identifier = NULL_TREE;
1528 tree functions = NULL_TREE;
1529
1530 /* Find the name of the overloaded function. */
1531 if (TREE_CODE (fn) == IDENTIFIER_NODE)
1532 identifier = fn;
1533 else if (is_overloaded_fn (fn))
1534 {
1535 functions = fn;
1536 identifier = DECL_NAME (get_first_fn (functions));
1537 }
1538 else if (DECL_P (fn))
1539 {
1540 functions = fn;
1541 identifier = DECL_NAME (fn);
1542 }
1543
1544 /* A call to a namespace-scope function using an unqualified name.
1545
1546 Do Koenig lookup -- unless any of the arguments are
1547 type-dependent. */
1548 if (!any_type_dependent_arguments_p (args))
1549 {
1550 fn = lookup_arg_dependent (identifier, functions, args);
1551 if (!fn)
1552 /* The unqualified name could not be resolved. */
1553 fn = unqualified_fn_lookup_error (identifier);
1554 }
1555 else
10b1d5e7 1556 fn = identifier;
b3445994
MM
1557
1558 return fn;
1559}
1560
4ba126e4
MM
1561/* Generate an expression for `FN (ARGS)'.
1562
1563 If DISALLOW_VIRTUAL is true, the call to FN will be not generated
1564 as a virtual call, even if FN is virtual. (This flag is set when
1565 encountering an expression where the function name is explicitly
1566 qualified. For example a call to `X::f' never generates a virtual
1567 call.)
1568
1569 Returns code for the call. */
b4c4a9ec
MM
1570
1571tree
6d80c4b9 1572finish_call_expr (tree fn, tree args, bool disallow_virtual, bool koenig_p)
b4c4a9ec 1573{
d17811fd
MM
1574 tree result;
1575 tree orig_fn;
1576 tree orig_args;
1577
4ba126e4
MM
1578 if (fn == error_mark_node || args == error_mark_node)
1579 return error_mark_node;
1580
4ba126e4
MM
1581 /* ARGS should be a list of arguments. */
1582 my_friendly_assert (!args || TREE_CODE (args) == TREE_LIST,
1583 20020712);
a759e627 1584
d17811fd
MM
1585 orig_fn = fn;
1586 orig_args = args;
1587
1588 if (processing_template_decl)
1589 {
1590 if (type_dependent_expression_p (fn)
1591 || any_type_dependent_arguments_p (args))
6d80c4b9 1592 {
6de9cd9a 1593 result = build_nt (CALL_EXPR, fn, args, NULL_TREE);
6d80c4b9
MM
1594 KOENIG_LOOKUP_P (result) = koenig_p;
1595 return result;
1596 }
d17811fd
MM
1597 if (!BASELINK_P (fn)
1598 && TREE_CODE (fn) != PSEUDO_DTOR_EXPR
1599 && TREE_TYPE (fn) != unknown_type_node)
1600 fn = build_non_dependent_expr (fn);
1601 args = build_non_dependent_args (orig_args);
1602 }
1603
a723baf1
MM
1604 /* A reference to a member function will appear as an overloaded
1605 function (rather than a BASELINK) if an unqualified name was used
1606 to refer to it. */
1607 if (!BASELINK_P (fn) && is_overloaded_fn (fn))
1608 {
12483c9f 1609 tree f = fn;
a723baf1 1610
12483c9f
NS
1611 if (TREE_CODE (f) == TEMPLATE_ID_EXPR)
1612 f = TREE_OPERAND (f, 0);
1613 f = get_first_fn (f);
a723baf1
MM
1614 if (DECL_FUNCTION_MEMBER_P (f))
1615 {
1616 tree type = currently_open_derived_class (DECL_CONTEXT (f));
c44e68a5
KL
1617 if (!type)
1618 type = DECL_CONTEXT (f);
a723baf1
MM
1619 fn = build_baselink (TYPE_BINFO (type),
1620 TYPE_BINFO (type),
1621 fn, /*optype=*/NULL_TREE);
1622 }
1623 }
1624
d17811fd 1625 result = NULL_TREE;
4ba126e4 1626 if (BASELINK_P (fn))
03d82991 1627 {
4ba126e4
MM
1628 tree object;
1629
1630 /* A call to a member function. From [over.call.func]:
1631
1632 If the keyword this is in scope and refers to the class of
1633 that member function, or a derived class thereof, then the
1634 function call is transformed into a qualified function call
1635 using (*this) as the postfix-expression to the left of the
1636 . operator.... [Otherwise] a contrived object of type T
1637 becomes the implied object argument.
1638
1639 This paragraph is unclear about this situation:
1640
1641 struct A { void f(); };
1642 struct B : public A {};
1643 struct C : public A { void g() { B::f(); }};
1644
1645 In particular, for `B::f', this paragraph does not make clear
1646 whether "the class of that member function" refers to `A' or
1647 to `B'. We believe it refers to `B'. */
1648 if (current_class_type
1649 && DERIVED_FROM_P (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)),
1650 current_class_type)
1651 && current_class_ref)
127b8136
MM
1652 object = maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)),
1653 NULL);
4ba126e4
MM
1654 else
1655 {
1656 tree representative_fn;
b4c4a9ec 1657
4ba126e4
MM
1658 representative_fn = BASELINK_FUNCTIONS (fn);
1659 if (TREE_CODE (representative_fn) == TEMPLATE_ID_EXPR)
1660 representative_fn = TREE_OPERAND (representative_fn, 0);
1661 representative_fn = get_first_fn (representative_fn);
1662 object = build_dummy_object (DECL_CONTEXT (representative_fn));
1663 }
b4c4a9ec 1664
d17811fd
MM
1665 if (processing_template_decl)
1666 {
1667 if (type_dependent_expression_p (object))
6de9cd9a 1668 return build_nt (CALL_EXPR, orig_fn, orig_args, NULL_TREE);
d17811fd
MM
1669 object = build_non_dependent_expr (object);
1670 }
1671
1672 result = build_new_method_call (object, fn, args, NULL_TREE,
1673 (disallow_virtual
1674 ? LOOKUP_NONVIRTUAL : 0));
4ba126e4
MM
1675 }
1676 else if (is_overloaded_fn (fn))
1677 /* A call to a namespace-scope function. */
d17811fd 1678 result = build_new_function_call (fn, args);
a723baf1
MM
1679 else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR)
1680 {
a723baf1
MM
1681 if (args)
1682 error ("arguments to destructor are not allowed");
1683 /* Mark the pseudo-destructor call as having side-effects so
1684 that we do not issue warnings about its use. */
1685 result = build1 (NOP_EXPR,
1686 void_type_node,
1687 TREE_OPERAND (fn, 0));
1688 TREE_SIDE_EFFECTS (result) = 1;
a723baf1 1689 }
4ba126e4 1690 else if (CLASS_TYPE_P (TREE_TYPE (fn)))
d17811fd
MM
1691 /* If the "function" is really an object of class type, it might
1692 have an overloaded `operator ()'. */
ec835fb2
MM
1693 result = build_new_op (CALL_EXPR, LOOKUP_NORMAL, fn, args, NULL_TREE,
1694 /*overloaded_p=*/NULL);
d17811fd
MM
1695 if (!result)
1696 /* A call where the function is unknown. */
1697 result = build_function_call (fn, args);
4ba126e4 1698
d17811fd 1699 if (processing_template_decl)
6d80c4b9 1700 {
6de9cd9a
DN
1701 result = build (CALL_EXPR, TREE_TYPE (result), orig_fn,
1702 orig_args, NULL_TREE);
6d80c4b9
MM
1703 KOENIG_LOOKUP_P (result) = koenig_p;
1704 }
d17811fd 1705 return result;
b4c4a9ec
MM
1706}
1707
1708/* Finish a call to a postfix increment or decrement or EXPR. (Which
1709 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1710 POSTDECREMENT_EXPR.) */
1711
1712tree
3a978d72 1713finish_increment_expr (tree expr, enum tree_code code)
b4c4a9ec 1714{
b4c4a9ec
MM
1715 return build_x_unary_op (code, expr);
1716}
1717
1718/* Finish a use of `this'. Returns an expression for `this'. */
1719
1720tree
3a978d72 1721finish_this_expr (void)
b4c4a9ec
MM
1722{
1723 tree result;
1724
1725 if (current_class_ptr)
1726 {
b4c4a9ec
MM
1727 result = current_class_ptr;
1728 }
1729 else if (current_function_decl
1730 && DECL_STATIC_FUNCTION_P (current_function_decl))
1731 {
8251199e 1732 error ("`this' is unavailable for static member functions");
b4c4a9ec
MM
1733 result = error_mark_node;
1734 }
1735 else
1736 {
1737 if (current_function_decl)
8251199e 1738 error ("invalid use of `this' in non-member function");
b4c4a9ec 1739 else
8251199e 1740 error ("invalid use of `this' at top level");
b4c4a9ec
MM
1741 result = error_mark_node;
1742 }
1743
1744 return result;
1745}
1746
a723baf1
MM
1747/* Finish a pseudo-destructor expression. If SCOPE is NULL, the
1748 expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
1749 the TYPE for the type given. If SCOPE is non-NULL, the expression
1750 was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
b4c4a9ec
MM
1751
1752tree
3a978d72 1753finish_pseudo_destructor_expr (tree object, tree scope, tree destructor)
b4c4a9ec 1754{
a723baf1
MM
1755 if (destructor == error_mark_node)
1756 return error_mark_node;
40242ccf 1757
a723baf1 1758 my_friendly_assert (TYPE_P (destructor), 20010905);
b4c4a9ec 1759
a723baf1
MM
1760 if (!processing_template_decl)
1761 {
1762 if (scope == error_mark_node)
1763 {
1764 error ("invalid qualifying scope in pseudo-destructor name");
1765 return error_mark_node;
1766 }
1767
26bcf8fc
MM
1768 /* [expr.pseudo] says both:
1769
1770 The type designated by the pseudo-destructor-name shall be
1771 the same as the object type.
1772
1773 and:
1774
1775 The cv-unqualified versions of the object type and of the
1776 type designated by the pseudo-destructor-name shall be the
1777 same type.
1778
1779 We implement the more generous second sentence, since that is
1780 what most other compilers do. */
1781 if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object),
1782 destructor))
a723baf1
MM
1783 {
1784 error ("`%E' is not of type `%T'", object, destructor);
1785 return error_mark_node;
1786 }
1787 }
b4c4a9ec 1788
a723baf1 1789 return build (PSEUDO_DTOR_EXPR, void_type_node, object, scope, destructor);
b4c4a9ec
MM
1790}
1791
ce4a0391
MM
1792/* Finish an expression of the form CODE EXPR. */
1793
1794tree
3a978d72 1795finish_unary_op_expr (enum tree_code code, tree expr)
ce4a0391
MM
1796{
1797 tree result = build_x_unary_op (code, expr);
7c355bca
ML
1798 /* Inside a template, build_x_unary_op does not fold the
1799 expression. So check whether the result is folded before
1800 setting TREE_NEGATED_INT. */
1801 if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST
88b4335f 1802 && TREE_CODE (result) == INTEGER_CST
8df83eae 1803 && !TYPE_UNSIGNED (TREE_TYPE (result))
88b4335f 1804 && INT_CST_LT (result, integer_zero_node))
ce4a0391
MM
1805 TREE_NEGATED_INT (result) = 1;
1806 overflow_warning (result);
1807 return result;
1808}
1809
a723baf1
MM
1810/* Finish a compound-literal expression. TYPE is the type to which
1811 the INITIALIZER_LIST is being cast. */
1812
1813tree
3a978d72 1814finish_compound_literal (tree type, tree initializer_list)
a723baf1
MM
1815{
1816 tree compound_literal;
1817
1818 /* Build a CONSTRUCTOR for the INITIALIZER_LIST. */
dcf92453 1819 compound_literal = build_constructor (NULL_TREE, initializer_list);
a723baf1
MM
1820 /* Mark it as a compound-literal. */
1821 TREE_HAS_CONSTRUCTOR (compound_literal) = 1;
1822 if (processing_template_decl)
1823 TREE_TYPE (compound_literal) = type;
1824 else
1825 {
1826 /* Check the initialization. */
1827 compound_literal = digest_init (type, compound_literal, NULL);
1828 /* If the TYPE was an array type with an unknown bound, then we can
1829 figure out the dimension now. For example, something like:
1830
1831 `(int []) { 2, 3 }'
1832
1833 implies that the array has two elements. */
1834 if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type))
1835 complete_array_type (type, compound_literal, 1);
1836 }
1837
1838 return compound_literal;
1839}
1840
5f261ba9
MM
1841/* Return the declaration for the function-name variable indicated by
1842 ID. */
1843
1844tree
1845finish_fname (tree id)
1846{
1847 tree decl;
1848
1849 decl = fname_decl (C_RID_CODE (id), id);
1850 if (processing_template_decl)
10b1d5e7 1851 decl = DECL_NAME (decl);
5f261ba9
MM
1852 return decl;
1853}
1854
15c7fb9c 1855/* Begin a function definition declared with DECL_SPECS, ATTRIBUTES,
838dfd8a 1856 and DECLARATOR. Returns nonzero if the function-declaration is
0e339752 1857 valid. */
b4c4a9ec
MM
1858
1859int
3a978d72 1860begin_function_definition (tree decl_specs, tree attributes, tree declarator)
b4c4a9ec 1861{
15c7fb9c 1862 if (!start_function (decl_specs, declarator, attributes, SF_DEFAULT))
b4c4a9ec 1863 return 0;
1f51a992 1864
39c01e4c
MM
1865 /* The things we're about to see are not directly qualified by any
1866 template headers we've seen thus far. */
1867 reset_specialization ();
1868
b4c4a9ec
MM
1869 return 1;
1870}
1871
8014a339 1872/* Finish a translation unit. */
ce4a0391
MM
1873
1874void
3a978d72 1875finish_translation_unit (void)
ce4a0391
MM
1876{
1877 /* In case there were missing closebraces,
1878 get us back to the global binding level. */
273a708f 1879 pop_everything ();
ce4a0391
MM
1880 while (current_namespace != global_namespace)
1881 pop_namespace ();
0ba8a114 1882
c6002625 1883 /* Do file scope __FUNCTION__ et al. */
0ba8a114 1884 finish_fname_decls ();
ce4a0391
MM
1885}
1886
b4c4a9ec
MM
1887/* Finish a template type parameter, specified as AGGR IDENTIFIER.
1888 Returns the parameter. */
1889
1890tree
3a978d72 1891finish_template_type_parm (tree aggr, tree identifier)
b4c4a9ec 1892{
6eabb241 1893 if (aggr != class_type_node)
b4c4a9ec 1894 {
8251199e 1895 pedwarn ("template type parameters must use the keyword `class' or `typename'");
b4c4a9ec
MM
1896 aggr = class_type_node;
1897 }
1898
1899 return build_tree_list (aggr, identifier);
1900}
1901
1902/* Finish a template template parameter, specified as AGGR IDENTIFIER.
1903 Returns the parameter. */
1904
1905tree
3a978d72 1906finish_template_template_parm (tree aggr, tree identifier)
b4c4a9ec
MM
1907{
1908 tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE);
1909 tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
1910 DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
1911 DECL_TEMPLATE_RESULT (tmpl) = decl;
c727aa5e 1912 DECL_ARTIFICIAL (decl) = 1;
b4c4a9ec
MM
1913 end_template_decl ();
1914
b37bf5bd
NS
1915 my_friendly_assert (DECL_TEMPLATE_PARMS (tmpl), 20010110);
1916
b4c4a9ec
MM
1917 return finish_template_type_parm (aggr, tmpl);
1918}
ce4a0391 1919
8ba658ee
MM
1920/* ARGUMENT is the default-argument value for a template template
1921 parameter. If ARGUMENT is invalid, issue error messages and return
1922 the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
1923
1924tree
1925check_template_template_default_arg (tree argument)
1926{
1927 if (TREE_CODE (argument) != TEMPLATE_DECL
1928 && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM
8ba658ee
MM
1929 && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE)
1930 {
a3a503a5
GB
1931 if (TREE_CODE (argument) == TYPE_DECL)
1932 {
1933 tree t = TREE_TYPE (argument);
1934
1935 /* Try to emit a slightly smarter error message if we detect
1936 that the user is using a template instantiation. */
1937 if (CLASSTYPE_TEMPLATE_INFO (t)
1938 && CLASSTYPE_TEMPLATE_INSTANTIATION (t))
1939 error ("invalid use of type `%T' as a default value for a "
1940 "template template-parameter", t);
1941 else
1942 error ("invalid use of `%D' as a default value for a template "
1943 "template-parameter", argument);
1944 }
1945 else
1946 error ("invalid default argument for a template template parameter");
8ba658ee
MM
1947 return error_mark_node;
1948 }
1949
1950 return argument;
1951}
1952
ce4a0391 1953/* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
838dfd8a 1954 nonzero, the parameter list was terminated by a `...'. */
ce4a0391
MM
1955
1956tree
3a978d72 1957finish_parmlist (tree parms, int ellipsis)
ce4a0391 1958{
5cce22b6
NS
1959 if (parms)
1960 {
1961 /* We mark the PARMS as a parmlist so that declarator processing can
1962 disambiguate certain constructs. */
1963 TREE_PARMLIST (parms) = 1;
1964 /* We do not append void_list_node here, but leave it to grokparms
1965 to do that. */
1966 PARMLIST_ELLIPSIS_P (parms) = ellipsis;
1967 }
ce4a0391
MM
1968 return parms;
1969}
1970
1971/* Begin a class definition, as indicated by T. */
1972
1973tree
3a978d72 1974begin_class_definition (tree t)
ce4a0391 1975{
7437519c
ZW
1976 if (t == error_mark_node)
1977 return error_mark_node;
1978
522d6614
NS
1979 if (processing_template_parmlist)
1980 {
33bd39a2 1981 error ("definition of `%#T' inside template parameter list", t);
522d6614
NS
1982 return error_mark_node;
1983 }
47ee8904
MM
1984 /* A non-implicit typename comes from code like:
1985
1986 template <typename T> struct A {
1987 template <typename U> struct A<T>::B ...
1988
1989 This is erroneous. */
1990 else if (TREE_CODE (t) == TYPENAME_TYPE)
1991 {
33bd39a2 1992 error ("invalid definition of qualified type `%T'", t);
47ee8904
MM
1993 t = error_mark_node;
1994 }
1995
1996 if (t == error_mark_node || ! IS_AGGR_TYPE (t))
ce4a0391 1997 {
33848bb0 1998 t = make_aggr_type (RECORD_TYPE);
ce4a0391
MM
1999 pushtag (make_anon_name (), t, 0);
2000 }
830fcda8 2001
4c571114
MM
2002 /* If this type was already complete, and we see another definition,
2003 that's an error. */
8fbc5ae7 2004 if (COMPLETE_TYPE_P (t))
4223f82f
MM
2005 {
2006 error ("redefinition of `%#T'", t);
2007 cp_error_at ("previous definition of `%#T'", t);
2008 return error_mark_node;
2009 }
4c571114 2010
b4f70b3d 2011 /* Update the location of the decl. */
f31686a3 2012 DECL_SOURCE_LOCATION (TYPE_NAME (t)) = input_location;
b4f70b3d 2013
4c571114 2014 if (TYPE_BEING_DEFINED (t))
ce4a0391 2015 {
33848bb0 2016 t = make_aggr_type (TREE_CODE (t));
ce4a0391 2017 pushtag (TYPE_IDENTIFIER (t), t, 0);
ce4a0391 2018 }
ff350acd 2019 maybe_process_partial_specialization (t);
29370796 2020 pushclass (t);
ce4a0391 2021 TYPE_BEING_DEFINED (t) = 1;
c0694c4b
MM
2022 if (flag_pack_struct)
2023 {
2024 tree v;
2025 TYPE_PACKED (t) = 1;
2026 /* Even though the type is being defined for the first time
2027 here, there might have been a forward declaration, so there
2028 might be cv-qualified variants of T. */
2029 for (v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
2030 TYPE_PACKED (v) = 1;
2031 }
ce4a0391
MM
2032 /* Reset the interface data, at the earliest possible
2033 moment, as it might have been set via a class foo;
2034 before. */
1951a1b6
JM
2035 if (! TYPE_ANONYMOUS_P (t))
2036 {
2037 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
2038 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
2039 (t, interface_unknown);
2040 }
ce4a0391
MM
2041 reset_specialization();
2042
b7975aed
MM
2043 /* Make a declaration for this class in its own scope. */
2044 build_self_reference ();
2045
830fcda8 2046 return t;
ce4a0391
MM
2047}
2048
61a127b3
MM
2049/* Finish the member declaration given by DECL. */
2050
2051void
3a978d72 2052finish_member_declaration (tree decl)
61a127b3
MM
2053{
2054 if (decl == error_mark_node || decl == NULL_TREE)
2055 return;
2056
2057 if (decl == void_type_node)
2058 /* The COMPONENT was a friend, not a member, and so there's
2059 nothing for us to do. */
2060 return;
2061
2062 /* We should see only one DECL at a time. */
2063 my_friendly_assert (TREE_CHAIN (decl) == NULL_TREE, 0);
2064
2065 /* Set up access control for DECL. */
2066 TREE_PRIVATE (decl)
2067 = (current_access_specifier == access_private_node);
2068 TREE_PROTECTED (decl)
2069 = (current_access_specifier == access_protected_node);
2070 if (TREE_CODE (decl) == TEMPLATE_DECL)
2071 {
17aec3eb
RK
2072 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
2073 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl);
61a127b3
MM
2074 }
2075
2076 /* Mark the DECL as a member of the current class. */
4f1c5b7d 2077 DECL_CONTEXT (decl) = current_class_type;
61a127b3 2078
421844e7
MM
2079 /* [dcl.link]
2080
2081 A C language linkage is ignored for the names of class members
2082 and the member function type of class member functions. */
2083 if (DECL_LANG_SPECIFIC (decl) && DECL_LANGUAGE (decl) == lang_c)
5d2ed28c 2084 SET_DECL_LANGUAGE (decl, lang_cplusplus);
421844e7 2085
61a127b3
MM
2086 /* Put functions on the TYPE_METHODS list and everything else on the
2087 TYPE_FIELDS list. Note that these are built up in reverse order.
2088 We reverse them (to obtain declaration order) in finish_struct. */
2089 if (TREE_CODE (decl) == FUNCTION_DECL
2090 || DECL_FUNCTION_TEMPLATE_P (decl))
2091 {
2092 /* We also need to add this function to the
2093 CLASSTYPE_METHOD_VEC. */
452a394b 2094 add_method (current_class_type, decl, /*error_p=*/0);
61a127b3
MM
2095
2096 TREE_CHAIN (decl) = TYPE_METHODS (current_class_type);
2097 TYPE_METHODS (current_class_type) = decl;
f139561c
MM
2098
2099 maybe_add_class_template_decl_list (current_class_type, decl,
2100 /*friend_p=*/0);
61a127b3 2101 }
f139561c 2102 /* Enter the DECL into the scope of the class. */
fd9aef9d 2103 else if ((TREE_CODE (decl) == USING_DECL && TREE_TYPE (decl))
399dedb9 2104 || pushdecl_class_level (decl))
61a127b3
MM
2105 {
2106 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
2107 go at the beginning. The reason is that lookup_field_1
2108 searches the list in order, and we want a field name to
2109 override a type name so that the "struct stat hack" will
2110 work. In particular:
2111
2112 struct S { enum E { }; int E } s;
2113 s.E = 3;
2114
0e339752 2115 is valid. In addition, the FIELD_DECLs must be maintained in
61a127b3
MM
2116 declaration order so that class layout works as expected.
2117 However, we don't need that order until class layout, so we
2118 save a little time by putting FIELD_DECLs on in reverse order
2119 here, and then reversing them in finish_struct_1. (We could
2120 also keep a pointer to the correct insertion points in the
2121 list.) */
2122
2123 if (TREE_CODE (decl) == TYPE_DECL)
2124 TYPE_FIELDS (current_class_type)
2125 = chainon (TYPE_FIELDS (current_class_type), decl);
2126 else
2127 {
2128 TREE_CHAIN (decl) = TYPE_FIELDS (current_class_type);
2129 TYPE_FIELDS (current_class_type) = decl;
2130 }
8f032717 2131
f139561c
MM
2132 maybe_add_class_template_decl_list (current_class_type, decl,
2133 /*friend_p=*/0);
61a127b3
MM
2134 }
2135}
2136
35acd3f2
MM
2137/* Finish processing the declaration of a member class template
2138 TYPES whose template parameters are given by PARMS. */
2139
2140tree
3a978d72 2141finish_member_class_template (tree types)
35acd3f2 2142{
36a117a5
MM
2143 tree t;
2144
2145 /* If there are declared, but undefined, partial specializations
2146 mixed in with the typespecs they will not yet have passed through
2147 maybe_process_partial_specialization, so we do that here. */
2148 for (t = types; t != NULL_TREE; t = TREE_CHAIN (t))
2149 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t))))
2150 maybe_process_partial_specialization (TREE_VALUE (t));
2151
61a127b3 2152 grok_x_components (types);
35acd3f2
MM
2153 if (TYPE_CONTEXT (TREE_VALUE (types)) != current_class_type)
2154 /* The component was in fact a friend declaration. We avoid
2155 finish_member_template_decl performing certain checks by
2156 unsetting TYPES. */
2157 types = NULL_TREE;
61a127b3
MM
2158
2159 finish_member_template_decl (types);
2160
35acd3f2
MM
2161 /* As with other component type declarations, we do
2162 not store the new DECL on the list of
2163 component_decls. */
2164 return NULL_TREE;
2165}
36a117a5 2166
306ef644 2167/* Finish processing a complete template declaration. The PARMS are
36a117a5
MM
2168 the template parameters. */
2169
2170void
3a978d72 2171finish_template_decl (tree parms)
36a117a5
MM
2172{
2173 if (parms)
2174 end_template_decl ();
2175 else
2176 end_specialization ();
2177}
2178
509fc277 2179/* Finish processing a template-id (which names a type) of the form
36a117a5 2180 NAME < ARGS >. Return the TYPE_DECL for the type named by the
838dfd8a 2181 template-id. If ENTERING_SCOPE is nonzero we are about to enter
36a117a5
MM
2182 the scope of template-id indicated. */
2183
2184tree
3a978d72 2185finish_template_type (tree name, tree args, int entering_scope)
36a117a5
MM
2186{
2187 tree decl;
2188
2189 decl = lookup_template_class (name, args,
42eaed49
NS
2190 NULL_TREE, NULL_TREE, entering_scope,
2191 tf_error | tf_warning | tf_user);
36a117a5
MM
2192 if (decl != error_mark_node)
2193 decl = TYPE_STUB_DECL (decl);
2194
2195 return decl;
2196}
648f19f6 2197
ea6021e8
MM
2198/* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2199 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2200 BASE_CLASS, or NULL_TREE if an error occurred. The
aba649ba 2201 ACCESS_SPECIFIER is one of
ea6021e8
MM
2202 access_{default,public,protected_private}[_virtual]_node.*/
2203
2204tree
dbbf88d1 2205finish_base_specifier (tree base, tree access, bool virtual_p)
ea6021e8 2206{
ea6021e8
MM
2207 tree result;
2208
dbbf88d1 2209 if (base == error_mark_node)
acb044ee
GDR
2210 {
2211 error ("invalid base-class specification");
2212 result = NULL_TREE;
2213 }
dbbf88d1 2214 else if (! is_aggr_type (base, 1))
ea6021e8 2215 result = NULL_TREE;
ea6021e8 2216 else
bb92901d 2217 {
dbbf88d1 2218 if (cp_type_quals (base) != 0)
bb92901d 2219 {
dbbf88d1
NS
2220 error ("base class `%T' has cv qualifiers", base);
2221 base = TYPE_MAIN_VARIANT (base);
bb92901d 2222 }
dbbf88d1
NS
2223 result = build_tree_list (access, base);
2224 TREE_VIA_VIRTUAL (result) = virtual_p;
bb92901d 2225 }
ea6021e8
MM
2226
2227 return result;
2228}
61a127b3
MM
2229
2230/* Called when multiple declarators are processed. If that is not
cd0be382 2231 permitted in this context, an error is issued. */
61a127b3
MM
2232
2233void
3a978d72 2234check_multiple_declarators (void)
61a127b3
MM
2235{
2236 /* [temp]
2237
2238 In a template-declaration, explicit specialization, or explicit
2239 instantiation the init-declarator-list in the declaration shall
2240 contain at most one declarator.
2241
2242 We don't just use PROCESSING_TEMPLATE_DECL for the first
0e339752 2243 condition since that would disallow the perfectly valid code,
61a127b3 2244 like `template <class T> struct S { int i, j; };'. */
5f261ba9 2245 if (at_function_scope_p ())
61a127b3
MM
2246 /* It's OK to write `template <class T> void f() { int i, j;}'. */
2247 return;
2248
2249 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2250 || processing_explicit_instantiation
2251 || processing_specialization)
33bd39a2 2252 error ("multiple declarators in template declaration");
61a127b3
MM
2253}
2254
22038b2c
NS
2255/* Issue a diagnostic that NAME cannot be found in SCOPE. */
2256
2257void
2258qualified_name_lookup_error (tree scope, tree name)
2259{
2260 if (TYPE_P (scope))
2261 {
2262 if (!COMPLETE_TYPE_P (scope))
2263 error ("incomplete type `%T' used in nested name specifier", scope);
2264 else
2265 error ("`%D' is not a member of `%T'", name, scope);
2266 }
2267 else if (scope != global_namespace)
2268 error ("`%D' is not a member of `%D'", name, scope);
2269 else
2270 error ("`::%D' has not been declared", name);
2271}
2272
b3445994
MM
2273/* ID_EXPRESSION is a representation of parsed, but unprocessed,
2274 id-expression. (See cp_parser_id_expression for details.) SCOPE,
2275 if non-NULL, is the type or namespace used to explicitly qualify
2276 ID_EXPRESSION. DECL is the entity to which that name has been
2277 resolved.
2278
2279 *CONSTANT_EXPRESSION_P is true if we are presently parsing a
2280 constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
2281 be set to true if this expression isn't permitted in a
2282 constant-expression, but it is otherwise not set by this function.
2283 *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
2284 constant-expression, but a non-constant expression is also
2285 permissible.
2286
2287 If an error occurs, and it is the kind of error that might cause
2288 the parser to abort a tentative parse, *ERROR_MSG is filled in. It
2289 is the caller's responsibility to issue the message. *ERROR_MSG
2290 will be a string with static storage duration, so the caller need
2291 not "free" it.
2292
2293 Return an expression for the entity, after issuing appropriate
2294 diagnostics. This function is also responsible for transforming a
2295 reference to a non-static member into a COMPONENT_REF that makes
2296 the use of "this" explicit.
2297
2298 Upon return, *IDK will be filled in appropriately. */
2299
2300tree
2301finish_id_expression (tree id_expression,
2302 tree decl,
2303 tree scope,
2304 cp_id_kind *idk,
2305 tree *qualifying_class,
67c03833
JM
2306 bool integral_constant_expression_p,
2307 bool allow_non_integral_constant_expression_p,
2308 bool *non_integral_constant_expression_p,
b3445994
MM
2309 const char **error_msg)
2310{
2311 /* Initialize the output parameters. */
2312 *idk = CP_ID_KIND_NONE;
2313 *error_msg = NULL;
2314
2315 if (id_expression == error_mark_node)
2316 return error_mark_node;
2317 /* If we have a template-id, then no further lookup is
2318 required. If the template-id was for a template-class, we
2319 will sometimes have a TYPE_DECL at this point. */
2320 else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
ee935db4 2321 || TREE_CODE (decl) == TYPE_DECL)
b3445994
MM
2322 ;
2323 /* Look up the name. */
2324 else
2325 {
2326 if (decl == error_mark_node)
2327 {
2328 /* Name lookup failed. */
4546865e
MM
2329 if (scope
2330 && (!TYPE_P (scope)
2331 || (!dependent_type_p (scope)
2332 && !(TREE_CODE (id_expression) == IDENTIFIER_NODE
2333 && IDENTIFIER_TYPENAME_P (id_expression)
2334 && dependent_type_p (TREE_TYPE (id_expression))))))
b3445994 2335 {
4546865e
MM
2336 /* If the qualifying type is non-dependent (and the name
2337 does not name a conversion operator to a dependent
2338 type), issue an error. */
22038b2c 2339 qualified_name_lookup_error (scope, id_expression);
b3445994
MM
2340 return error_mark_node;
2341 }
2342 else if (!scope)
2343 {
2344 /* It may be resolved via Koenig lookup. */
2345 *idk = CP_ID_KIND_UNQUALIFIED;
2346 return id_expression;
2347 }
4546865e
MM
2348 else
2349 decl = id_expression;
b3445994
MM
2350 }
2351 /* If DECL is a variable that would be out of scope under
2352 ANSI/ISO rules, but in scope in the ARM, name lookup
2353 will succeed. Issue a diagnostic here. */
2354 else
2355 decl = check_for_out_of_scope_variable (decl);
2356
2357 /* Remember that the name was used in the definition of
2358 the current class so that we can check later to see if
2359 the meaning would have been different after the class
2360 was entirely defined. */
2361 if (!scope && decl != error_mark_node)
2362 maybe_note_name_used_in_class (id_expression, decl);
2363 }
2364
2365 /* If we didn't find anything, or what we found was a type,
2366 then this wasn't really an id-expression. */
2367 if (TREE_CODE (decl) == TEMPLATE_DECL
2368 && !DECL_FUNCTION_TEMPLATE_P (decl))
2369 {
2370 *error_msg = "missing template arguments";
2371 return error_mark_node;
2372 }
2373 else if (TREE_CODE (decl) == TYPE_DECL
2374 || TREE_CODE (decl) == NAMESPACE_DECL)
2375 {
2376 *error_msg = "expected primary-expression";
2377 return error_mark_node;
2378 }
2379
2380 /* If the name resolved to a template parameter, there is no
931a9c05
GB
2381 need to look it up again later. */
2382 if ((TREE_CODE (decl) == CONST_DECL && DECL_TEMPLATE_PARM_P (decl))
2383 || TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
b3445994
MM
2384 {
2385 *idk = CP_ID_KIND_NONE;
931a9c05
GB
2386 if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
2387 decl = TEMPLATE_PARM_DECL (decl);
67c03833 2388 if (integral_constant_expression_p
68deab91 2389 && !dependent_type_p (TREE_TYPE (decl))
931a9c05
GB
2390 && !INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (decl)))
2391 {
67c03833 2392 if (!allow_non_integral_constant_expression_p)
931a9c05
GB
2393 error ("template parameter `%D' of type `%T' is not allowed in "
2394 "an integral constant expression because it is not of "
2395 "integral or enumeration type", decl, TREE_TYPE (decl));
67c03833 2396 *non_integral_constant_expression_p = true;
931a9c05
GB
2397 }
2398 return DECL_INITIAL (decl);
2399 }
2400 /* Similarly, we resolve enumeration constants to their
2401 underlying values. */
2402 else if (TREE_CODE (decl) == CONST_DECL)
2403 {
2404 *idk = CP_ID_KIND_NONE;
2405 if (!processing_template_decl)
b3445994
MM
2406 return DECL_INITIAL (decl);
2407 return decl;
2408 }
2409 else
2410 {
2411 bool dependent_p;
2412
2413 /* If the declaration was explicitly qualified indicate
2414 that. The semantics of `A::f(3)' are different than
2415 `f(3)' if `f' is virtual. */
2416 *idk = (scope
2417 ? CP_ID_KIND_QUALIFIED
2418 : (TREE_CODE (decl) == TEMPLATE_ID_EXPR
2419 ? CP_ID_KIND_TEMPLATE_ID
2420 : CP_ID_KIND_UNQUALIFIED));
2421
2422
2423 /* [temp.dep.expr]
2424
2425 An id-expression is type-dependent if it contains an
2426 identifier that was declared with a dependent type.
2427
b3445994
MM
2428 The standard is not very specific about an id-expression that
2429 names a set of overloaded functions. What if some of them
2430 have dependent types and some of them do not? Presumably,
2431 such a name should be treated as a dependent name. */
2432 /* Assume the name is not dependent. */
2433 dependent_p = false;
2434 if (!processing_template_decl)
2435 /* No names are dependent outside a template. */
2436 ;
2437 /* A template-id where the name of the template was not resolved
2438 is definitely dependent. */
2439 else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
2440 && (TREE_CODE (TREE_OPERAND (decl, 0))
2441 == IDENTIFIER_NODE))
2442 dependent_p = true;
2443 /* For anything except an overloaded function, just check its
2444 type. */
2445 else if (!is_overloaded_fn (decl))
2446 dependent_p
2447 = dependent_type_p (TREE_TYPE (decl));
2448 /* For a set of overloaded functions, check each of the
2449 functions. */
2450 else
2451 {
2452 tree fns = decl;
2453
2454 if (BASELINK_P (fns))
2455 fns = BASELINK_FUNCTIONS (fns);
2456
2457 /* For a template-id, check to see if the template
2458 arguments are dependent. */
2459 if (TREE_CODE (fns) == TEMPLATE_ID_EXPR)
2460 {
2461 tree args = TREE_OPERAND (fns, 1);
2462 dependent_p = any_dependent_template_arguments_p (args);
2463 /* The functions are those referred to by the
2464 template-id. */
2465 fns = TREE_OPERAND (fns, 0);
2466 }
2467
2468 /* If there are no dependent template arguments, go through
cd0be382 2469 the overloaded functions. */
b3445994
MM
2470 while (fns && !dependent_p)
2471 {
2472 tree fn = OVL_CURRENT (fns);
2473
2474 /* Member functions of dependent classes are
2475 dependent. */
2476 if (TREE_CODE (fn) == FUNCTION_DECL
2477 && type_dependent_expression_p (fn))
2478 dependent_p = true;
2479 else if (TREE_CODE (fn) == TEMPLATE_DECL
2480 && dependent_template_p (fn))
2481 dependent_p = true;
2482
2483 fns = OVL_NEXT (fns);
2484 }
2485 }
2486
2487 /* If the name was dependent on a template parameter, we will
2488 resolve the name at instantiation time. */
2489 if (dependent_p)
2490 {
2491 /* Create a SCOPE_REF for qualified names, if the scope is
2492 dependent. */
2493 if (scope)
2494 {
2495 if (TYPE_P (scope))
2496 *qualifying_class = scope;
2497 /* Since this name was dependent, the expression isn't
2498 constant -- yet. No error is issued because it might
2499 be constant when things are instantiated. */
67c03833
JM
2500 if (integral_constant_expression_p)
2501 *non_integral_constant_expression_p = true;
b3445994
MM
2502 if (TYPE_P (scope) && dependent_type_p (scope))
2503 return build_nt (SCOPE_REF, scope, id_expression);
2504 else if (TYPE_P (scope) && DECL_P (decl))
2505 return build (SCOPE_REF, TREE_TYPE (decl), scope,
2506 id_expression);
2507 else
2508 return decl;
2509 }
2510 /* A TEMPLATE_ID already contains all the information we
2511 need. */
2512 if (TREE_CODE (id_expression) == TEMPLATE_ID_EXPR)
2513 return id_expression;
2514 /* Since this name was dependent, the expression isn't
2515 constant -- yet. No error is issued because it might be
2516 constant when things are instantiated. */
67c03833
JM
2517 if (integral_constant_expression_p)
2518 *non_integral_constant_expression_p = true;
10b1d5e7 2519 *idk = CP_ID_KIND_UNQUALIFIED_DEPENDENT;
5a98fa7b
MM
2520 /* If we found a variable, then name lookup during the
2521 instantiation will always resolve to the same VAR_DECL
2522 (or an instantiation thereof). */
3c398f34
MM
2523 if (TREE_CODE (decl) == VAR_DECL
2524 || TREE_CODE (decl) == PARM_DECL)
5a98fa7b 2525 return decl;
10b1d5e7 2526 return id_expression;
b3445994
MM
2527 }
2528
2529 /* Only certain kinds of names are allowed in constant
931a9c05
GB
2530 expression. Enumerators and template parameters
2531 have already been handled above. */
67c03833 2532 if (integral_constant_expression_p)
b3445994 2533 {
931a9c05
GB
2534 /* Const variables or static data members of integral or
2535 enumeration types initialized with constant expressions
2536 are OK. */
2537 if (TREE_CODE (decl) == VAR_DECL
2538 && CP_TYPE_CONST_P (TREE_TYPE (decl))
2539 && INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (decl))
2540 && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
b3445994
MM
2541 ;
2542 else
2543 {
67c03833 2544 if (!allow_non_integral_constant_expression_p)
b3445994
MM
2545 {
2546 error ("`%D' cannot appear in a constant-expression", decl);
2547 return error_mark_node;
2548 }
67c03833 2549 *non_integral_constant_expression_p = true;
b3445994
MM
2550 }
2551 }
415d4636
MM
2552
2553 if (TREE_CODE (decl) == NAMESPACE_DECL)
9e95d15f
NS
2554 {
2555 error ("use of namespace `%D' as expression", decl);
2556 return error_mark_node;
2557 }
2558 else if (DECL_CLASS_TEMPLATE_P (decl))
2559 {
2560 error ("use of class template `%T' as expression", decl);
2561 return error_mark_node;
2562 }
2563 else if (TREE_CODE (decl) == TREE_LIST)
2564 {
2565 /* Ambiguous reference to base members. */
2566 error ("request for member `%D' is ambiguous in "
2567 "multiple inheritance lattice", id_expression);
2568 print_candidates (decl);
2569 return error_mark_node;
2570 }
415d4636
MM
2571
2572 /* Mark variable-like entities as used. Functions are similarly
2573 marked either below or after overload resolution. */
2574 if (TREE_CODE (decl) == VAR_DECL
2575 || TREE_CODE (decl) == PARM_DECL
2576 || TREE_CODE (decl) == RESULT_DECL)
2577 mark_used (decl);
2578
2579 if (scope)
2580 {
2581 decl = (adjust_result_of_qualified_name_lookup
2582 (decl, scope, current_class_type));
e20bcc5e
JH
2583
2584 if (TREE_CODE (decl) == FUNCTION_DECL)
2585 mark_used (decl);
2586
415d4636
MM
2587 if (TREE_CODE (decl) == FIELD_DECL || BASELINK_P (decl))
2588 *qualifying_class = scope;
2589 else if (!processing_template_decl)
2590 decl = convert_from_reference (decl);
2591 else if (TYPE_P (scope))
2592 decl = build (SCOPE_REF, TREE_TYPE (decl), scope, decl);
2593 }
9e95d15f
NS
2594 else if (TREE_CODE (decl) == FIELD_DECL)
2595 decl = finish_non_static_data_member (decl, current_class_ref,
2596 /*qualifying_scope=*/NULL_TREE);
2597 else if (is_overloaded_fn (decl))
2598 {
2599 tree first_fn = OVL_CURRENT (decl);
b3445994 2600
9e95d15f
NS
2601 if (TREE_CODE (first_fn) == TEMPLATE_DECL)
2602 first_fn = DECL_TEMPLATE_RESULT (first_fn);
415d4636
MM
2603
2604 if (!really_overloaded_fn (decl))
2605 mark_used (first_fn);
2606
9e95d15f
NS
2607 if (TREE_CODE (first_fn) == FUNCTION_DECL
2608 && DECL_FUNCTION_MEMBER_P (first_fn))
2609 {
2610 /* A set of member functions. */
2611 decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0);
2612 return finish_class_member_access_expr (decl, id_expression);
2613 }
9e95d15f
NS
2614 }
2615 else
2616 {
2617 if (TREE_CODE (decl) == VAR_DECL
2618 || TREE_CODE (decl) == PARM_DECL
2619 || TREE_CODE (decl) == RESULT_DECL)
2620 {
2621 tree context = decl_function_context (decl);
2622
2623 if (context != NULL_TREE && context != current_function_decl
2624 && ! TREE_STATIC (decl))
2625 {
2626 error ("use of %s from containing function",
2627 (TREE_CODE (decl) == VAR_DECL
2628 ? "`auto' variable" : "parameter"));
2629 cp_error_at (" `%#D' declared here", decl);
2630 return error_mark_node;
2631 }
2632 }
2633
2634 if (DECL_P (decl) && DECL_NONLOCAL (decl)
2635 && DECL_CLASS_SCOPE_P (decl)
2636 && DECL_CONTEXT (decl) != current_class_type)
2637 {
2638 tree path;
2639
2640 path = currently_open_derived_class (DECL_CONTEXT (decl));
2641 perform_or_defer_access_check (TYPE_BINFO (path), decl);
2642 }
2643
9e95d15f
NS
2644 if (! processing_template_decl)
2645 decl = convert_from_reference (decl);
2646 }
2647
b3445994
MM
2648 /* Resolve references to variables of anonymous unions
2649 into COMPONENT_REFs. */
2650 if (TREE_CODE (decl) == ALIAS_DECL)
6de9cd9a 2651 decl = unshare_expr (DECL_INITIAL (decl));
b3445994
MM
2652 }
2653
2654 if (TREE_DEPRECATED (decl))
2655 warn_deprecated_use (decl);
2656
2657 return decl;
2658}
2659
0213a355
JM
2660/* Implement the __typeof keyword: Return the type of EXPR, suitable for
2661 use as a type-specifier. */
2662
b894fc05 2663tree
3a978d72 2664finish_typeof (tree expr)
b894fc05 2665{
65a5559b
MM
2666 tree type;
2667
dffbbe80 2668 if (type_dependent_expression_p (expr))
b894fc05 2669 {
65a5559b 2670 type = make_aggr_type (TYPEOF_TYPE);
eb34af89 2671 TYPEOF_TYPE_EXPR (type) = expr;
b894fc05 2672
65a5559b 2673 return type;
b894fc05
JM
2674 }
2675
65a5559b
MM
2676 type = TREE_TYPE (expr);
2677
2678 if (!type || type == unknown_type_node)
2679 {
2680 error ("type of `%E' is unknown", expr);
2681 return error_mark_node;
2682 }
2683
2684 return type;
b894fc05 2685}
558475f0 2686
3eb24f73 2687/* Called from expand_body via walk_tree. Replace all AGGR_INIT_EXPRs
6de9cd9a 2688 with equivalent CALL_EXPRs. */
3eb24f73
MM
2689
2690static tree
3a978d72 2691simplify_aggr_init_exprs_r (tree* tp,
9eeb200f
JM
2692 int* walk_subtrees,
2693 void* data ATTRIBUTE_UNUSED)
3eb24f73 2694{
22e92ac3
MM
2695 /* We don't need to walk into types; there's nothing in a type that
2696 needs simplification. (And, furthermore, there are places we
2697 actively don't want to go. For example, we don't want to wander
2698 into the default arguments for a FUNCTION_DECL that appears in a
2699 CALL_EXPR.) */
9eeb200f 2700 if (TYPE_P (*tp))
22e92ac3
MM
2701 {
2702 *walk_subtrees = 0;
2703 return NULL_TREE;
2704 }
2705 /* Only AGGR_INIT_EXPRs are interesting. */
9eeb200f 2706 else if (TREE_CODE (*tp) != AGGR_INIT_EXPR)
3eb24f73
MM
2707 return NULL_TREE;
2708
9eeb200f
JM
2709 simplify_aggr_init_expr (tp);
2710
2711 /* Keep iterating. */
2712 return NULL_TREE;
2713}
2714
2715/* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
2716 function is broken out from the above for the benefit of the tree-ssa
2717 project. */
2718
2719void
2720simplify_aggr_init_expr (tree *tp)
2721{
2722 tree aggr_init_expr = *tp;
2723
3eb24f73 2724 /* Form an appropriate CALL_EXPR. */
9eeb200f
JM
2725 tree fn = TREE_OPERAND (aggr_init_expr, 0);
2726 tree args = TREE_OPERAND (aggr_init_expr, 1);
2727 tree slot = TREE_OPERAND (aggr_init_expr, 2);
2692eb7d 2728 tree type = TREE_TYPE (slot);
9eeb200f
JM
2729
2730 tree call_expr;
2731 enum style_t { ctor, arg, pcc } style;
4977bab6 2732
3eb24f73 2733 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
4977bab6
ZW
2734 style = ctor;
2735#ifdef PCC_STATIC_STRUCT_RETURN
2736 else if (1)
2737 style = pcc;
2738#endif
2739 else if (TREE_ADDRESSABLE (type))
2740 style = arg;
2741 else
2742 /* We shouldn't build an AGGR_INIT_EXPR if we don't need any special
2743 handling. See build_cplus_new. */
2744 abort ();
2745
2746 if (style == ctor || style == arg)
3eb24f73 2747 {
4977bab6
ZW
2748 /* Pass the address of the slot. If this is a constructor, we
2749 replace the first argument; otherwise, we tack on a new one. */
9eeb200f
JM
2750 tree addr;
2751
4977bab6
ZW
2752 if (style == ctor)
2753 args = TREE_CHAIN (args);
2754
dffd7eb6 2755 cxx_mark_addressable (slot);
2692eb7d 2756 addr = build1 (ADDR_EXPR, build_pointer_type (type), slot);
9eeb200f
JM
2757 if (style == arg)
2758 {
2759 /* The return type might have different cv-quals from the slot. */
2760 tree fntype = TREE_TYPE (TREE_TYPE (fn));
2761#ifdef ENABLE_CHECKING
2762 if (TREE_CODE (fntype) != FUNCTION_TYPE
2763 && TREE_CODE (fntype) != METHOD_TYPE)
2764 abort ();
2765#endif
2766 addr = convert (build_pointer_type (TREE_TYPE (fntype)), addr);
2767 }
2768
2769 args = tree_cons (NULL_TREE, addr, args);
3eb24f73 2770 }
4977bab6 2771
b850de4f
MM
2772 call_expr = build (CALL_EXPR,
2773 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
2774 fn, args, NULL_TREE);
3eb24f73 2775
4977bab6 2776 if (style == arg)
89ea02fb
JM
2777 /* Tell the backend that we've added our return slot to the argument
2778 list. */
2779 CALL_EXPR_HAS_RETURN_SLOT_ADDR (call_expr) = 1;
4977bab6 2780 else if (style == pcc)
3eb24f73 2781 {
4977bab6
ZW
2782 /* If we're using the non-reentrant PCC calling convention, then we
2783 need to copy the returned value out of the static buffer into the
2784 SLOT. */
78757caa 2785 push_deferring_access_checks (dk_no_check);
46af705a
JDA
2786 call_expr = build_aggr_init (slot, call_expr,
2787 DIRECT_BIND | LOOKUP_ONLYCONVERTING);
78757caa 2788 pop_deferring_access_checks ();
3eb24f73 2789 }
3eb24f73 2790
3eb24f73 2791 *tp = call_expr;
3eb24f73
MM
2792}
2793
31f8e4f3
MM
2794/* Emit all thunks to FN that should be emitted when FN is emitted. */
2795
2796static void
3a978d72 2797emit_associated_thunks (tree fn)
31f8e4f3
MM
2798{
2799 /* When we use vcall offsets, we emit thunks with the virtual
2800 functions to which they thunk. The whole point of vcall offsets
2801 is so that you can know statically the entire set of thunks that
2802 will ever be needed for a given virtual function, thereby
2803 enabling you to output all the thunks with the function itself. */
3461fba7 2804 if (DECL_VIRTUAL_P (fn))
31f8e4f3 2805 {
bb5e8a7f 2806 tree thunk;
4977bab6 2807
bb5e8a7f 2808 for (thunk = DECL_THUNKS (fn); thunk; thunk = TREE_CHAIN (thunk))
4977bab6 2809 {
e00853fd 2810 if (!THUNK_ALIAS (thunk))
4977bab6 2811 {
bb885938
NS
2812 use_thunk (thunk, /*emit_p=*/1);
2813 if (DECL_RESULT_THUNK_P (thunk))
2814 {
2815 tree probe;
2816
2817 for (probe = DECL_THUNKS (thunk);
2818 probe; probe = TREE_CHAIN (probe))
2819 use_thunk (probe, /*emit_p=*/1);
2820 }
4977bab6 2821 }
bb885938
NS
2822 else
2823 my_friendly_assert (!DECL_THUNKS (thunk), 20031023);
4977bab6 2824 }
31f8e4f3
MM
2825 }
2826}
2827
558475f0
MM
2828/* Generate RTL for FN. */
2829
2830void
3a978d72 2831expand_body (tree fn)
558475f0 2832{
367aa585 2833 tree saved_function;
6de9cd9a 2834
92788413
MM
2835 /* Compute the appropriate object-file linkage for inline
2836 functions. */
79065db2 2837 if (DECL_DECLARED_INLINE_P (fn))
92788413
MM
2838 import_export_decl (fn);
2839
4f8e1232
MM
2840 /* If FN is external, then there's no point in generating RTL for
2841 it. This situation can arise with an inline function under
83662e2b 2842 `-fexternal-templates'; we instantiate the function, even though
4f8e1232
MM
2843 we're not planning on emitting it, in case we get a chance to
2844 inline it. */
2845 if (DECL_EXTERNAL (fn))
2846 return;
2847
4985cde3 2848 /* ??? When is this needed? */
367aa585 2849 saved_function = current_function_decl;
367aa585 2850
de81ffd4
JH
2851 /* Emit any thunks that should be emitted at the same time as FN. */
2852 emit_associated_thunks (fn);
2853
c1f927e8 2854 tree_rest_of_compilation (fn, function_depth > 1);
d658cd4c 2855
367aa585 2856 current_function_decl = saved_function;
ea11ca7e 2857
4985cde3 2858 extract_interface_info ();
14691f8d 2859
4985cde3
RH
2860 /* If this function is marked with the constructor attribute, add it
2861 to the list of functions to be called along with constructors
2862 from static duration objects. */
2863 if (DECL_STATIC_CONSTRUCTOR (fn))
2864 static_ctors = tree_cons (NULL_TREE, fn, static_ctors);
2865
2866 /* If this function is marked with the destructor attribute, add it
2867 to the list of functions to be called along with destructors from
2868 static duration objects. */
2869 if (DECL_STATIC_DESTRUCTOR (fn))
2870 static_dtors = tree_cons (NULL_TREE, fn, static_dtors);
85b22f78
NS
2871
2872 if (DECL_CLONED_FUNCTION_P (fn))
2873 {
2874 /* If this is a clone, go through the other clones now and mark
2875 their parameters used. We have to do that here, as we don't
2876 know whether any particular clone will be expanded, and
2877 therefore cannot pick one arbitrarily. */
2878 tree probe;
2879
2880 for (probe = TREE_CHAIN (DECL_CLONED_FUNCTION (fn));
2881 probe && DECL_CLONED_FUNCTION_P (probe);
2882 probe = TREE_CHAIN (probe))
2883 {
2884 tree parms;
2885
2886 for (parms = DECL_ARGUMENTS (probe);
2887 parms; parms = TREE_CHAIN (parms))
2888 TREE_USED (parms) = 1;
2889 }
2890 }
558475f0 2891}
54f7877c 2892
8cd2462c
JH
2893/* Generate RTL for FN. */
2894
2895void
5671bf27 2896expand_or_defer_fn (tree fn)
8cd2462c
JH
2897{
2898 /* When the parser calls us after finishing the body of a template
c353b8e3
MM
2899 function, we don't really want to expand the body. */
2900 if (processing_template_decl)
8cd2462c
JH
2901 {
2902 /* Normally, collection only occurs in rest_of_compilation. So,
2903 if we don't collect here, we never collect junk generated
2904 during the processing of templates until we hit a
2905 non-template function. */
2906 ggc_collect ();
2907 return;
2908 }
2909
2910 /* Replace AGGR_INIT_EXPRs with appropriate CALL_EXPRs. */
2911 walk_tree_without_duplicates (&DECL_SAVED_TREE (fn),
2912 simplify_aggr_init_exprs_r,
2913 NULL);
2914
2915 /* If this is a constructor or destructor body, we have to clone
2916 it. */
2917 if (maybe_clone_body (fn))
2918 {
2919 /* We don't want to process FN again, so pretend we've written
2920 it out, even though we haven't. */
2921 TREE_ASM_WRITTEN (fn) = 1;
2922 return;
2923 }
2924
2925 /* There's no reason to do any of the work here if we're only doing
2926 semantic analysis; this code just generates RTL. */
2927 if (flag_syntax_only)
2928 return;
2929
e4d91027
RH
2930 /* Compute the appropriate object-file linkage for inline functions. */
2931 if (DECL_DECLARED_INLINE_P (fn))
2932 import_export_decl (fn);
8cd2462c 2933
99edd65d
RH
2934 function_depth++;
2935
e4d91027 2936 /* Expand or defer, at the whim of the compilation unit manager. */
6b00c969 2937 cgraph_finalize_function (fn, function_depth > 1);
99edd65d
RH
2938
2939 function_depth--;
8cd2462c
JH
2940}
2941
6de9cd9a
DN
2942struct nrv_data
2943{
2944 tree var;
2945 tree result;
2946 htab_t visited;
2947};
0d97bf4c 2948
6de9cd9a
DN
2949/* Helper function for walk_tree, used by finalize_nrv below. */
2950
2951static tree
2952finalize_nrv_r (tree* tp, int* walk_subtrees, void* data)
0d97bf4c 2953{
6de9cd9a
DN
2954 struct nrv_data *dp = (struct nrv_data *)data;
2955 void **slot;
07b2f2fd
JM
2956
2957 /* No need to walk into types. There wouldn't be any need to walk into
2958 non-statements, except that we have to consider STMT_EXPRs. */
0d97bf4c
JM
2959 if (TYPE_P (*tp))
2960 *walk_subtrees = 0;
6de9cd9a
DN
2961 /* Change all returns to just refer to the RESULT_DECL; this is a nop,
2962 but differs from using NULL_TREE in that it indicates that we care
2963 about the value of the RESULT_DECL. */
0d97bf4c 2964 else if (TREE_CODE (*tp) == RETURN_STMT)
6de9cd9a
DN
2965 RETURN_STMT_EXPR (*tp) = dp->result;
2966 /* Change all cleanups for the NRV to only run when an exception is
2967 thrown. */
07b2f2fd 2968 else if (TREE_CODE (*tp) == CLEANUP_STMT
6de9cd9a 2969 && CLEANUP_DECL (*tp) == dp->var)
659e5a7a 2970 CLEANUP_EH_ONLY (*tp) = 1;
6de9cd9a
DN
2971 /* Replace the DECL_STMT for the NRV with an initialization of the
2972 RESULT_DECL, if needed. */
2973 else if (TREE_CODE (*tp) == DECL_STMT
2974 && DECL_STMT_DECL (*tp) == dp->var)
2975 {
2976 tree init;
2977 if (DECL_INITIAL (dp->var)
2978 && DECL_INITIAL (dp->var) != error_mark_node)
2979 {
2980 init = build (INIT_EXPR, void_type_node, dp->result,
2981 DECL_INITIAL (dp->var));
2982 DECL_INITIAL (dp->var) = error_mark_node;
2983 }
2984 else
2985 init = NULL_TREE;
2986 init = build_stmt (EXPR_STMT, init);
2987 SET_EXPR_LOCUS (init, EXPR_LOCUS (*tp));
2988 TREE_CHAIN (init) = TREE_CHAIN (*tp);
2989 *tp = init;
2990 }
2991 /* And replace all uses of the NRV with the RESULT_DECL. */
2992 else if (*tp == dp->var)
2993 *tp = dp->result;
2994
2995 /* Avoid walking into the same tree more than once. Unfortunately, we
2996 can't just use walk_tree_without duplicates because it would only call
2997 us for the first occurrence of dp->var in the function body. */
2998 slot = htab_find_slot (dp->visited, *tp, INSERT);
2999 if (*slot)
3000 *walk_subtrees = 0;
3001 else
3002 *slot = *tp;
0d97bf4c
JM
3003
3004 /* Keep iterating. */
3005 return NULL_TREE;
3006}
3007
6de9cd9a
DN
3008/* Called from finish_function to implement the named return value
3009 optimization by overriding all the RETURN_STMTs and pertinent
3010 CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
3011 RESULT_DECL for the function. */
f444e36b 3012
4985cde3 3013void
6de9cd9a 3014finalize_nrv (tree *tp, tree var, tree result)
f444e36b 3015{
6de9cd9a
DN
3016 struct nrv_data data;
3017
3018 /* Copy debugging information from VAR to RESULT. */
3019 DECL_NAME (result) = DECL_NAME (var);
3020 DECL_SOURCE_LOCATION (result) = DECL_SOURCE_LOCATION (var);
3021 DECL_ABSTRACT_ORIGIN (result) = DECL_ABSTRACT_ORIGIN (var);
3022 /* Don't forget that we take its address. */
3023 TREE_ADDRESSABLE (result) = TREE_ADDRESSABLE (var);
3024
3025 data.var = var;
3026 data.result = result;
3027 data.visited = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
3028 walk_tree (tp, finalize_nrv_r, &data, 0);
3029 htab_delete (data.visited);
b850de4f
MM
3030}
3031
54f7877c
MM
3032/* Perform initialization related to this module. */
3033
3034void
3a978d72 3035init_cp_semantics (void)
54f7877c 3036{
54f7877c 3037}
cf22909c
KL
3038
3039#include "gt-cp-semantics.h"