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.
6 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
7 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
8 Written by Mark Mitchell (mmitchell@usa.net) based on code found
9 formerly in parse.y and pt.c.
11 This file is part of GCC.
13 GCC is free software; you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 3, or (at your option)
18 GCC is distributed in the hope that it will be useful, but
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.
23 You should have received a copy of the GNU General Public License
24 along with GCC; see the file COPYING3. If not see
25 <http://www.gnu.org/licenses/>. */
29 #include "coretypes.h"
33 #include "c-family/c-common.h"
34 #include "c-family/c-objc.h"
35 #include "tree-inline.h"
36 #include "tree-mudflap.h"
41 #include "diagnostic.h"
43 #include "tree-iterator.h"
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. */
54 static tree maybe_convert_cond (tree);
55 static tree finalize_nrv_r (tree *, int *, void *);
56 static tree capture_decltype (tree);
57 static tree thisify_lambda_field (tree);
60 /* Deferred Access Checking Overview
61 ---------------------------------
63 Most C++ expressions and declarations require access checking
64 to be performed during parsing. However, in several cases,
65 this has to be treated differently.
67 For member declarations, access checking has to be deferred
68 until more information about the declaration is known. For
80 When we are parsing the function return type `A::X', we don't
81 really know if this is allowed until we parse the function name.
83 Furthermore, some contexts require that access checking is
84 never performed at all. These include class heads, and template
87 Typical use of access checking functions is described here:
89 1. When we enter a context that requires certain access checking
90 mode, the function `push_deferring_access_checks' is called with
91 DEFERRING argument specifying the desired mode. Access checking
92 may be performed immediately (dk_no_deferred), deferred
93 (dk_deferred), or not performed (dk_no_check).
95 2. When a declaration such as a type, or a variable, is encountered,
96 the function `perform_or_defer_access_check' is called. It
97 maintains a VEC of all deferred checks.
99 3. The global `current_class_type' or `current_function_decl' is then
100 setup by the parser. `enforce_access' relies on these information
103 4. Upon exiting the context mentioned in step 1,
104 `perform_deferred_access_checks' is called to check all declaration
105 stored in the VEC. `pop_deferring_access_checks' is then
106 called to restore the previous access checking mode.
108 In case of parsing error, we simply call `pop_deferring_access_checks'
109 without `perform_deferred_access_checks'. */
111 typedef struct GTY(()) deferred_access {
112 /* A VEC representing name-lookups for which we have deferred
113 checking access controls. We cannot check the accessibility of
114 names used in a decl-specifier-seq until we know what is being
115 declared because code like:
122 A::B* A::f() { return 0; }
124 is valid, even though `A::B' is not generally accessible. */
125 VEC (deferred_access_check,gc)* GTY(()) deferred_access_checks;
127 /* The current mode of access checks. */
128 enum deferring_kind deferring_access_checks_kind;
131 DEF_VEC_O (deferred_access);
132 DEF_VEC_ALLOC_O (deferred_access,gc);
134 /* Data for deferred access checking. */
135 static GTY(()) VEC(deferred_access,gc) *deferred_access_stack;
136 static GTY(()) unsigned deferred_access_no_check;
138 /* Save the current deferred access states and start deferred
139 access checking iff DEFER_P is true. */
142 push_deferring_access_checks (deferring_kind deferring)
144 /* For context like template instantiation, access checking
145 disabling applies to all nested context. */
146 if (deferred_access_no_check || deferring == dk_no_check)
147 deferred_access_no_check++;
150 deferred_access *ptr;
152 ptr = VEC_safe_push (deferred_access, gc, deferred_access_stack, NULL);
153 ptr->deferred_access_checks = NULL;
154 ptr->deferring_access_checks_kind = deferring;
158 /* Resume deferring access checks again after we stopped doing
162 resume_deferring_access_checks (void)
164 if (!deferred_access_no_check)
165 VEC_last (deferred_access, deferred_access_stack)
166 ->deferring_access_checks_kind = dk_deferred;
169 /* Stop deferring access checks. */
172 stop_deferring_access_checks (void)
174 if (!deferred_access_no_check)
175 VEC_last (deferred_access, deferred_access_stack)
176 ->deferring_access_checks_kind = dk_no_deferred;
179 /* Discard the current deferred access checks and restore the
183 pop_deferring_access_checks (void)
185 if (deferred_access_no_check)
186 deferred_access_no_check--;
188 VEC_pop (deferred_access, deferred_access_stack);
191 /* Returns a TREE_LIST representing the deferred checks.
192 The TREE_PURPOSE of each node is the type through which the
193 access occurred; the TREE_VALUE is the declaration named.
196 VEC (deferred_access_check,gc)*
197 get_deferred_access_checks (void)
199 if (deferred_access_no_check)
202 return (VEC_last (deferred_access, deferred_access_stack)
203 ->deferred_access_checks);
206 /* Take current deferred checks and combine with the
207 previous states if we also defer checks previously.
208 Otherwise perform checks now. */
211 pop_to_parent_deferring_access_checks (void)
213 if (deferred_access_no_check)
214 deferred_access_no_check--;
217 VEC (deferred_access_check,gc) *checks;
218 deferred_access *ptr;
220 checks = (VEC_last (deferred_access, deferred_access_stack)
221 ->deferred_access_checks);
223 VEC_pop (deferred_access, deferred_access_stack);
224 ptr = VEC_last (deferred_access, deferred_access_stack);
225 if (ptr->deferring_access_checks_kind == dk_no_deferred)
228 perform_access_checks (checks);
232 /* Merge with parent. */
234 deferred_access_check *chk, *probe;
236 FOR_EACH_VEC_ELT (deferred_access_check, checks, i, chk)
238 FOR_EACH_VEC_ELT (deferred_access_check,
239 ptr->deferred_access_checks, j, probe)
241 if (probe->binfo == chk->binfo &&
242 probe->decl == chk->decl &&
243 probe->diag_decl == chk->diag_decl)
246 /* Insert into parent's checks. */
247 VEC_safe_push (deferred_access_check, gc,
248 ptr->deferred_access_checks, chk);
255 /* Perform the access checks in CHECKS. The TREE_PURPOSE of each node
256 is the BINFO indicating the qualifying scope used to access the
257 DECL node stored in the TREE_VALUE of the node. */
260 perform_access_checks (VEC (deferred_access_check,gc)* checks)
263 deferred_access_check *chk;
268 FOR_EACH_VEC_ELT (deferred_access_check, checks, i, chk)
269 enforce_access (chk->binfo, chk->decl, chk->diag_decl);
272 /* Perform the deferred access checks.
274 After performing the checks, we still have to keep the list
275 `deferred_access_stack->deferred_access_checks' since we may want
276 to check access for them again later in a different context.
283 A::X A::a, x; // No error for `A::a', error for `x'
285 We have to perform deferred access of `A::X', first with `A::a',
289 perform_deferred_access_checks (void)
291 perform_access_checks (get_deferred_access_checks ());
294 /* Defer checking the accessibility of DECL, when looked up in
295 BINFO. DIAG_DECL is the declaration to use to print diagnostics. */
298 perform_or_defer_access_check (tree binfo, tree decl, tree diag_decl)
301 deferred_access *ptr;
302 deferred_access_check *chk;
303 deferred_access_check *new_access;
306 /* Exit if we are in a context that no access checking is performed.
308 if (deferred_access_no_check)
311 gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
313 ptr = VEC_last (deferred_access, deferred_access_stack);
315 /* If we are not supposed to defer access checks, just check now. */
316 if (ptr->deferring_access_checks_kind == dk_no_deferred)
318 enforce_access (binfo, decl, diag_decl);
322 /* See if we are already going to perform this check. */
323 FOR_EACH_VEC_ELT (deferred_access_check,
324 ptr->deferred_access_checks, i, chk)
326 if (chk->decl == decl && chk->binfo == binfo &&
327 chk->diag_decl == diag_decl)
332 /* If not, record the check. */
334 VEC_safe_push (deferred_access_check, gc,
335 ptr->deferred_access_checks, 0);
336 new_access->binfo = binfo;
337 new_access->decl = decl;
338 new_access->diag_decl = diag_decl;
341 /* Used by build_over_call in LOOKUP_SPECULATIVE mode: return whether DECL
342 is accessible in BINFO, and possibly complain if not. If we're not
343 checking access, everything is accessible. */
346 speculative_access_check (tree binfo, tree decl, tree diag_decl,
349 if (deferred_access_no_check)
352 /* If we're checking for implicit delete, we don't want access
354 if (!accessible_p (binfo, decl, true))
356 /* Unless we're under maybe_explain_implicit_delete. */
358 enforce_access (binfo, decl, diag_decl);
365 /* Returns nonzero if the current statement is a full expression,
366 i.e. temporaries created during that statement should be destroyed
367 at the end of the statement. */
370 stmts_are_full_exprs_p (void)
372 return current_stmt_tree ()->stmts_are_full_exprs_p;
375 /* T is a statement. Add it to the statement-tree. This is the C++
376 version. The C/ObjC frontends have a slightly different version of
382 enum tree_code code = TREE_CODE (t);
384 if (EXPR_P (t) && code != LABEL_EXPR)
386 if (!EXPR_HAS_LOCATION (t))
387 SET_EXPR_LOCATION (t, input_location);
389 /* When we expand a statement-tree, we must know whether or not the
390 statements are full-expressions. We record that fact here. */
391 STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p ();
394 /* Add T to the statement-tree. Non-side-effect statements need to be
395 recorded during statement expressions. */
396 append_to_statement_list_force (t, &cur_stmt_list);
401 /* Returns the stmt_tree to which statements are currently being added. */
404 current_stmt_tree (void)
407 ? &cfun->language->base.x_stmt_tree
408 : &scope_chain->x_stmt_tree);
411 /* If statements are full expressions, wrap STMT in a CLEANUP_POINT_EXPR. */
414 maybe_cleanup_point_expr (tree expr)
416 if (!processing_template_decl && stmts_are_full_exprs_p ())
417 expr = fold_build_cleanup_point_expr (TREE_TYPE (expr), expr);
421 /* Like maybe_cleanup_point_expr except have the type of the new expression be
422 void so we don't need to create a temporary variable to hold the inner
423 expression. The reason why we do this is because the original type might be
424 an aggregate and we cannot create a temporary variable for that type. */
427 maybe_cleanup_point_expr_void (tree expr)
429 if (!processing_template_decl && stmts_are_full_exprs_p ())
430 expr = fold_build_cleanup_point_expr (void_type_node, expr);
436 /* Create a declaration statement for the declaration given by the DECL. */
439 add_decl_expr (tree decl)
441 tree r = build_stmt (input_location, DECL_EXPR, decl);
442 if (DECL_INITIAL (decl)
443 || (DECL_SIZE (decl) && TREE_SIDE_EFFECTS (DECL_SIZE (decl))))
444 r = maybe_cleanup_point_expr_void (r);
448 /* Finish a scope. */
451 do_poplevel (tree stmt_list)
455 if (stmts_are_full_exprs_p ())
456 block = poplevel (kept_level_p (), 1, 0);
458 stmt_list = pop_stmt_list (stmt_list);
460 if (!processing_template_decl)
462 stmt_list = c_build_bind_expr (input_location, block, stmt_list);
463 /* ??? See c_end_compound_stmt re statement expressions. */
469 /* Begin a new scope. */
472 do_pushlevel (scope_kind sk)
474 tree ret = push_stmt_list ();
475 if (stmts_are_full_exprs_p ())
476 begin_scope (sk, NULL);
480 /* Queue a cleanup. CLEANUP is an expression/statement to be executed
481 when the current scope is exited. EH_ONLY is true when this is not
482 meant to apply to normal control flow transfer. */
485 push_cleanup (tree decl, tree cleanup, bool eh_only)
487 tree stmt = build_stmt (input_location, CLEANUP_STMT, NULL, cleanup, decl);
488 CLEANUP_EH_ONLY (stmt) = eh_only;
490 CLEANUP_BODY (stmt) = push_stmt_list ();
493 /* Begin a conditional that might contain a declaration. When generating
494 normal code, we want the declaration to appear before the statement
495 containing the conditional. When generating template code, we want the
496 conditional to be rendered as the raw DECL_EXPR. */
499 begin_cond (tree *cond_p)
501 if (processing_template_decl)
502 *cond_p = push_stmt_list ();
505 /* Finish such a conditional. */
508 finish_cond (tree *cond_p, tree expr)
510 if (processing_template_decl)
512 tree cond = pop_stmt_list (*cond_p);
513 if (TREE_CODE (cond) == DECL_EXPR)
516 if (check_for_bare_parameter_packs (expr))
517 *cond_p = error_mark_node;
522 /* If *COND_P specifies a conditional with a declaration, transform the
525 for (; A x = 42;) { }
527 while (true) { A x = 42; if (!x) break; }
528 for (;;) { A x = 42; if (!x) break; }
529 The statement list for BODY will be empty if the conditional did
530 not declare anything. */
533 simplify_loop_decl_cond (tree *cond_p, tree body)
537 if (!TREE_SIDE_EFFECTS (body))
541 *cond_p = boolean_true_node;
543 if_stmt = begin_if_stmt ();
544 cond = cp_build_unary_op (TRUTH_NOT_EXPR, cond, 0, tf_warning_or_error);
545 finish_if_stmt_cond (cond, if_stmt);
546 finish_break_stmt ();
547 finish_then_clause (if_stmt);
548 finish_if_stmt (if_stmt);
551 /* Finish a goto-statement. */
554 finish_goto_stmt (tree destination)
556 if (TREE_CODE (destination) == IDENTIFIER_NODE)
557 destination = lookup_label (destination);
559 /* We warn about unused labels with -Wunused. That means we have to
560 mark the used labels as used. */
561 if (TREE_CODE (destination) == LABEL_DECL)
562 TREE_USED (destination) = 1;
565 destination = mark_rvalue_use (destination);
566 if (!processing_template_decl)
568 destination = cp_convert (ptr_type_node, destination);
569 if (error_operand_p (destination))
574 check_goto (destination);
576 return add_stmt (build_stmt (input_location, GOTO_EXPR, destination));
579 /* COND is the condition-expression for an if, while, etc.,
580 statement. Convert it to a boolean value, if appropriate.
581 In addition, verify sequence points if -Wsequence-point is enabled. */
584 maybe_convert_cond (tree cond)
586 /* Empty conditions remain empty. */
590 /* Wait until we instantiate templates before doing conversion. */
591 if (processing_template_decl)
594 if (warn_sequence_point)
595 verify_sequence_points (cond);
597 /* Do the conversion. */
598 cond = convert_from_reference (cond);
600 if (TREE_CODE (cond) == MODIFY_EXPR
601 && !TREE_NO_WARNING (cond)
604 warning (OPT_Wparentheses,
605 "suggest parentheses around assignment used as truth value");
606 TREE_NO_WARNING (cond) = 1;
609 return condition_conversion (cond);
612 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
615 finish_expr_stmt (tree expr)
619 if (expr != NULL_TREE)
621 if (!processing_template_decl)
623 if (warn_sequence_point)
624 verify_sequence_points (expr);
625 expr = convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
627 else if (!type_dependent_expression_p (expr))
628 convert_to_void (build_non_dependent_expr (expr), ICV_STATEMENT,
629 tf_warning_or_error);
631 if (check_for_bare_parameter_packs (expr))
632 expr = error_mark_node;
634 /* Simplification of inner statement expressions, compound exprs,
635 etc can result in us already having an EXPR_STMT. */
636 if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
638 if (TREE_CODE (expr) != EXPR_STMT)
639 expr = build_stmt (input_location, EXPR_STMT, expr);
640 expr = maybe_cleanup_point_expr_void (expr);
652 /* Begin an if-statement. Returns a newly created IF_STMT if
659 scope = do_pushlevel (sk_block);
660 r = build_stmt (input_location, IF_STMT, NULL_TREE,
661 NULL_TREE, NULL_TREE, scope);
662 begin_cond (&IF_COND (r));
666 /* Process the COND of an if-statement, which may be given by
670 finish_if_stmt_cond (tree cond, tree if_stmt)
672 finish_cond (&IF_COND (if_stmt), maybe_convert_cond (cond));
674 THEN_CLAUSE (if_stmt) = push_stmt_list ();
677 /* Finish the then-clause of an if-statement, which may be given by
681 finish_then_clause (tree if_stmt)
683 THEN_CLAUSE (if_stmt) = pop_stmt_list (THEN_CLAUSE (if_stmt));
687 /* Begin the else-clause of an if-statement. */
690 begin_else_clause (tree if_stmt)
692 ELSE_CLAUSE (if_stmt) = push_stmt_list ();
695 /* Finish the else-clause of an if-statement, which may be given by
699 finish_else_clause (tree if_stmt)
701 ELSE_CLAUSE (if_stmt) = pop_stmt_list (ELSE_CLAUSE (if_stmt));
704 /* Finish an if-statement. */
707 finish_if_stmt (tree if_stmt)
709 tree scope = IF_SCOPE (if_stmt);
710 IF_SCOPE (if_stmt) = NULL;
711 add_stmt (do_poplevel (scope));
715 /* Begin a while-statement. Returns a newly created WHILE_STMT if
719 begin_while_stmt (void)
722 r = build_stmt (input_location, WHILE_STMT, NULL_TREE, NULL_TREE);
724 WHILE_BODY (r) = do_pushlevel (sk_block);
725 begin_cond (&WHILE_COND (r));
729 /* Process the COND of a while-statement, which may be given by
733 finish_while_stmt_cond (tree cond, tree while_stmt)
735 finish_cond (&WHILE_COND (while_stmt), maybe_convert_cond (cond));
736 simplify_loop_decl_cond (&WHILE_COND (while_stmt), WHILE_BODY (while_stmt));
739 /* Finish a while-statement, which may be given by WHILE_STMT. */
742 finish_while_stmt (tree while_stmt)
744 WHILE_BODY (while_stmt) = do_poplevel (WHILE_BODY (while_stmt));
748 /* Begin a do-statement. Returns a newly created DO_STMT if
754 tree r = build_stmt (input_location, DO_STMT, NULL_TREE, NULL_TREE);
756 DO_BODY (r) = push_stmt_list ();
760 /* Finish the body of a do-statement, which may be given by DO_STMT. */
763 finish_do_body (tree do_stmt)
765 tree body = DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt));
767 if (TREE_CODE (body) == STATEMENT_LIST && STATEMENT_LIST_TAIL (body))
768 body = STATEMENT_LIST_TAIL (body)->stmt;
770 if (IS_EMPTY_STMT (body))
771 warning (OPT_Wempty_body,
772 "suggest explicit braces around empty body in %<do%> statement");
775 /* Finish a do-statement, which may be given by DO_STMT, and whose
776 COND is as indicated. */
779 finish_do_stmt (tree cond, tree do_stmt)
781 cond = maybe_convert_cond (cond);
782 DO_COND (do_stmt) = cond;
786 /* Finish a return-statement. The EXPRESSION returned, if any, is as
790 finish_return_stmt (tree expr)
795 expr = check_return_expr (expr, &no_warning);
797 if (flag_openmp && !check_omp_return ())
798 return error_mark_node;
799 if (!processing_template_decl)
801 if (warn_sequence_point)
802 verify_sequence_points (expr);
804 if (DECL_DESTRUCTOR_P (current_function_decl)
805 || (DECL_CONSTRUCTOR_P (current_function_decl)
806 && targetm.cxx.cdtor_returns_this ()))
808 /* Similarly, all destructors must run destructors for
809 base-classes before returning. So, all returns in a
810 destructor get sent to the DTOR_LABEL; finish_function emits
811 code to return a value there. */
812 return finish_goto_stmt (cdtor_label);
816 r = build_stmt (input_location, RETURN_EXPR, expr);
817 TREE_NO_WARNING (r) |= no_warning;
818 r = maybe_cleanup_point_expr_void (r);
825 /* Begin the scope of a for-statement or a range-for-statement.
826 Both the returned trees are to be used in a call to
827 begin_for_stmt or begin_range_for_stmt. */
830 begin_for_scope (tree *init)
832 tree scope = NULL_TREE;
833 if (flag_new_for_scope > 0)
834 scope = do_pushlevel (sk_for);
836 if (processing_template_decl)
837 *init = push_stmt_list ();
844 /* Begin a for-statement. Returns a new FOR_STMT.
845 SCOPE and INIT should be the return of begin_for_scope,
849 begin_for_stmt (tree scope, tree init)
853 r = build_stmt (input_location, FOR_STMT, NULL_TREE, NULL_TREE,
854 NULL_TREE, NULL_TREE, NULL_TREE);
856 if (scope == NULL_TREE)
858 gcc_assert (!init || !(flag_new_for_scope > 0));
860 scope = begin_for_scope (&init);
862 FOR_INIT_STMT (r) = init;
863 FOR_SCOPE (r) = scope;
868 /* Finish the for-init-statement of a for-statement, which may be
869 given by FOR_STMT. */
872 finish_for_init_stmt (tree for_stmt)
874 if (processing_template_decl)
875 FOR_INIT_STMT (for_stmt) = pop_stmt_list (FOR_INIT_STMT (for_stmt));
877 FOR_BODY (for_stmt) = do_pushlevel (sk_block);
878 begin_cond (&FOR_COND (for_stmt));
881 /* Finish the COND of a for-statement, which may be given by
885 finish_for_cond (tree cond, tree for_stmt)
887 finish_cond (&FOR_COND (for_stmt), maybe_convert_cond (cond));
888 simplify_loop_decl_cond (&FOR_COND (for_stmt), FOR_BODY (for_stmt));
891 /* Finish the increment-EXPRESSION in a for-statement, which may be
892 given by FOR_STMT. */
895 finish_for_expr (tree expr, tree for_stmt)
899 /* If EXPR is an overloaded function, issue an error; there is no
900 context available to use to perform overload resolution. */
901 if (type_unknown_p (expr))
903 cxx_incomplete_type_error (expr, TREE_TYPE (expr));
904 expr = error_mark_node;
906 if (!processing_template_decl)
908 if (warn_sequence_point)
909 verify_sequence_points (expr);
910 expr = convert_to_void (expr, ICV_THIRD_IN_FOR,
911 tf_warning_or_error);
913 else if (!type_dependent_expression_p (expr))
914 convert_to_void (build_non_dependent_expr (expr), ICV_THIRD_IN_FOR,
915 tf_warning_or_error);
916 expr = maybe_cleanup_point_expr_void (expr);
917 if (check_for_bare_parameter_packs (expr))
918 expr = error_mark_node;
919 FOR_EXPR (for_stmt) = expr;
922 /* Finish the body of a for-statement, which may be given by
923 FOR_STMT. The increment-EXPR for the loop must be
925 It can also finish RANGE_FOR_STMT. */
928 finish_for_stmt (tree for_stmt)
930 if (TREE_CODE (for_stmt) == RANGE_FOR_STMT)
931 RANGE_FOR_BODY (for_stmt) = do_poplevel (RANGE_FOR_BODY (for_stmt));
933 FOR_BODY (for_stmt) = do_poplevel (FOR_BODY (for_stmt));
935 /* Pop the scope for the body of the loop. */
936 if (flag_new_for_scope > 0)
939 tree *scope_ptr = (TREE_CODE (for_stmt) == RANGE_FOR_STMT
940 ? &RANGE_FOR_SCOPE (for_stmt)
941 : &FOR_SCOPE (for_stmt));
944 add_stmt (do_poplevel (scope));
950 /* Begin a range-for-statement. Returns a new RANGE_FOR_STMT.
951 SCOPE and INIT should be the return of begin_for_scope,
953 To finish it call finish_for_stmt(). */
956 begin_range_for_stmt (tree scope, tree init)
960 r = build_stmt (input_location, RANGE_FOR_STMT,
961 NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE);
963 if (scope == NULL_TREE)
965 gcc_assert (!init || !(flag_new_for_scope > 0));
967 scope = begin_for_scope (&init);
970 /* RANGE_FOR_STMTs do not use nor save the init tree, so we
973 pop_stmt_list (init);
974 RANGE_FOR_SCOPE (r) = scope;
979 /* Finish the head of a range-based for statement, which may
980 be given by RANGE_FOR_STMT. DECL must be the declaration
981 and EXPR must be the loop expression. */
984 finish_range_for_decl (tree range_for_stmt, tree decl, tree expr)
986 RANGE_FOR_DECL (range_for_stmt) = decl;
987 RANGE_FOR_EXPR (range_for_stmt) = expr;
988 add_stmt (range_for_stmt);
989 RANGE_FOR_BODY (range_for_stmt) = do_pushlevel (sk_block);
992 /* Finish a break-statement. */
995 finish_break_stmt (void)
997 return add_stmt (build_stmt (input_location, BREAK_STMT));
1000 /* Finish a continue-statement. */
1003 finish_continue_stmt (void)
1005 return add_stmt (build_stmt (input_location, CONTINUE_STMT));
1008 /* Begin a switch-statement. Returns a new SWITCH_STMT if
1012 begin_switch_stmt (void)
1016 scope = do_pushlevel (sk_block);
1017 r = build_stmt (input_location, SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE, scope);
1019 begin_cond (&SWITCH_STMT_COND (r));
1024 /* Finish the cond of a switch-statement. */
1027 finish_switch_cond (tree cond, tree switch_stmt)
1029 tree orig_type = NULL;
1030 if (!processing_template_decl)
1032 /* Convert the condition to an integer or enumeration type. */
1033 cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true);
1034 if (cond == NULL_TREE)
1036 error ("switch quantity not an integer");
1037 cond = error_mark_node;
1039 orig_type = TREE_TYPE (cond);
1040 if (cond != error_mark_node)
1044 Integral promotions are performed. */
1045 cond = perform_integral_promotions (cond);
1046 cond = maybe_cleanup_point_expr (cond);
1049 if (check_for_bare_parameter_packs (cond))
1050 cond = error_mark_node;
1051 else if (!processing_template_decl && warn_sequence_point)
1052 verify_sequence_points (cond);
1054 finish_cond (&SWITCH_STMT_COND (switch_stmt), cond);
1055 SWITCH_STMT_TYPE (switch_stmt) = orig_type;
1056 add_stmt (switch_stmt);
1057 push_switch (switch_stmt);
1058 SWITCH_STMT_BODY (switch_stmt) = push_stmt_list ();
1061 /* Finish the body of a switch-statement, which may be given by
1062 SWITCH_STMT. The COND to switch on is indicated. */
1065 finish_switch_stmt (tree switch_stmt)
1069 SWITCH_STMT_BODY (switch_stmt) =
1070 pop_stmt_list (SWITCH_STMT_BODY (switch_stmt));
1074 scope = SWITCH_STMT_SCOPE (switch_stmt);
1075 SWITCH_STMT_SCOPE (switch_stmt) = NULL;
1076 add_stmt (do_poplevel (scope));
1079 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
1083 begin_try_block (void)
1085 tree r = build_stmt (input_location, TRY_BLOCK, NULL_TREE, NULL_TREE);
1087 TRY_STMTS (r) = push_stmt_list ();
1091 /* Likewise, for a function-try-block. The block returned in
1092 *COMPOUND_STMT is an artificial outer scope, containing the
1093 function-try-block. */
1096 begin_function_try_block (tree *compound_stmt)
1099 /* This outer scope does not exist in the C++ standard, but we need
1100 a place to put __FUNCTION__ and similar variables. */
1101 *compound_stmt = begin_compound_stmt (0);
1102 r = begin_try_block ();
1103 FN_TRY_BLOCK_P (r) = 1;
1107 /* Finish a try-block, which may be given by TRY_BLOCK. */
1110 finish_try_block (tree try_block)
1112 TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
1113 TRY_HANDLERS (try_block) = push_stmt_list ();
1116 /* Finish the body of a cleanup try-block, which may be given by
1120 finish_cleanup_try_block (tree try_block)
1122 TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
1125 /* Finish an implicitly generated try-block, with a cleanup is given
1129 finish_cleanup (tree cleanup, tree try_block)
1131 TRY_HANDLERS (try_block) = cleanup;
1132 CLEANUP_P (try_block) = 1;
1135 /* Likewise, for a function-try-block. */
1138 finish_function_try_block (tree try_block)
1140 finish_try_block (try_block);
1141 /* FIXME : something queer about CTOR_INITIALIZER somehow following
1142 the try block, but moving it inside. */
1143 in_function_try_handler = 1;
1146 /* Finish a handler-sequence for a try-block, which may be given by
1150 finish_handler_sequence (tree try_block)
1152 TRY_HANDLERS (try_block) = pop_stmt_list (TRY_HANDLERS (try_block));
1153 check_handlers (TRY_HANDLERS (try_block));
1156 /* Finish the handler-seq for a function-try-block, given by
1157 TRY_BLOCK. COMPOUND_STMT is the outer block created by
1158 begin_function_try_block. */
1161 finish_function_handler_sequence (tree try_block, tree compound_stmt)
1163 in_function_try_handler = 0;
1164 finish_handler_sequence (try_block);
1165 finish_compound_stmt (compound_stmt);
1168 /* Begin a handler. Returns a HANDLER if appropriate. */
1171 begin_handler (void)
1175 r = build_stmt (input_location, HANDLER, NULL_TREE, NULL_TREE);
1178 /* Create a binding level for the eh_info and the exception object
1180 HANDLER_BODY (r) = do_pushlevel (sk_catch);
1185 /* Finish the handler-parameters for a handler, which may be given by
1186 HANDLER. DECL is the declaration for the catch parameter, or NULL
1187 if this is a `catch (...)' clause. */
1190 finish_handler_parms (tree decl, tree handler)
1192 tree type = NULL_TREE;
1193 if (processing_template_decl)
1197 decl = pushdecl (decl);
1198 decl = push_template_decl (decl);
1199 HANDLER_PARMS (handler) = decl;
1200 type = TREE_TYPE (decl);
1204 type = expand_start_catch_block (decl);
1205 HANDLER_TYPE (handler) = type;
1206 if (!processing_template_decl && type)
1207 mark_used (eh_type_info (type));
1210 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
1211 the return value from the matching call to finish_handler_parms. */
1214 finish_handler (tree handler)
1216 if (!processing_template_decl)
1217 expand_end_catch_block ();
1218 HANDLER_BODY (handler) = do_poplevel (HANDLER_BODY (handler));
1221 /* Begin a compound statement. FLAGS contains some bits that control the
1222 behavior and context. If BCS_NO_SCOPE is set, the compound statement
1223 does not define a scope. If BCS_FN_BODY is set, this is the outermost
1224 block of a function. If BCS_TRY_BLOCK is set, this is the block
1225 created on behalf of a TRY statement. Returns a token to be passed to
1226 finish_compound_stmt. */
1229 begin_compound_stmt (unsigned int flags)
1233 if (flags & BCS_NO_SCOPE)
1235 r = push_stmt_list ();
1236 STATEMENT_LIST_NO_SCOPE (r) = 1;
1238 /* Normally, we try hard to keep the BLOCK for a statement-expression.
1239 But, if it's a statement-expression with a scopeless block, there's
1240 nothing to keep, and we don't want to accidentally keep a block
1241 *inside* the scopeless block. */
1242 keep_next_level (false);
1245 r = do_pushlevel (flags & BCS_TRY_BLOCK ? sk_try : sk_block);
1247 /* When processing a template, we need to remember where the braces were,
1248 so that we can set up identical scopes when instantiating the template
1249 later. BIND_EXPR is a handy candidate for this.
1250 Note that do_poplevel won't create a BIND_EXPR itself here (and thus
1251 result in nested BIND_EXPRs), since we don't build BLOCK nodes when
1252 processing templates. */
1253 if (processing_template_decl)
1255 r = build3 (BIND_EXPR, NULL, NULL, r, NULL);
1256 BIND_EXPR_TRY_BLOCK (r) = (flags & BCS_TRY_BLOCK) != 0;
1257 BIND_EXPR_BODY_BLOCK (r) = (flags & BCS_FN_BODY) != 0;
1258 TREE_SIDE_EFFECTS (r) = 1;
1264 /* Finish a compound-statement, which is given by STMT. */
1267 finish_compound_stmt (tree stmt)
1269 if (TREE_CODE (stmt) == BIND_EXPR)
1271 tree body = do_poplevel (BIND_EXPR_BODY (stmt));
1272 /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special,
1273 discard the BIND_EXPR so it can be merged with the containing
1275 if (TREE_CODE (body) == STATEMENT_LIST
1276 && STATEMENT_LIST_HEAD (body) == NULL
1277 && !BIND_EXPR_BODY_BLOCK (stmt)
1278 && !BIND_EXPR_TRY_BLOCK (stmt))
1281 BIND_EXPR_BODY (stmt) = body;
1283 else if (STATEMENT_LIST_NO_SCOPE (stmt))
1284 stmt = pop_stmt_list (stmt);
1287 /* Destroy any ObjC "super" receivers that may have been
1289 objc_clear_super_receiver ();
1291 stmt = do_poplevel (stmt);
1294 /* ??? See c_end_compound_stmt wrt statement expressions. */
1299 /* Finish an asm-statement, whose components are a STRING, some
1300 OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some
1301 LABELS. Also note whether the asm-statement should be
1302 considered volatile. */
1305 finish_asm_stmt (int volatile_p, tree string, tree output_operands,
1306 tree input_operands, tree clobbers, tree labels)
1310 int ninputs = list_length (input_operands);
1311 int noutputs = list_length (output_operands);
1313 if (!processing_template_decl)
1315 const char *constraint;
1316 const char **oconstraints;
1317 bool allows_mem, allows_reg, is_inout;
1321 oconstraints = XALLOCAVEC (const char *, noutputs);
1323 string = resolve_asm_operand_names (string, output_operands,
1324 input_operands, labels);
1326 for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i)
1328 operand = TREE_VALUE (t);
1330 /* ??? Really, this should not be here. Users should be using a
1331 proper lvalue, dammit. But there's a long history of using
1332 casts in the output operands. In cases like longlong.h, this
1333 becomes a primitive form of typechecking -- if the cast can be
1334 removed, then the output operand had a type of the proper width;
1335 otherwise we'll get an error. Gross, but ... */
1336 STRIP_NOPS (operand);
1338 operand = mark_lvalue_use (operand);
1340 if (!lvalue_or_else (operand, lv_asm, tf_warning_or_error))
1341 operand = error_mark_node;
1343 if (operand != error_mark_node
1344 && (TREE_READONLY (operand)
1345 || CP_TYPE_CONST_P (TREE_TYPE (operand))
1346 /* Functions are not modifiable, even though they are
1348 || TREE_CODE (TREE_TYPE (operand)) == FUNCTION_TYPE
1349 || TREE_CODE (TREE_TYPE (operand)) == METHOD_TYPE
1350 /* If it's an aggregate and any field is const, then it is
1351 effectively const. */
1352 || (CLASS_TYPE_P (TREE_TYPE (operand))
1353 && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand)))))
1354 cxx_readonly_error (operand, lv_asm);
1356 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
1357 oconstraints[i] = constraint;
1359 if (parse_output_constraint (&constraint, i, ninputs, noutputs,
1360 &allows_mem, &allows_reg, &is_inout))
1362 /* If the operand is going to end up in memory,
1363 mark it addressable. */
1364 if (!allows_reg && !cxx_mark_addressable (operand))
1365 operand = error_mark_node;
1368 operand = error_mark_node;
1370 TREE_VALUE (t) = operand;
1373 for (i = 0, t = input_operands; t; ++i, t = TREE_CHAIN (t))
1375 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
1376 operand = decay_conversion (TREE_VALUE (t));
1378 /* If the type of the operand hasn't been determined (e.g.,
1379 because it involves an overloaded function), then issue
1380 an error message. There's no context available to
1381 resolve the overloading. */
1382 if (TREE_TYPE (operand) == unknown_type_node)
1384 error ("type of asm operand %qE could not be determined",
1386 operand = error_mark_node;
1389 if (parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
1390 oconstraints, &allows_mem, &allows_reg))
1392 /* If the operand is going to end up in memory,
1393 mark it addressable. */
1394 if (!allows_reg && allows_mem)
1396 /* Strip the nops as we allow this case. FIXME, this really
1397 should be rejected or made deprecated. */
1398 STRIP_NOPS (operand);
1399 if (!cxx_mark_addressable (operand))
1400 operand = error_mark_node;
1404 operand = error_mark_node;
1406 TREE_VALUE (t) = operand;
1410 r = build_stmt (input_location, ASM_EXPR, string,
1411 output_operands, input_operands,
1413 ASM_VOLATILE_P (r) = volatile_p || noutputs == 0;
1414 r = maybe_cleanup_point_expr_void (r);
1415 return add_stmt (r);
1418 /* Finish a label with the indicated NAME. Returns the new label. */
1421 finish_label_stmt (tree name)
1423 tree decl = define_label (input_location, name);
1425 if (decl == error_mark_node)
1426 return error_mark_node;
1428 add_stmt (build_stmt (input_location, LABEL_EXPR, decl));
1433 /* Finish a series of declarations for local labels. G++ allows users
1434 to declare "local" labels, i.e., labels with scope. This extension
1435 is useful when writing code involving statement-expressions. */
1438 finish_label_decl (tree name)
1440 if (!at_function_scope_p ())
1442 error ("__label__ declarations are only allowed in function scopes");
1446 add_decl_expr (declare_local_label (name));
1449 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1452 finish_decl_cleanup (tree decl, tree cleanup)
1454 push_cleanup (decl, cleanup, false);
1457 /* If the current scope exits with an exception, run CLEANUP. */
1460 finish_eh_cleanup (tree cleanup)
1462 push_cleanup (NULL, cleanup, true);
1465 /* The MEM_INITS is a list of mem-initializers, in reverse of the
1466 order they were written by the user. Each node is as for
1467 emit_mem_initializers. */
1470 finish_mem_initializers (tree mem_inits)
1472 /* Reorder the MEM_INITS so that they are in the order they appeared
1473 in the source program. */
1474 mem_inits = nreverse (mem_inits);
1476 if (processing_template_decl)
1480 for (mem = mem_inits; mem; mem = TREE_CHAIN (mem))
1482 /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the
1483 check for bare parameter packs in the TREE_VALUE, because
1484 any parameter packs in the TREE_VALUE have already been
1485 bound as part of the TREE_PURPOSE. See
1486 make_pack_expansion for more information. */
1487 if (TREE_CODE (TREE_PURPOSE (mem)) != TYPE_PACK_EXPANSION
1488 && check_for_bare_parameter_packs (TREE_VALUE (mem)))
1489 TREE_VALUE (mem) = error_mark_node;
1492 add_stmt (build_min_nt (CTOR_INITIALIZER, mem_inits));
1495 emit_mem_initializers (mem_inits);
1498 /* Finish a parenthesized expression EXPR. */
1501 finish_parenthesized_expr (tree expr)
1504 /* This inhibits warnings in c_common_truthvalue_conversion. */
1505 TREE_NO_WARNING (expr) = 1;
1507 if (TREE_CODE (expr) == OFFSET_REF)
1508 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
1509 enclosed in parentheses. */
1510 PTRMEM_OK_P (expr) = 0;
1512 if (TREE_CODE (expr) == STRING_CST)
1513 PAREN_STRING_LITERAL_P (expr) = 1;
1518 /* Finish a reference to a non-static data member (DECL) that is not
1519 preceded by `.' or `->'. */
1522 finish_non_static_data_member (tree decl, tree object, tree qualifying_scope)
1524 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
1528 tree scope = qualifying_scope;
1529 if (scope == NULL_TREE)
1530 scope = context_for_name_lookup (decl);
1531 object = maybe_dummy_object (scope, NULL);
1534 if (object == error_mark_node)
1535 return error_mark_node;
1537 /* DR 613: Can use non-static data members without an associated
1538 object in sizeof/decltype/alignof. */
1539 if (is_dummy_object (object) && cp_unevaluated_operand == 0
1540 && (!processing_template_decl || !current_class_ref))
1542 if (current_function_decl
1543 && DECL_STATIC_FUNCTION_P (current_function_decl))
1544 error ("invalid use of member %q+D in static member function", decl);
1546 error ("invalid use of non-static data member %q+D", decl);
1547 error ("from this location");
1549 return error_mark_node;
1552 if (current_class_ptr)
1553 TREE_USED (current_class_ptr) = 1;
1554 if (processing_template_decl && !qualifying_scope)
1556 tree type = TREE_TYPE (decl);
1558 if (TREE_CODE (type) == REFERENCE_TYPE)
1559 type = TREE_TYPE (type);
1562 /* Set the cv qualifiers. */
1563 int quals = (current_class_ref
1564 ? cp_type_quals (TREE_TYPE (current_class_ref))
1565 : TYPE_UNQUALIFIED);
1567 if (DECL_MUTABLE_P (decl))
1568 quals &= ~TYPE_QUAL_CONST;
1570 quals |= cp_type_quals (TREE_TYPE (decl));
1571 type = cp_build_qualified_type (type, quals);
1574 return build_min (COMPONENT_REF, type, object, decl, NULL_TREE);
1576 /* If PROCESSING_TEMPLATE_DECL is nonzero here, then
1577 QUALIFYING_SCOPE is also non-null. Wrap this in a SCOPE_REF
1579 else if (processing_template_decl)
1580 return build_qualified_name (TREE_TYPE (decl),
1583 /*template_p=*/false);
1586 tree access_type = TREE_TYPE (object);
1588 perform_or_defer_access_check (TYPE_BINFO (access_type), decl,
1591 /* If the data member was named `C::M', convert `*this' to `C'
1593 if (qualifying_scope)
1595 tree binfo = NULL_TREE;
1596 object = build_scoped_ref (object, qualifying_scope,
1600 return build_class_member_access_expr (object, decl,
1601 /*access_path=*/NULL_TREE,
1602 /*preserve_reference=*/false,
1603 tf_warning_or_error);
1607 /* If we are currently parsing a template and we encountered a typedef
1608 TYPEDEF_DECL that is being accessed though CONTEXT, this function
1609 adds the typedef to a list tied to the current template.
1610 At tempate instantiatin time, that list is walked and access check
1611 performed for each typedef.
1612 LOCATION is the location of the usage point of TYPEDEF_DECL. */
1615 add_typedef_to_current_template_for_access_check (tree typedef_decl,
1617 location_t location)
1619 tree template_info = NULL;
1620 tree cs = current_scope ();
1622 if (!is_typedef_decl (typedef_decl)
1624 || !CLASS_TYPE_P (context)
1628 if (CLASS_TYPE_P (cs) || TREE_CODE (cs) == FUNCTION_DECL)
1629 template_info = get_template_info (cs);
1632 && TI_TEMPLATE (template_info)
1633 && !currently_open_class (context))
1634 append_type_to_template_for_access_check (cs, typedef_decl,
1638 /* DECL was the declaration to which a qualified-id resolved. Issue
1639 an error message if it is not accessible. If OBJECT_TYPE is
1640 non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the
1641 type of `*x', or `x', respectively. If the DECL was named as
1642 `A::B' then NESTED_NAME_SPECIFIER is `A'. */
1645 check_accessibility_of_qualified_id (tree decl,
1647 tree nested_name_specifier)
1650 tree qualifying_type = NULL_TREE;
1652 /* If we are parsing a template declaration and if decl is a typedef,
1653 add it to a list tied to the template.
1654 At template instantiation time, that list will be walked and
1655 access check performed. */
1656 add_typedef_to_current_template_for_access_check (decl,
1657 nested_name_specifier
1658 ? nested_name_specifier
1659 : DECL_CONTEXT (decl),
1662 /* If we're not checking, return immediately. */
1663 if (deferred_access_no_check)
1666 /* Determine the SCOPE of DECL. */
1667 scope = context_for_name_lookup (decl);
1668 /* If the SCOPE is not a type, then DECL is not a member. */
1669 if (!TYPE_P (scope))
1671 /* Compute the scope through which DECL is being accessed. */
1673 /* OBJECT_TYPE might not be a class type; consider:
1675 class A { typedef int I; };
1679 In this case, we will have "A::I" as the DECL, but "I" as the
1681 && CLASS_TYPE_P (object_type)
1682 && DERIVED_FROM_P (scope, object_type))
1683 /* If we are processing a `->' or `.' expression, use the type of the
1685 qualifying_type = object_type;
1686 else if (nested_name_specifier)
1688 /* If the reference is to a non-static member of the
1689 current class, treat it as if it were referenced through
1691 if (DECL_NONSTATIC_MEMBER_P (decl)
1692 && current_class_ptr
1693 && DERIVED_FROM_P (scope, current_class_type))
1694 qualifying_type = current_class_type;
1695 /* Otherwise, use the type indicated by the
1696 nested-name-specifier. */
1698 qualifying_type = nested_name_specifier;
1701 /* Otherwise, the name must be from the current class or one of
1703 qualifying_type = currently_open_derived_class (scope);
1706 /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM
1707 or similar in a default argument value. */
1708 && CLASS_TYPE_P (qualifying_type)
1709 && !dependent_type_p (qualifying_type))
1710 perform_or_defer_access_check (TYPE_BINFO (qualifying_type), decl,
1714 /* EXPR is the result of a qualified-id. The QUALIFYING_CLASS was the
1715 class named to the left of the "::" operator. DONE is true if this
1716 expression is a complete postfix-expression; it is false if this
1717 expression is followed by '->', '[', '(', etc. ADDRESS_P is true
1718 iff this expression is the operand of '&'. TEMPLATE_P is true iff
1719 the qualified-id was of the form "A::template B". TEMPLATE_ARG_P
1720 is true iff this qualified name appears as a template argument. */
1723 finish_qualified_id_expr (tree qualifying_class,
1728 bool template_arg_p)
1730 gcc_assert (TYPE_P (qualifying_class));
1732 if (error_operand_p (expr))
1733 return error_mark_node;
1735 if (DECL_P (expr) || BASELINK_P (expr))
1739 check_template_keyword (expr);
1741 /* If EXPR occurs as the operand of '&', use special handling that
1742 permits a pointer-to-member. */
1743 if (address_p && done)
1745 if (TREE_CODE (expr) == SCOPE_REF)
1746 expr = TREE_OPERAND (expr, 1);
1747 expr = build_offset_ref (qualifying_class, expr,
1748 /*address_p=*/true);
1752 /* Within the scope of a class, turn references to non-static
1753 members into expression of the form "this->...". */
1755 /* But, within a template argument, we do not want make the
1756 transformation, as there is no "this" pointer. */
1758 else if (TREE_CODE (expr) == FIELD_DECL)
1760 push_deferring_access_checks (dk_no_check);
1761 expr = finish_non_static_data_member (expr, NULL_TREE,
1763 pop_deferring_access_checks ();
1765 else if (BASELINK_P (expr) && !processing_template_decl)
1769 /* See if any of the functions are non-static members. */
1770 /* If so, the expression may be relative to 'this'. */
1771 if (!shared_member_p (expr)
1772 && (ob = maybe_dummy_object (qualifying_class, NULL),
1773 !is_dummy_object (ob)))
1774 expr = (build_class_member_access_expr
1777 BASELINK_ACCESS_BINFO (expr),
1778 /*preserve_reference=*/false,
1779 tf_warning_or_error));
1781 /* The expression is a qualified name whose address is not
1783 expr = build_offset_ref (qualifying_class, expr, /*address_p=*/false);
1789 /* Begin a statement-expression. The value returned must be passed to
1790 finish_stmt_expr. */
1793 begin_stmt_expr (void)
1795 return push_stmt_list ();
1798 /* Process the final expression of a statement expression. EXPR can be
1799 NULL, if the final expression is empty. Return a STATEMENT_LIST
1800 containing all the statements in the statement-expression, or
1801 ERROR_MARK_NODE if there was an error. */
1804 finish_stmt_expr_expr (tree expr, tree stmt_expr)
1806 if (error_operand_p (expr))
1808 /* The type of the statement-expression is the type of the last
1810 TREE_TYPE (stmt_expr) = error_mark_node;
1811 return error_mark_node;
1814 /* If the last statement does not have "void" type, then the value
1815 of the last statement is the value of the entire expression. */
1818 tree type = TREE_TYPE (expr);
1820 if (processing_template_decl)
1822 expr = build_stmt (input_location, EXPR_STMT, expr);
1823 expr = add_stmt (expr);
1824 /* Mark the last statement so that we can recognize it as such at
1825 template-instantiation time. */
1826 EXPR_STMT_STMT_EXPR_RESULT (expr) = 1;
1828 else if (VOID_TYPE_P (type))
1830 /* Just treat this like an ordinary statement. */
1831 expr = finish_expr_stmt (expr);
1835 /* It actually has a value we need to deal with. First, force it
1836 to be an rvalue so that we won't need to build up a copy
1837 constructor call later when we try to assign it to something. */
1838 expr = force_rvalue (expr, tf_warning_or_error);
1839 if (error_operand_p (expr))
1840 return error_mark_node;
1842 /* Update for array-to-pointer decay. */
1843 type = TREE_TYPE (expr);
1845 /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a
1846 normal statement, but don't convert to void or actually add
1848 if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
1849 expr = maybe_cleanup_point_expr (expr);
1853 /* The type of the statement-expression is the type of the last
1855 TREE_TYPE (stmt_expr) = type;
1861 /* Finish a statement-expression. EXPR should be the value returned
1862 by the previous begin_stmt_expr. Returns an expression
1863 representing the statement-expression. */
1866 finish_stmt_expr (tree stmt_expr, bool has_no_scope)
1871 if (error_operand_p (stmt_expr))
1873 pop_stmt_list (stmt_expr);
1874 return error_mark_node;
1877 gcc_assert (TREE_CODE (stmt_expr) == STATEMENT_LIST);
1879 type = TREE_TYPE (stmt_expr);
1880 result = pop_stmt_list (stmt_expr);
1881 TREE_TYPE (result) = type;
1883 if (processing_template_decl)
1885 result = build_min (STMT_EXPR, type, result);
1886 TREE_SIDE_EFFECTS (result) = 1;
1887 STMT_EXPR_NO_SCOPE (result) = has_no_scope;
1889 else if (CLASS_TYPE_P (type))
1891 /* Wrap the statement-expression in a TARGET_EXPR so that the
1892 temporary object created by the final expression is destroyed at
1893 the end of the full-expression containing the
1894 statement-expression. */
1895 result = force_target_expr (type, result, tf_warning_or_error);
1901 /* Returns the expression which provides the value of STMT_EXPR. */
1904 stmt_expr_value_expr (tree stmt_expr)
1906 tree t = STMT_EXPR_STMT (stmt_expr);
1908 if (TREE_CODE (t) == BIND_EXPR)
1909 t = BIND_EXPR_BODY (t);
1911 if (TREE_CODE (t) == STATEMENT_LIST && STATEMENT_LIST_TAIL (t))
1912 t = STATEMENT_LIST_TAIL (t)->stmt;
1914 if (TREE_CODE (t) == EXPR_STMT)
1915 t = EXPR_STMT_EXPR (t);
1920 /* Return TRUE iff EXPR_STMT is an empty list of
1921 expression statements. */
1924 empty_expr_stmt_p (tree expr_stmt)
1926 tree body = NULL_TREE;
1928 if (expr_stmt == void_zero_node)
1933 if (TREE_CODE (expr_stmt) == EXPR_STMT)
1934 body = EXPR_STMT_EXPR (expr_stmt);
1935 else if (TREE_CODE (expr_stmt) == STATEMENT_LIST)
1941 if (TREE_CODE (body) == STATEMENT_LIST)
1942 return tsi_end_p (tsi_start (body));
1944 return empty_expr_stmt_p (body);
1949 /* Perform Koenig lookup. FN is the postfix-expression representing
1950 the function (or functions) to call; ARGS are the arguments to the
1951 call; if INCLUDE_STD then the `std' namespace is automatically
1952 considered an associated namespace (used in range-based for loops).
1953 Returns the functions to be considered by overload resolution. */
1956 perform_koenig_lookup (tree fn, VEC(tree,gc) *args, bool include_std)
1958 tree identifier = NULL_TREE;
1959 tree functions = NULL_TREE;
1960 tree tmpl_args = NULL_TREE;
1961 bool template_id = false;
1963 if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
1965 /* Use a separate flag to handle null args. */
1967 tmpl_args = TREE_OPERAND (fn, 1);
1968 fn = TREE_OPERAND (fn, 0);
1971 /* Find the name of the overloaded function. */
1972 if (TREE_CODE (fn) == IDENTIFIER_NODE)
1974 else if (is_overloaded_fn (fn))
1977 identifier = DECL_NAME (get_first_fn (functions));
1979 else if (DECL_P (fn))
1982 identifier = DECL_NAME (fn);
1985 /* A call to a namespace-scope function using an unqualified name.
1987 Do Koenig lookup -- unless any of the arguments are
1989 if (!any_type_dependent_arguments_p (args)
1990 && !any_dependent_template_arguments_p (tmpl_args))
1992 fn = lookup_arg_dependent (identifier, functions, args, include_std);
1994 /* The unqualified name could not be resolved. */
1995 fn = unqualified_fn_lookup_error (identifier);
1998 if (fn && template_id)
1999 fn = build2 (TEMPLATE_ID_EXPR, unknown_type_node, fn, tmpl_args);
2004 /* Generate an expression for `FN (ARGS)'. This may change the
2007 If DISALLOW_VIRTUAL is true, the call to FN will be not generated
2008 as a virtual call, even if FN is virtual. (This flag is set when
2009 encountering an expression where the function name is explicitly
2010 qualified. For example a call to `X::f' never generates a virtual
2013 Returns code for the call. */
2016 finish_call_expr (tree fn, VEC(tree,gc) **args, bool disallow_virtual,
2017 bool koenig_p, tsubst_flags_t complain)
2021 VEC(tree,gc) *orig_args = NULL;
2023 if (fn == error_mark_node)
2024 return error_mark_node;
2026 gcc_assert (!TYPE_P (fn));
2030 if (processing_template_decl)
2032 /* If the call expression is dependent, build a CALL_EXPR node
2033 with no type; type_dependent_expression_p recognizes
2034 expressions with no type as being dependent. */
2035 if (type_dependent_expression_p (fn)
2036 || any_type_dependent_arguments_p (*args)
2037 /* For a non-static member function, we need to specifically
2038 test the type dependency of the "this" pointer because it
2039 is not included in *ARGS even though it is considered to
2040 be part of the list of arguments. Note that this is
2041 related to CWG issues 515 and 1005. */
2042 || (((TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE)
2044 && current_class_ref
2045 && type_dependent_expression_p (current_class_ref)))
2047 result = build_nt_call_vec (fn, *args);
2048 KOENIG_LOOKUP_P (result) = koenig_p;
2053 tree fndecl = OVL_CURRENT (fn);
2054 if (TREE_CODE (fndecl) != FUNCTION_DECL
2055 || !TREE_THIS_VOLATILE (fndecl))
2061 current_function_returns_abnormally = 1;
2065 orig_args = make_tree_vector_copy (*args);
2066 if (!BASELINK_P (fn)
2067 && TREE_CODE (fn) != PSEUDO_DTOR_EXPR
2068 && TREE_TYPE (fn) != unknown_type_node)
2069 fn = build_non_dependent_expr (fn);
2070 make_args_non_dependent (*args);
2073 if (TREE_CODE (fn) == COMPONENT_REF)
2075 tree member = TREE_OPERAND (fn, 1);
2076 if (BASELINK_P (member))
2078 tree object = TREE_OPERAND (fn, 0);
2079 return build_new_method_call (object, member,
2082 ? LOOKUP_NORMAL | LOOKUP_NONVIRTUAL
2089 if (is_overloaded_fn (fn))
2090 fn = baselink_for_fns (fn);
2093 if (BASELINK_P (fn))
2097 /* A call to a member function. From [over.call.func]:
2099 If the keyword this is in scope and refers to the class of
2100 that member function, or a derived class thereof, then the
2101 function call is transformed into a qualified function call
2102 using (*this) as the postfix-expression to the left of the
2103 . operator.... [Otherwise] a contrived object of type T
2104 becomes the implied object argument.
2108 struct A { void f(); };
2109 struct B : public A {};
2110 struct C : public A { void g() { B::f(); }};
2112 "the class of that member function" refers to `A'. But 11.2
2113 [class.access.base] says that we need to convert 'this' to B* as
2114 part of the access, so we pass 'B' to maybe_dummy_object. */
2116 object = maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)),
2119 if (processing_template_decl)
2121 if (type_dependent_expression_p (object))
2123 tree ret = build_nt_call_vec (orig_fn, orig_args);
2124 release_tree_vector (orig_args);
2127 object = build_non_dependent_expr (object);
2130 result = build_new_method_call (object, fn, args, NULL_TREE,
2132 ? LOOKUP_NORMAL|LOOKUP_NONVIRTUAL
2137 else if (is_overloaded_fn (fn))
2139 /* If the function is an overloaded builtin, resolve it. */
2140 if (TREE_CODE (fn) == FUNCTION_DECL
2141 && (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL
2142 || DECL_BUILT_IN_CLASS (fn) == BUILT_IN_MD))
2143 result = resolve_overloaded_builtin (input_location, fn, *args);
2146 /* A call to a namespace-scope function. */
2147 result = build_new_function_call (fn, args, koenig_p, complain);
2149 else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR)
2151 if (!VEC_empty (tree, *args))
2152 error ("arguments to destructor are not allowed");
2153 /* Mark the pseudo-destructor call as having side-effects so
2154 that we do not issue warnings about its use. */
2155 result = build1 (NOP_EXPR,
2157 TREE_OPERAND (fn, 0));
2158 TREE_SIDE_EFFECTS (result) = 1;
2160 else if (CLASS_TYPE_P (TREE_TYPE (fn)))
2161 /* If the "function" is really an object of class type, it might
2162 have an overloaded `operator ()'. */
2163 result = build_op_call (fn, args, complain);
2166 /* A call where the function is unknown. */
2167 result = cp_build_function_call_vec (fn, args, complain);
2169 if (processing_template_decl && result != error_mark_node)
2171 if (TREE_CODE (result) == INDIRECT_REF)
2172 result = TREE_OPERAND (result, 0);
2173 result = build_call_vec (TREE_TYPE (result), orig_fn, orig_args);
2174 KOENIG_LOOKUP_P (result) = koenig_p;
2175 release_tree_vector (orig_args);
2176 result = convert_from_reference (result);
2181 /* Free garbage OVERLOADs from arg-dependent lookup. */
2182 tree next = NULL_TREE;
2184 fn && TREE_CODE (fn) == OVERLOAD && OVL_ARG_DEPENDENT (fn);
2187 if (processing_template_decl)
2188 /* In a template, we'll re-use them at instantiation time. */
2189 OVL_ARG_DEPENDENT (fn) = false;
2192 next = OVL_CHAIN (fn);
2201 /* Finish a call to a postfix increment or decrement or EXPR. (Which
2202 is indicated by CODE, which should be POSTINCREMENT_EXPR or
2203 POSTDECREMENT_EXPR.) */
2206 finish_increment_expr (tree expr, enum tree_code code)
2208 return build_x_unary_op (code, expr, tf_warning_or_error);
2211 /* Finish a use of `this'. Returns an expression for `this'. */
2214 finish_this_expr (void)
2218 if (current_class_ptr)
2220 tree type = TREE_TYPE (current_class_ref);
2222 /* In a lambda expression, 'this' refers to the captured 'this'. */
2223 if (LAMBDA_TYPE_P (type))
2224 result = lambda_expr_this_capture (CLASSTYPE_LAMBDA_EXPR (type));
2226 result = current_class_ptr;
2229 else if (current_function_decl
2230 && DECL_STATIC_FUNCTION_P (current_function_decl))
2232 error ("%<this%> is unavailable for static member functions");
2233 result = error_mark_node;
2237 if (current_function_decl)
2238 error ("invalid use of %<this%> in non-member function");
2240 error ("invalid use of %<this%> at top level");
2241 result = error_mark_node;
2247 /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
2248 expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
2249 the TYPE for the type given. If SCOPE is non-NULL, the expression
2250 was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
2253 finish_pseudo_destructor_expr (tree object, tree scope, tree destructor)
2255 if (object == error_mark_node || destructor == error_mark_node)
2256 return error_mark_node;
2258 gcc_assert (TYPE_P (destructor));
2260 if (!processing_template_decl)
2262 if (scope == error_mark_node)
2264 error ("invalid qualifying scope in pseudo-destructor name");
2265 return error_mark_node;
2267 if (scope && TYPE_P (scope) && !check_dtor_name (scope, destructor))
2269 error ("qualified type %qT does not match destructor name ~%qT",
2271 return error_mark_node;
2275 /* [expr.pseudo] says both:
2277 The type designated by the pseudo-destructor-name shall be
2278 the same as the object type.
2282 The cv-unqualified versions of the object type and of the
2283 type designated by the pseudo-destructor-name shall be the
2286 We implement the more generous second sentence, since that is
2287 what most other compilers do. */
2288 if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object),
2291 error ("%qE is not of type %qT", object, destructor);
2292 return error_mark_node;
2296 return build3 (PSEUDO_DTOR_EXPR, void_type_node, object, scope, destructor);
2299 /* Finish an expression of the form CODE EXPR. */
2302 finish_unary_op_expr (enum tree_code code, tree expr)
2304 tree result = build_x_unary_op (code, expr, tf_warning_or_error);
2305 /* Inside a template, build_x_unary_op does not fold the
2306 expression. So check whether the result is folded before
2307 setting TREE_NEGATED_INT. */
2308 if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST
2309 && TREE_CODE (result) == INTEGER_CST
2310 && !TYPE_UNSIGNED (TREE_TYPE (result))
2311 && INT_CST_LT (result, integer_zero_node))
2313 /* RESULT may be a cached INTEGER_CST, so we must copy it before
2314 setting TREE_NEGATED_INT. */
2315 result = copy_node (result);
2316 TREE_NEGATED_INT (result) = 1;
2318 if (TREE_OVERFLOW_P (result) && !TREE_OVERFLOW_P (expr))
2319 overflow_warning (input_location, result);
2324 /* Finish a compound-literal expression. TYPE is the type to which
2325 the CONSTRUCTOR in COMPOUND_LITERAL is being cast. */
2328 finish_compound_literal (tree type, tree compound_literal,
2329 tsubst_flags_t complain)
2331 if (type == error_mark_node)
2332 return error_mark_node;
2334 if (TREE_CODE (type) == REFERENCE_TYPE)
2337 = finish_compound_literal (TREE_TYPE (type), compound_literal,
2339 return cp_build_c_cast (type, compound_literal, complain);
2342 if (!TYPE_OBJ_P (type))
2344 if (complain & tf_error)
2345 error ("compound literal of non-object type %qT", type);
2346 return error_mark_node;
2349 if (processing_template_decl)
2351 TREE_TYPE (compound_literal) = type;
2352 /* Mark the expression as a compound literal. */
2353 TREE_HAS_CONSTRUCTOR (compound_literal) = 1;
2354 return compound_literal;
2357 type = complete_type (type);
2359 if (TYPE_NON_AGGREGATE_CLASS (type))
2361 /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
2362 everywhere that deals with function arguments would be a pain, so
2363 just wrap it in a TREE_LIST. The parser set a flag so we know
2364 that it came from T{} rather than T({}). */
2365 CONSTRUCTOR_IS_DIRECT_INIT (compound_literal) = 1;
2366 compound_literal = build_tree_list (NULL_TREE, compound_literal);
2367 return build_functional_cast (type, compound_literal, complain);
2370 if (TREE_CODE (type) == ARRAY_TYPE
2371 && check_array_initializer (NULL_TREE, type, compound_literal))
2372 return error_mark_node;
2373 compound_literal = reshape_init (type, compound_literal);
2374 if (TREE_CODE (type) == ARRAY_TYPE
2375 && TYPE_DOMAIN (type) == NULL_TREE)
2377 cp_complete_array_type_or_error (&type, compound_literal,
2379 if (type == error_mark_node)
2380 return error_mark_node;
2382 compound_literal = digest_init (type, compound_literal);
2383 /* Put static/constant array temporaries in static variables, but always
2384 represent class temporaries with TARGET_EXPR so we elide copies. */
2385 if ((!at_function_scope_p () || CP_TYPE_CONST_P (type))
2386 && TREE_CODE (type) == ARRAY_TYPE
2387 && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
2388 && initializer_constant_valid_p (compound_literal, type))
2390 tree decl = create_temporary_var (type);
2391 DECL_INITIAL (decl) = compound_literal;
2392 TREE_STATIC (decl) = 1;
2393 if (literal_type_p (type) && CP_TYPE_CONST_NON_VOLATILE_P (type))
2395 /* 5.19 says that a constant expression can include an
2396 lvalue-rvalue conversion applied to "a glvalue of literal type
2397 that refers to a non-volatile temporary object initialized
2398 with a constant expression". Rather than try to communicate
2399 that this VAR_DECL is a temporary, just mark it constexpr. */
2400 DECL_DECLARED_CONSTEXPR_P (decl) = true;
2401 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
2402 TREE_CONSTANT (decl) = true;
2404 cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
2405 decl = pushdecl_top_level (decl);
2406 DECL_NAME (decl) = make_anon_name ();
2407 SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl));
2411 return get_target_expr_sfinae (compound_literal, complain);
2414 /* Return the declaration for the function-name variable indicated by
2418 finish_fname (tree id)
2422 decl = fname_decl (input_location, C_RID_CODE (id), id);
2423 if (processing_template_decl && current_function_decl)
2424 decl = DECL_NAME (decl);
2428 /* Finish a translation unit. */
2431 finish_translation_unit (void)
2433 /* In case there were missing closebraces,
2434 get us back to the global binding level. */
2436 while (current_namespace != global_namespace)
2439 /* Do file scope __FUNCTION__ et al. */
2440 finish_fname_decls ();
2443 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
2444 Returns the parameter. */
2447 finish_template_type_parm (tree aggr, tree identifier)
2449 if (aggr != class_type_node)
2451 permerror (input_location, "template type parameters must use the keyword %<class%> or %<typename%>");
2452 aggr = class_type_node;
2455 return build_tree_list (aggr, identifier);
2458 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
2459 Returns the parameter. */
2462 finish_template_template_parm (tree aggr, tree identifier)
2464 tree decl = build_decl (input_location,
2465 TYPE_DECL, identifier, NULL_TREE);
2466 tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
2467 DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
2468 DECL_TEMPLATE_RESULT (tmpl) = decl;
2469 DECL_ARTIFICIAL (decl) = 1;
2470 end_template_decl ();
2472 gcc_assert (DECL_TEMPLATE_PARMS (tmpl));
2474 check_default_tmpl_args (decl, DECL_TEMPLATE_PARMS (tmpl),
2475 /*is_primary=*/true, /*is_partial=*/false,
2478 return finish_template_type_parm (aggr, tmpl);
2481 /* ARGUMENT is the default-argument value for a template template
2482 parameter. If ARGUMENT is invalid, issue error messages and return
2483 the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
2486 check_template_template_default_arg (tree argument)
2488 if (TREE_CODE (argument) != TEMPLATE_DECL
2489 && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM
2490 && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE)
2492 if (TREE_CODE (argument) == TYPE_DECL)
2493 error ("invalid use of type %qT as a default value for a template "
2494 "template-parameter", TREE_TYPE (argument));
2496 error ("invalid default argument for a template template parameter");
2497 return error_mark_node;
2503 /* Begin a class definition, as indicated by T. */
2506 begin_class_definition (tree t, tree attributes)
2508 if (error_operand_p (t) || error_operand_p (TYPE_MAIN_DECL (t)))
2509 return error_mark_node;
2511 if (processing_template_parmlist)
2513 error ("definition of %q#T inside template parameter list", t);
2514 return error_mark_node;
2517 /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
2518 are passed the same as decimal scalar types. */
2519 if (TREE_CODE (t) == RECORD_TYPE
2520 && !processing_template_decl)
2522 tree ns = TYPE_CONTEXT (t);
2523 if (ns && TREE_CODE (ns) == NAMESPACE_DECL
2524 && DECL_CONTEXT (ns) == std_node
2526 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (ns)), "decimal"))
2528 const char *n = TYPE_NAME_STRING (t);
2529 if ((strcmp (n, "decimal32") == 0)
2530 || (strcmp (n, "decimal64") == 0)
2531 || (strcmp (n, "decimal128") == 0))
2532 TYPE_TRANSPARENT_AGGR (t) = 1;
2536 /* A non-implicit typename comes from code like:
2538 template <typename T> struct A {
2539 template <typename U> struct A<T>::B ...
2541 This is erroneous. */
2542 else if (TREE_CODE (t) == TYPENAME_TYPE)
2544 error ("invalid definition of qualified type %qT", t);
2545 t = error_mark_node;
2548 if (t == error_mark_node || ! MAYBE_CLASS_TYPE_P (t))
2550 t = make_class_type (RECORD_TYPE);
2551 pushtag (make_anon_name (), t, /*tag_scope=*/ts_current);
2554 if (TYPE_BEING_DEFINED (t))
2556 t = make_class_type (TREE_CODE (t));
2557 pushtag (TYPE_IDENTIFIER (t), t, /*tag_scope=*/ts_current);
2559 maybe_process_partial_specialization (t);
2561 TYPE_BEING_DEFINED (t) = 1;
2563 cplus_decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
2564 fixup_attribute_variants (t);
2566 if (flag_pack_struct)
2569 TYPE_PACKED (t) = 1;
2570 /* Even though the type is being defined for the first time
2571 here, there might have been a forward declaration, so there
2572 might be cv-qualified variants of T. */
2573 for (v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
2574 TYPE_PACKED (v) = 1;
2576 /* Reset the interface data, at the earliest possible
2577 moment, as it might have been set via a class foo;
2579 if (! TYPE_ANONYMOUS_P (t))
2581 struct c_fileinfo *finfo = get_fileinfo (input_filename);
2582 CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
2583 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
2584 (t, finfo->interface_unknown);
2586 reset_specialization();
2588 /* Make a declaration for this class in its own scope. */
2589 build_self_reference ();
2594 /* Finish the member declaration given by DECL. */
2597 finish_member_declaration (tree decl)
2599 if (decl == error_mark_node || decl == NULL_TREE)
2602 if (decl == void_type_node)
2603 /* The COMPONENT was a friend, not a member, and so there's
2604 nothing for us to do. */
2607 /* We should see only one DECL at a time. */
2608 gcc_assert (DECL_CHAIN (decl) == NULL_TREE);
2610 /* Set up access control for DECL. */
2612 = (current_access_specifier == access_private_node);
2613 TREE_PROTECTED (decl)
2614 = (current_access_specifier == access_protected_node);
2615 if (TREE_CODE (decl) == TEMPLATE_DECL)
2617 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
2618 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl);
2621 /* Mark the DECL as a member of the current class. */
2622 DECL_CONTEXT (decl) = current_class_type;
2624 /* Check for bare parameter packs in the member variable declaration. */
2625 if (TREE_CODE (decl) == FIELD_DECL)
2627 if (check_for_bare_parameter_packs (TREE_TYPE (decl)))
2628 TREE_TYPE (decl) = error_mark_node;
2629 if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl)))
2630 DECL_ATTRIBUTES (decl) = NULL_TREE;
2635 A C language linkage is ignored for the names of class members
2636 and the member function type of class member functions. */
2637 if (DECL_LANG_SPECIFIC (decl) && DECL_LANGUAGE (decl) == lang_c)
2638 SET_DECL_LANGUAGE (decl, lang_cplusplus);
2640 /* Put functions on the TYPE_METHODS list and everything else on the
2641 TYPE_FIELDS list. Note that these are built up in reverse order.
2642 We reverse them (to obtain declaration order) in finish_struct. */
2643 if (TREE_CODE (decl) == FUNCTION_DECL
2644 || DECL_FUNCTION_TEMPLATE_P (decl))
2646 /* We also need to add this function to the
2647 CLASSTYPE_METHOD_VEC. */
2648 if (add_method (current_class_type, decl, NULL_TREE))
2650 DECL_CHAIN (decl) = TYPE_METHODS (current_class_type);
2651 TYPE_METHODS (current_class_type) = decl;
2653 maybe_add_class_template_decl_list (current_class_type, decl,
2657 /* Enter the DECL into the scope of the class. */
2658 else if ((TREE_CODE (decl) == USING_DECL && !DECL_DEPENDENT_P (decl))
2659 || pushdecl_class_level (decl))
2661 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
2662 go at the beginning. The reason is that lookup_field_1
2663 searches the list in order, and we want a field name to
2664 override a type name so that the "struct stat hack" will
2665 work. In particular:
2667 struct S { enum E { }; int E } s;
2670 is valid. In addition, the FIELD_DECLs must be maintained in
2671 declaration order so that class layout works as expected.
2672 However, we don't need that order until class layout, so we
2673 save a little time by putting FIELD_DECLs on in reverse order
2674 here, and then reversing them in finish_struct_1. (We could
2675 also keep a pointer to the correct insertion points in the
2678 if (TREE_CODE (decl) == TYPE_DECL)
2679 TYPE_FIELDS (current_class_type)
2680 = chainon (TYPE_FIELDS (current_class_type), decl);
2683 DECL_CHAIN (decl) = TYPE_FIELDS (current_class_type);
2684 TYPE_FIELDS (current_class_type) = decl;
2687 maybe_add_class_template_decl_list (current_class_type, decl,
2692 note_decl_for_pch (decl);
2695 /* DECL has been declared while we are building a PCH file. Perform
2696 actions that we might normally undertake lazily, but which can be
2697 performed now so that they do not have to be performed in
2698 translation units which include the PCH file. */
2701 note_decl_for_pch (tree decl)
2703 gcc_assert (pch_file);
2705 /* There's a good chance that we'll have to mangle names at some
2706 point, even if only for emission in debugging information. */
2707 if ((TREE_CODE (decl) == VAR_DECL
2708 || TREE_CODE (decl) == FUNCTION_DECL)
2709 && !processing_template_decl)
2713 /* Finish processing a complete template declaration. The PARMS are
2714 the template parameters. */
2717 finish_template_decl (tree parms)
2720 end_template_decl ();
2722 end_specialization ();
2725 /* Finish processing a template-id (which names a type) of the form
2726 NAME < ARGS >. Return the TYPE_DECL for the type named by the
2727 template-id. If ENTERING_SCOPE is nonzero we are about to enter
2728 the scope of template-id indicated. */
2731 finish_template_type (tree name, tree args, int entering_scope)
2735 decl = lookup_template_class (name, args,
2736 NULL_TREE, NULL_TREE, entering_scope,
2737 tf_warning_or_error | tf_user);
2738 if (decl != error_mark_node)
2739 decl = TYPE_STUB_DECL (decl);
2744 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2745 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2746 BASE_CLASS, or NULL_TREE if an error occurred. The
2747 ACCESS_SPECIFIER is one of
2748 access_{default,public,protected_private}_node. For a virtual base
2749 we set TREE_TYPE. */
2752 finish_base_specifier (tree base, tree access, bool virtual_p)
2756 if (base == error_mark_node)
2758 error ("invalid base-class specification");
2761 else if (! MAYBE_CLASS_TYPE_P (base))
2763 error ("%qT is not a class type", base);
2768 if (cp_type_quals (base) != 0)
2770 error ("base class %qT has cv qualifiers", base);
2771 base = TYPE_MAIN_VARIANT (base);
2773 result = build_tree_list (access, base);
2775 TREE_TYPE (result) = integer_type_node;
2781 /* If FNS is a member function, a set of member functions, or a
2782 template-id referring to one or more member functions, return a
2783 BASELINK for FNS, incorporating the current access context.
2784 Otherwise, return FNS unchanged. */
2787 baselink_for_fns (tree fns)
2792 if (BASELINK_P (fns)
2793 || error_operand_p (fns))
2797 if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
2798 fn = TREE_OPERAND (fn, 0);
2799 fn = get_first_fn (fn);
2800 if (!DECL_FUNCTION_MEMBER_P (fn))
2803 cl = currently_open_derived_class (DECL_CONTEXT (fn));
2805 cl = DECL_CONTEXT (fn);
2806 cl = TYPE_BINFO (cl);
2807 return build_baselink (cl, cl, fns, /*optype=*/NULL_TREE);
2810 /* Returns true iff DECL is an automatic variable from a function outside
2814 outer_automatic_var_p (tree decl)
2816 return ((TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL)
2817 && DECL_FUNCTION_SCOPE_P (decl)
2818 && !TREE_STATIC (decl)
2819 && DECL_CONTEXT (decl) != current_function_decl);
2822 /* Returns true iff DECL is a capture field from a lambda that is not our
2823 immediate context. */
2826 outer_lambda_capture_p (tree decl)
2828 return (TREE_CODE (decl) == FIELD_DECL
2829 && LAMBDA_TYPE_P (DECL_CONTEXT (decl))
2830 && (!current_class_type
2831 || !DERIVED_FROM_P (DECL_CONTEXT (decl), current_class_type)));
2834 /* ID_EXPRESSION is a representation of parsed, but unprocessed,
2835 id-expression. (See cp_parser_id_expression for details.) SCOPE,
2836 if non-NULL, is the type or namespace used to explicitly qualify
2837 ID_EXPRESSION. DECL is the entity to which that name has been
2840 *CONSTANT_EXPRESSION_P is true if we are presently parsing a
2841 constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
2842 be set to true if this expression isn't permitted in a
2843 constant-expression, but it is otherwise not set by this function.
2844 *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
2845 constant-expression, but a non-constant expression is also
2848 DONE is true if this expression is a complete postfix-expression;
2849 it is false if this expression is followed by '->', '[', '(', etc.
2850 ADDRESS_P is true iff this expression is the operand of '&'.
2851 TEMPLATE_P is true iff the qualified-id was of the form
2852 "A::template B". TEMPLATE_ARG_P is true iff this qualified name
2853 appears as a template argument.
2855 If an error occurs, and it is the kind of error that might cause
2856 the parser to abort a tentative parse, *ERROR_MSG is filled in. It
2857 is the caller's responsibility to issue the message. *ERROR_MSG
2858 will be a string with static storage duration, so the caller need
2861 Return an expression for the entity, after issuing appropriate
2862 diagnostics. This function is also responsible for transforming a
2863 reference to a non-static member into a COMPONENT_REF that makes
2864 the use of "this" explicit.
2866 Upon return, *IDK will be filled in appropriately. */
2868 finish_id_expression (tree id_expression,
2872 bool integral_constant_expression_p,
2873 bool allow_non_integral_constant_expression_p,
2874 bool *non_integral_constant_expression_p,
2878 bool template_arg_p,
2879 const char **error_msg,
2880 location_t location)
2882 /* Initialize the output parameters. */
2883 *idk = CP_ID_KIND_NONE;
2886 if (id_expression == error_mark_node)
2887 return error_mark_node;
2888 /* If we have a template-id, then no further lookup is
2889 required. If the template-id was for a template-class, we
2890 will sometimes have a TYPE_DECL at this point. */
2891 else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
2892 || TREE_CODE (decl) == TYPE_DECL)
2894 /* Look up the name. */
2897 if (decl == error_mark_node)
2899 /* Name lookup failed. */
2902 || (!dependent_type_p (scope)
2903 && !(TREE_CODE (id_expression) == IDENTIFIER_NODE
2904 && IDENTIFIER_TYPENAME_P (id_expression)
2905 && dependent_type_p (TREE_TYPE (id_expression))))))
2907 /* If the qualifying type is non-dependent (and the name
2908 does not name a conversion operator to a dependent
2909 type), issue an error. */
2910 qualified_name_lookup_error (scope, id_expression, decl, location);
2911 return error_mark_node;
2915 /* It may be resolved via Koenig lookup. */
2916 *idk = CP_ID_KIND_UNQUALIFIED;
2917 return id_expression;
2920 decl = id_expression;
2922 /* If DECL is a variable that would be out of scope under
2923 ANSI/ISO rules, but in scope in the ARM, name lookup
2924 will succeed. Issue a diagnostic here. */
2926 decl = check_for_out_of_scope_variable (decl);
2928 /* Remember that the name was used in the definition of
2929 the current class so that we can check later to see if
2930 the meaning would have been different after the class
2931 was entirely defined. */
2932 if (!scope && decl != error_mark_node
2933 && TREE_CODE (id_expression) == IDENTIFIER_NODE)
2934 maybe_note_name_used_in_class (id_expression, decl);
2936 /* Disallow uses of local variables from containing functions, except
2937 within lambda-expressions. */
2938 if ((outer_automatic_var_p (decl)
2939 || outer_lambda_capture_p (decl))
2940 /* It's not a use (3.2) if we're in an unevaluated context. */
2941 && !cp_unevaluated_operand)
2943 tree context = DECL_CONTEXT (decl);
2944 tree containing_function = current_function_decl;
2945 tree lambda_stack = NULL_TREE;
2946 tree lambda_expr = NULL_TREE;
2947 tree initializer = decl;
2949 /* Core issue 696: "[At the July 2009 meeting] the CWG expressed
2950 support for an approach in which a reference to a local
2951 [constant] automatic variable in a nested class or lambda body
2952 would enter the expression as an rvalue, which would reduce
2953 the complexity of the problem"
2955 FIXME update for final resolution of core issue 696. */
2956 if (decl_constant_var_p (decl))
2957 return integral_constant_value (decl);
2959 if (TYPE_P (context))
2961 /* Implicit capture of an explicit capture. */
2962 context = lambda_function (context);
2963 initializer = thisify_lambda_field (decl);
2966 /* If we are in a lambda function, we can move out until we hit
2968 2. a non-lambda function, or
2969 3. a non-default capturing lambda function. */
2970 while (context != containing_function
2971 && LAMBDA_FUNCTION_P (containing_function))
2973 lambda_expr = CLASSTYPE_LAMBDA_EXPR
2974 (DECL_CONTEXT (containing_function));
2976 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr)
2980 lambda_stack = tree_cons (NULL_TREE,
2985 = decl_function_context (containing_function);
2988 if (context == containing_function)
2990 decl = add_default_capture (lambda_stack,
2991 /*id=*/DECL_NAME (decl),
2994 else if (lambda_expr)
2996 error ("%qD is not captured", decl);
2997 return error_mark_node;
3001 error (TREE_CODE (decl) == VAR_DECL
3002 ? "use of %<auto%> variable from containing function"
3003 : "use of parameter from containing function");
3004 error (" %q+#D declared here", decl);
3005 return error_mark_node;
3009 /* Also disallow uses of function parameters outside the function
3010 body, except inside an unevaluated context (i.e. decltype). */
3011 if (TREE_CODE (decl) == PARM_DECL
3012 && DECL_CONTEXT (decl) == NULL_TREE
3013 && !cp_unevaluated_operand)
3015 error ("use of parameter %qD outside function body", decl);
3016 return error_mark_node;
3020 /* If we didn't find anything, or what we found was a type,
3021 then this wasn't really an id-expression. */
3022 if (TREE_CODE (decl) == TEMPLATE_DECL
3023 && !DECL_FUNCTION_TEMPLATE_P (decl))
3025 *error_msg = "missing template arguments";
3026 return error_mark_node;
3028 else if (TREE_CODE (decl) == TYPE_DECL
3029 || TREE_CODE (decl) == NAMESPACE_DECL)
3031 *error_msg = "expected primary-expression";
3032 return error_mark_node;
3035 /* If the name resolved to a template parameter, there is no
3036 need to look it up again later. */
3037 if ((TREE_CODE (decl) == CONST_DECL && DECL_TEMPLATE_PARM_P (decl))
3038 || TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
3042 *idk = CP_ID_KIND_NONE;
3043 if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
3044 decl = TEMPLATE_PARM_DECL (decl);
3045 r = convert_from_reference (DECL_INITIAL (decl));
3047 if (integral_constant_expression_p
3048 && !dependent_type_p (TREE_TYPE (decl))
3049 && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r))))
3051 if (!allow_non_integral_constant_expression_p)
3052 error ("template parameter %qD of type %qT is not allowed in "
3053 "an integral constant expression because it is not of "
3054 "integral or enumeration type", decl, TREE_TYPE (decl));
3055 *non_integral_constant_expression_p = true;
3059 /* Similarly, we resolve enumeration constants to their
3060 underlying values. */
3061 else if (TREE_CODE (decl) == CONST_DECL)
3063 *idk = CP_ID_KIND_NONE;
3064 if (!processing_template_decl)
3066 used_types_insert (TREE_TYPE (decl));
3067 return DECL_INITIAL (decl);
3075 /* If the declaration was explicitly qualified indicate
3076 that. The semantics of `A::f(3)' are different than
3077 `f(3)' if `f' is virtual. */
3079 ? CP_ID_KIND_QUALIFIED
3080 : (TREE_CODE (decl) == TEMPLATE_ID_EXPR
3081 ? CP_ID_KIND_TEMPLATE_ID
3082 : CP_ID_KIND_UNQUALIFIED));
3087 An id-expression is type-dependent if it contains an
3088 identifier that was declared with a dependent type.
3090 The standard is not very specific about an id-expression that
3091 names a set of overloaded functions. What if some of them
3092 have dependent types and some of them do not? Presumably,
3093 such a name should be treated as a dependent name. */
3094 /* Assume the name is not dependent. */
3095 dependent_p = false;
3096 if (!processing_template_decl)
3097 /* No names are dependent outside a template. */
3099 /* A template-id where the name of the template was not resolved
3100 is definitely dependent. */
3101 else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
3102 && (TREE_CODE (TREE_OPERAND (decl, 0))
3103 == IDENTIFIER_NODE))
3105 /* For anything except an overloaded function, just check its
3107 else if (!is_overloaded_fn (decl))
3109 = dependent_type_p (TREE_TYPE (decl));
3110 /* For a set of overloaded functions, check each of the
3116 if (BASELINK_P (fns))
3117 fns = BASELINK_FUNCTIONS (fns);
3119 /* For a template-id, check to see if the template
3120 arguments are dependent. */
3121 if (TREE_CODE (fns) == TEMPLATE_ID_EXPR)
3123 tree args = TREE_OPERAND (fns, 1);
3124 dependent_p = any_dependent_template_arguments_p (args);
3125 /* The functions are those referred to by the
3127 fns = TREE_OPERAND (fns, 0);
3130 /* If there are no dependent template arguments, go through
3131 the overloaded functions. */
3132 while (fns && !dependent_p)
3134 tree fn = OVL_CURRENT (fns);
3136 /* Member functions of dependent classes are
3138 if (TREE_CODE (fn) == FUNCTION_DECL
3139 && type_dependent_expression_p (fn))
3141 else if (TREE_CODE (fn) == TEMPLATE_DECL
3142 && dependent_template_p (fn))
3145 fns = OVL_NEXT (fns);
3149 /* If the name was dependent on a template parameter, we will
3150 resolve the name at instantiation time. */
3153 /* Create a SCOPE_REF for qualified names, if the scope is
3159 if (address_p && done)
3160 decl = finish_qualified_id_expr (scope, decl,
3166 tree type = NULL_TREE;
3167 if (DECL_P (decl) && !dependent_scope_p (scope))
3168 type = TREE_TYPE (decl);
3169 decl = build_qualified_name (type,
3175 if (TREE_TYPE (decl))
3176 decl = convert_from_reference (decl);
3179 /* A TEMPLATE_ID already contains all the information we
3181 if (TREE_CODE (id_expression) == TEMPLATE_ID_EXPR)
3182 return id_expression;
3183 *idk = CP_ID_KIND_UNQUALIFIED_DEPENDENT;
3184 /* If we found a variable, then name lookup during the
3185 instantiation will always resolve to the same VAR_DECL
3186 (or an instantiation thereof). */
3187 if (TREE_CODE (decl) == VAR_DECL
3188 || TREE_CODE (decl) == PARM_DECL)
3189 return convert_from_reference (decl);
3190 /* The same is true for FIELD_DECL, but we also need to
3191 make sure that the syntax is correct. */
3192 else if (TREE_CODE (decl) == FIELD_DECL)
3194 /* Since SCOPE is NULL here, this is an unqualified name.
3195 Access checking has been performed during name lookup
3196 already. Turn off checking to avoid duplicate errors. */
3197 push_deferring_access_checks (dk_no_check);
3198 decl = finish_non_static_data_member
3200 /*qualifying_scope=*/NULL_TREE);
3201 pop_deferring_access_checks ();
3204 return id_expression;
3207 if (TREE_CODE (decl) == NAMESPACE_DECL)
3209 error ("use of namespace %qD as expression", decl);
3210 return error_mark_node;
3212 else if (DECL_CLASS_TEMPLATE_P (decl))
3214 error ("use of class template %qT as expression", decl);
3215 return error_mark_node;
3217 else if (TREE_CODE (decl) == TREE_LIST)
3219 /* Ambiguous reference to base members. */
3220 error ("request for member %qD is ambiguous in "
3221 "multiple inheritance lattice", id_expression);
3222 print_candidates (decl);
3223 return error_mark_node;
3226 /* Mark variable-like entities as used. Functions are similarly
3227 marked either below or after overload resolution. */
3228 if (TREE_CODE (decl) == VAR_DECL
3229 || TREE_CODE (decl) == PARM_DECL
3230 || TREE_CODE (decl) == RESULT_DECL)
3233 /* Only certain kinds of names are allowed in constant
3234 expression. Enumerators and template parameters have already
3235 been handled above. */
3236 if (! error_operand_p (decl)
3237 && integral_constant_expression_p
3238 && ! decl_constant_var_p (decl)
3239 && ! builtin_valid_in_constant_expr_p (decl))
3241 if (!allow_non_integral_constant_expression_p)
3243 error ("%qD cannot appear in a constant-expression", decl);
3244 return error_mark_node;
3246 *non_integral_constant_expression_p = true;
3251 decl = (adjust_result_of_qualified_name_lookup
3252 (decl, scope, current_class_type));
3254 if (TREE_CODE (decl) == FUNCTION_DECL)
3257 if (TREE_CODE (decl) == FIELD_DECL || BASELINK_P (decl))
3258 decl = finish_qualified_id_expr (scope,
3266 tree r = convert_from_reference (decl);
3268 /* In a template, return a SCOPE_REF for most qualified-ids
3269 so that we can check access at instantiation time. But if
3270 we're looking at a member of the current instantiation, we
3271 know we have access and building up the SCOPE_REF confuses
3272 non-type template argument handling. */
3273 if (processing_template_decl && TYPE_P (scope)
3274 && !currently_open_class (scope))
3275 r = build_qualified_name (TREE_TYPE (r),
3281 else if (TREE_CODE (decl) == FIELD_DECL)
3283 /* Since SCOPE is NULL here, this is an unqualified name.
3284 Access checking has been performed during name lookup
3285 already. Turn off checking to avoid duplicate errors. */
3286 push_deferring_access_checks (dk_no_check);
3287 decl = finish_non_static_data_member (decl, NULL_TREE,
3288 /*qualifying_scope=*/NULL_TREE);
3289 pop_deferring_access_checks ();
3291 else if (is_overloaded_fn (decl))
3295 first_fn = get_first_fn (decl);
3296 if (TREE_CODE (first_fn) == TEMPLATE_DECL)
3297 first_fn = DECL_TEMPLATE_RESULT (first_fn);
3299 if (!really_overloaded_fn (decl))
3300 mark_used (first_fn);
3303 && TREE_CODE (first_fn) == FUNCTION_DECL
3304 && DECL_FUNCTION_MEMBER_P (first_fn)
3305 && !shared_member_p (decl))
3307 /* A set of member functions. */
3308 decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0);
3309 return finish_class_member_access_expr (decl, id_expression,
3310 /*template_p=*/false,
3311 tf_warning_or_error);
3314 decl = baselink_for_fns (decl);
3318 if (DECL_P (decl) && DECL_NONLOCAL (decl)
3319 && DECL_CLASS_SCOPE_P (decl))
3321 tree context = context_for_name_lookup (decl);
3322 if (context != current_class_type)
3324 tree path = currently_open_derived_class (context);
3325 perform_or_defer_access_check (TYPE_BINFO (path),
3330 decl = convert_from_reference (decl);
3334 if (TREE_DEPRECATED (decl))
3335 warn_deprecated_use (decl, NULL_TREE);
3340 /* Implement the __typeof keyword: Return the type of EXPR, suitable for
3341 use as a type-specifier. */
3344 finish_typeof (tree expr)
3348 if (type_dependent_expression_p (expr))
3350 type = cxx_make_type (TYPEOF_TYPE);
3351 TYPEOF_TYPE_EXPR (type) = expr;
3352 SET_TYPE_STRUCTURAL_EQUALITY (type);
3357 expr = mark_type_use (expr);
3359 type = unlowered_expr_type (expr);
3361 if (!type || type == unknown_type_node)
3363 error ("type of %qE is unknown", expr);
3364 return error_mark_node;
3370 /* Implement the __underlying_type keyword: Return the underlying
3371 type of TYPE, suitable for use as a type-specifier. */
3374 finish_underlying_type (tree type)
3376 tree underlying_type;
3378 if (processing_template_decl)
3380 underlying_type = cxx_make_type (UNDERLYING_TYPE);
3381 UNDERLYING_TYPE_TYPE (underlying_type) = type;
3382 SET_TYPE_STRUCTURAL_EQUALITY (underlying_type);
3384 return underlying_type;
3387 complete_type (type);
3389 if (TREE_CODE (type) != ENUMERAL_TYPE)
3391 error ("%qE is not an enumeration type", type);
3392 return error_mark_node;
3395 underlying_type = ENUM_UNDERLYING_TYPE (type);
3397 /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
3398 includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
3399 See finish_enum_value_list for details. */
3400 if (!ENUM_FIXED_UNDERLYING_TYPE_P (type))
3402 = c_common_type_for_mode (TYPE_MODE (underlying_type),
3403 TYPE_UNSIGNED (underlying_type));
3405 return underlying_type;
3408 /* Perform C++-specific checks for __builtin_offsetof before calling
3412 finish_offsetof (tree expr)
3414 if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR)
3416 error ("cannot apply %<offsetof%> to destructor %<~%T%>",
3417 TREE_OPERAND (expr, 2));
3418 return error_mark_node;
3420 if (TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE
3421 || TREE_CODE (TREE_TYPE (expr)) == METHOD_TYPE
3422 || TREE_TYPE (expr) == unknown_type_node)
3424 if (TREE_CODE (expr) == COMPONENT_REF
3425 || TREE_CODE (expr) == COMPOUND_EXPR)
3426 expr = TREE_OPERAND (expr, 1);
3427 error ("cannot apply %<offsetof%> to member function %qD", expr);
3428 return error_mark_node;
3430 if (TREE_CODE (expr) == INDIRECT_REF && REFERENCE_REF_P (expr))
3431 expr = TREE_OPERAND (expr, 0);
3432 return fold_offsetof (expr, NULL_TREE);
3435 /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
3436 function is broken out from the above for the benefit of the tree-ssa
3440 simplify_aggr_init_expr (tree *tp)
3442 tree aggr_init_expr = *tp;
3444 /* Form an appropriate CALL_EXPR. */
3445 tree fn = AGGR_INIT_EXPR_FN (aggr_init_expr);
3446 tree slot = AGGR_INIT_EXPR_SLOT (aggr_init_expr);
3447 tree type = TREE_TYPE (slot);
3450 enum style_t { ctor, arg, pcc } style;
3452 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
3454 #ifdef PCC_STATIC_STRUCT_RETURN
3460 gcc_assert (TREE_ADDRESSABLE (type));
3464 call_expr = build_call_array_loc (input_location,
3465 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
3467 aggr_init_expr_nargs (aggr_init_expr),
3468 AGGR_INIT_EXPR_ARGP (aggr_init_expr));
3469 TREE_NOTHROW (call_expr) = TREE_NOTHROW (aggr_init_expr);
3473 /* Replace the first argument to the ctor with the address of the
3475 cxx_mark_addressable (slot);
3476 CALL_EXPR_ARG (call_expr, 0) =
3477 build1 (ADDR_EXPR, build_pointer_type (type), slot);
3479 else if (style == arg)
3481 /* Just mark it addressable here, and leave the rest to
3482 expand_call{,_inline}. */
3483 cxx_mark_addressable (slot);
3484 CALL_EXPR_RETURN_SLOT_OPT (call_expr) = true;
3485 call_expr = build2 (INIT_EXPR, TREE_TYPE (call_expr), slot, call_expr);
3487 else if (style == pcc)
3489 /* If we're using the non-reentrant PCC calling convention, then we
3490 need to copy the returned value out of the static buffer into the
3492 push_deferring_access_checks (dk_no_check);
3493 call_expr = build_aggr_init (slot, call_expr,
3494 DIRECT_BIND | LOOKUP_ONLYCONVERTING,
3495 tf_warning_or_error);
3496 pop_deferring_access_checks ();
3497 call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (slot), call_expr, slot);
3500 if (AGGR_INIT_ZERO_FIRST (aggr_init_expr))
3502 tree init = build_zero_init (type, NULL_TREE,
3503 /*static_storage_p=*/false);
3504 init = build2 (INIT_EXPR, void_type_node, slot, init);
3505 call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (call_expr),
3512 /* Emit all thunks to FN that should be emitted when FN is emitted. */
3515 emit_associated_thunks (tree fn)
3517 /* When we use vcall offsets, we emit thunks with the virtual
3518 functions to which they thunk. The whole point of vcall offsets
3519 is so that you can know statically the entire set of thunks that
3520 will ever be needed for a given virtual function, thereby
3521 enabling you to output all the thunks with the function itself. */
3522 if (DECL_VIRTUAL_P (fn)
3523 /* Do not emit thunks for extern template instantiations. */
3524 && ! DECL_REALLY_EXTERN (fn))
3528 for (thunk = DECL_THUNKS (fn); thunk; thunk = DECL_CHAIN (thunk))
3530 if (!THUNK_ALIAS (thunk))
3532 use_thunk (thunk, /*emit_p=*/1);
3533 if (DECL_RESULT_THUNK_P (thunk))
3537 for (probe = DECL_THUNKS (thunk);
3538 probe; probe = DECL_CHAIN (probe))
3539 use_thunk (probe, /*emit_p=*/1);
<