summaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog563
-rw-r--r--gcc/cp/Make-lang.in30
-rw-r--r--gcc/cp/call.c203
-rw-r--r--gcc/cp/class.c513
-rw-r--r--gcc/cp/config-lang.in2
-rw-r--r--gcc/cp/cp-gimplify.c6
-rw-r--r--gcc/cp/cp-lang.c3
-rw-r--r--gcc/cp/cp-objcp-common.c4
-rw-r--r--gcc/cp/cp-objcp-common.h3
-rw-r--r--gcc/cp/cp-tree.def1
-rw-r--r--gcc/cp/cp-tree.h163
-rw-r--r--gcc/cp/cvt.c8
-rw-r--r--gcc/cp/cxx-pretty-print.c20
-rw-r--r--gcc/cp/cxx-pretty-print.h2
-rw-r--r--gcc/cp/decl.c330
-rw-r--r--gcc/cp/decl2.c28
-rw-r--r--gcc/cp/error.c28
-rw-r--r--gcc/cp/except.c206
-rw-r--r--gcc/cp/expr.c4
-rw-r--r--gcc/cp/g++spec.c2
-rw-r--r--gcc/cp/init.c21
-rw-r--r--gcc/cp/lang-specs.h8
-rw-r--r--gcc/cp/lex.c13
-rw-r--r--gcc/cp/method.c779
-rw-r--r--gcc/cp/name-lookup.c50
-rw-r--r--gcc/cp/name-lookup.h2
-rw-r--r--gcc/cp/parser.c153
-rw-r--r--gcc/cp/pt.c187
-rw-r--r--gcc/cp/ptree.c6
-rw-r--r--gcc/cp/repo.c12
-rw-r--r--gcc/cp/rtti.c18
-rw-r--r--gcc/cp/search.c30
-rw-r--r--gcc/cp/semantics.c126
-rw-r--r--gcc/cp/tree.c81
-rw-r--r--gcc/cp/typeck.c225
-rw-r--r--gcc/cp/typeck2.c44
36 files changed, 2800 insertions, 1074 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 48a4613b477..27e7f7a5ff3 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,565 @@
+2010-07-01 Richard Guenther <rguenther@suse.de>
+
+ * cp-gimplify.c (cp_gimplify_expr): Open-code the rhs
+ predicate we are looking for, allow non-gimplified
+ INDIRECT_REFs.
+
+2010-06-30 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR c++/44628
+ * typeck.c (cp_build_unary_op): Early return error_mark_node when
+ arg is NULL_TREE too.
+ * call.c (convert_class_to_reference): Return error_mark_node when
+ expr is NULL_TREE.
+
+2010-06-30 Michael Matz <matz@suse.de>
+
+ * repo.c (finish_repo): Fix typo.
+
+2010-06-30 Nathan Froyd <froydnj@codesourcery.com>
+
+ * parser.c (cp_parser_omp_for_loop): Use a VEC for for_block.
+
+2010-06-30 Nathan Froyd <froydnj@codesourcery.com>
+
+ * repo.c (pending_repo): Change type to a VEC.
+ (finish_repo): Adjust for new type of pending_repo.
+ (repo_emit_p): Likewise.
+
+2010-06-30 Manuel López-Ibáñez <manu@gcc.gnu.org>
+
+ * tree.c: Include gimple.h. Do not include tree-flow.h
+ * decl.c: Do not include tree-flow.h
+ * Make-lang.in: Adjust dependencies.
+
+2010-06-29 Nathan Froyd <froydnj@codesourcery.com>
+
+ * decl.c (incomplete_var): Declare. Declare VECs containing them.
+ (incomplete_vars): Adjust comment. Change type to a VEC.
+ (maybe_register_incomplete_var): Adjust for new type.
+ (complete_vars): Adjust iteration over incomplete_vars.
+
+2010-06-29 Nathan Froyd <froydnj@codesourcery.com>
+
+ * decl.c (struct named_label_entry): Change type of bad_decls field
+ to a VEC.
+ (poplevel_named_label_1): Adjust for new type of bad_decls.
+ (check_goto): Likewise.
+
+2010-06-29 Jason Merrill <jason@redhat.com>
+
+ Enable implicitly declared move constructor/operator= (N3053).
+ * class.c (add_implicitly_declared_members): A class with no
+ explicitly declared copy or move constructor gets both declared
+ implicitly, and similarly for operator=.
+ (check_bases): A type with no copy ctor does not inhibit
+ a const copy ctor in a derived class. It does mean the derived
+ one is non-trivial.
+ (check_field_decl): Likewise.
+ (check_bases_and_members): A nonexistent copy ctor/op= is non-trivial.
+ * tree.c (type_has_nontrivial_copy_init): Adjust semantics.
+ (trivially_copyable_p): Likewise.
+ * call.c (convert_like_real): Use type_has_nontrivial_copy_init.
+ * class.c (finish_struct_bits): Likewise.
+ * tree.c (build_target_expr_with_type): Likewise.
+ * typeck2.c (store_init_value): Likewise.
+
+ Enable implicitly deleted functions (N2346)
+ * class.c (check_bases_and_members): Adjust lambda flags.
+ * method.c (implicitly_declare_fn): Set DECL_DELETED_FN if appropriate.
+
+ * decl2.c (mark_used): Adjust error for use of deleted function.
+
+ Machinery to support implicit delete/move.
+ * cp-tree.h: (struct lang_type_class): Add lazy_move_assign,
+ has_complex_move_ctor, has_complex_move_assign bitfields.
+ (CLASSTYPE_LAZY_MOVE_ASSIGN): New.
+ (TYPE_HAS_COMPLEX_MOVE_ASSIGN): New.
+ (TYPE_HAS_COMPLEX_MOVE_CTOR): New.
+ (enum special_function_kind): Add sfk_move_assignment.
+ (LOOKUP_SPECULATIVE): New.
+ * call.c (build_over_call): Return early if it's set.
+ (build_over_call): Use trivial_fn_p.
+ * class.c (check_bases): If the base has no default constructor,
+ the derived one is non-trivial. Handle move ctor/op=.
+ (check_field_decl): Likewise.
+ (check_bases_and_members): Handle move ctor/op=.
+ (add_implicitly_declared_members): Handle CLASSTYPE_LAZY_MOVE_ASSIGN.
+ (type_has_move_constructor, type_has_move_assign): New.
+ * decl.c (grok_special_member_properties): Handle move ctor/op=.
+ * method.c (type_has_trivial_fn, type_set_nontrivial_flag): New.
+ (trivial_fn_p): New.
+ (do_build_copy_constructor): Use it.
+ (do_build_assign_ref): Likewise. Handle move assignment.
+ (build_stub_type, build_stub_object, locate_fn_flags): New.
+ (locate_ctor): Use locate_fn_flags.
+ (locate_copy, locate_dtor): Remove.
+ (get_dtor, get_default_ctor, get_copy_ctor, get_copy_assign): New.
+ (process_subob_fn, synthesized_method_walk): New.
+ (maybe_explain_implicit_delete): New.
+ (implicitly_declare_fn): Use synthesized_method_walk,
+ type_has_trivial_fn, and type_set_nontrivial_flag.
+ (defaulted_late_check): Set DECL_DELETED_FN.
+ (defaultable_fn_check): Handle sfk_move_assignment.
+ (lazily_declare_fn): Clear CLASSTYPE_LAZY_* early. Don't declare
+ implicitly deleted move ctor/op=.
+ * search.c (lookup_fnfields_1): Handle sfk_move_assignment.
+ (lookup_fnfields_slot): New.
+ * semantics.c (omp_clause_info_fndecl): Remove.
+ (cxx_omp_create_clause_info): Use get_default_ctor, get_copy_ctor,
+ get_copy_assign, trivial_fn_p.
+ (trait_expr_value): Adjust call to locate_ctor.
+ * tree.c (special_function_p): Handle sfk_move_assignment.
+
+ * class.c (type_has_virtual_destructor): New.
+ * cp-tree.h: Declare it.
+ * semantics.c (trait_expr_value): Use it.
+
+ * call.c (build_over_call): Only give warnings with tf_warning.
+
+ * name-lookup.c (pop_scope): Handle NULL_TREE.
+
+ * cp-tree.h (TYPE_HAS_ASSIGN_REF): Rename to TYPE_HAS_COPY_ASSIGN.
+ (TYPE_HAS_CONST_ASSIGN_REF): Rename to TYPE_HAS_CONST_COPY_ASSIGN.
+ (TYPE_HAS_INIT_REF): Rename to TYPE_HAS_COPY_CTOR.
+ (TYPE_HAS_CONST_INIT_REF): Rename to TYPE_HAS_CONST_COPY_CTOR.
+ (TYPE_HAS_COMPLEX_ASSIGN_REF): Rename to TYPE_HAS_COMPLEX_COPY_ASSIGN.
+ (TYPE_HAS_COMPLEX_INIT_REF): Rename to TYPE_HAS_COMPLEX_COPY_CTOR.
+ (TYPE_HAS_TRIVIAL_ASSIGN_REF): Rename to TYPE_HAS_TRIVIAL_COPY_ASSIGN.
+ (TYPE_HAS_TRIVIAL_INIT_REF): Rename to TYPE_HAS_TRIVIAL_COPY_CTOR.
+ (CLASSTYPE_LAZY_ASSIGNMENT_OP): Rename to CLASSTYPE_LAZY_COPY_ASSIGN.
+ (sfk_assignment_operator): Rename to sfk_copy_assignment.
+ * decl.c, call.c, class.c, init.c, method.c, pt.c, ptree.c: Adjust.
+ * search.c, semantics.c, tree.c: Adjust.
+
+ * pt.c (dependent_scope_ref_p): Remove.
+ (value_dependent_expression_p): Don't call it.
+ (type_dependent_expression_p): Here either.
+ * init.c (build_offset_ref): Set TREE_TYPE on a qualified-id
+ if the scope isn't dependent.
+
+ * pt.c (convert_nontype_argument): Use mark_lvalue_use if we want
+ a reference.
+
+ PR c++/44587
+ * pt.c (has_value_dependent_address): New.
+ (value_dependent_expression_p): Check it.
+ (convert_nontype_argument): Likewise. Call decay_conversion before
+ folding if we want a pointer.
+ * semantics.c (finish_id_expression): Don't add SCOPE_REF if the
+ scope is the current instantiation.
+
+2010-06-28 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/44682
+ * class.c (build_base_path): If want_pointer, call mark_rvalue_use
+ on expr.
+
+2010-06-28 Steven Bosscher <steven@gcc.gnu.org>
+
+ * init.c: Do not include except.h.
+ * decl.c: Likewise.
+ * expr.c: Likewise.
+ * cp-lang.c: Likewise.
+ * pt.c: Likewise.
+ * semantics.c: Likewise.
+ * decl2.c: Likewise.
+ * except.c: Likewise.
+ (init_exception_processing): Do not set the removed
+ lang_protect_cleanup_actions here.
+ (cp_protect_cleanup_actions): Make non-static and remove prototype.
+ (doing_eh): New, moved from except.c but removed the do_warning flag.
+ (expand_start_catch_block): Update doing_eh call.
+ (expand_end_catch_block): Likewise.
+ (build_throw): Likewise.
+ * cp-tree.h: Prototype cp_protect_cleanup_actions.
+ * cp-objcp-common.h: Set LANG_HOOKS_EH_PROTECT_CLEANUP_ACTIONS to
+ cp_protect_cleanup_actions.
+ * Make-lang.in: Update dependencies.
+
+2010-06-26 Jason Merrill <jason@redhat.com>
+
+ * call.c (add_function_candidate): Set LOOKUP_COPY_PARM for any
+ constructor called with a single argument that takes a reference
+ to the constructor's class.
+ (BAD_CONVERSION_RANK): New.
+ (compare_ics): Use it to compare bad ICSes.
+
+2010-06-25 Joseph Myers <joseph@codesourcery.com>
+
+ * lang-specs.h: Remove +e handling.
+
+2010-06-24 Andi Kleen <ak@linux.intel.com>
+
+ * parser.c: (cp_parser_question_colon_clause):
+ Switch to use cp_lexer_peek_token.
+ Call warn_for_omitted_condop. Call pedwarn for omitted
+ middle operand.
+
+2010-06-22 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/44619
+ * typeck2.c (build_m_component_ref): Call mark_lvalue_use on
+ datum and mark_rvalue_use on component.
+
+ PR c++/44627
+ * error.c (dump_expr): Don't look at CALL_EXPR_ARG (t, 0) if
+ the CALL_EXPR has no arguments.
+
+2010-06-21 Jason Merrill <jason@redhat.com>
+
+ * typeck.c (comp_except_specs): Fix ce_derived with noexcept.
+
+ * semantics.c (check_trait_type): Check COMPLETE_TYPE_P for array
+ element type.
+
+2010-06-17 Nathan Froyd <froydnj@codesourcery.com>
+
+ * name-lookup.c (struct arg_lookup): Convert namespaces and
+ classes fields to VEC.
+ (arg_assoc_namespace): Adjust for new type of namespaces.
+ (arg_assoc_class): Adjust for new type of classes.
+ (lookup_arg_dependent): Use make_tree_vector and
+ release_tree_vector.
+ * typeck2.c (build_x_arrow): Use vec_member.
+
+2010-06-17 Manuel López-Ibáñez <manu@gcc.gnu.org>
+
+ PR c++/44486
+ * error.c (dump_decl): Better wording for anonymous namespace.
+
+2010-06-16 Nathan Froyd <froydnj@codesourcery.com>
+
+ * class.c (build_vtbl_initializer): Adjust computation of new_position
+ and which entry to add padding for.
+
+2010-06-16 Jason Merrill <jason@redhat.com>
+
+ * except.c (check_noexcept_r): Return the problematic function.
+ (finish_noexcept_expr): Give -Wnoexcept warning. Add complain parm.
+ * pt.c (tsubst_copy_and_build): Pass it.
+ * parser.c (cp_parser_unary_expression): Likewise.
+ * cp-tree.h: Adjust prototype.
+
+ * method.c (defaulted_late_check): Give the defaulted method
+ the same exception specification as the implicit declaration.
+
+2010-06-15 Jason Merrill <jason@redhat.com>
+
+ * class.c (add_implicitly_declared_members): Implicit assignment
+ operators can also be virtual overriders.
+ * method.c (lazily_declare_fn): Likewise.
+
+ * call.c (convert_like_real): Give "initializing argument of"
+ information for ambiguous conversion. Give source position
+ of function.
+
+ * call.c (print_z_candidates): Do print viable deleted candidates.
+ (joust): Don't choose a deleted function just because its worst
+ conversion is better than another candidate's worst.
+
+ * call.c (convert_like_real): Don't complain about
+ list-value-initialization from an explicit constructor.
+
+ * decl.c (duplicate_decls): Use DECL_IS_BUILTIN rather than test
+ DECL_SOURCE_LOCATION directly.
+
+ * class.c (type_has_user_provided_default_constructor): Use
+ sufficient_parms_p.
+
+ * call.c (is_subseq): Handle ck_aggr, ck_list.
+ (compare_ics): Treat an aggregate or ambiguous conversion to the
+ same type as involving the same function.
+
+2010-06-13 Shujing Zhao <pearly.zhao@oracle.com>
+
+ * typeck.c (convert_for_assignment): Fix comment. Change message
+ format from %d to %qP.
+ (convert_for_initialization): Fix comment.
+
+2010-06-11 Shujing Zhao <pearly.zhao@oracle.com>
+
+ * cp-tree.h (expr_list_kind): New type.
+ (impl_conv_rhs): New type.
+ (build_x_compound_expr_from_list, convert_for_initialization): Adjust
+ prototype.
+ (typeck.c (convert_arguments): Use impl_conv_rhs and emit the
+ diagnostics for easy translation. Change caller.
+ (convert_for_initialization): Use impl_conv_rhs and change caller.
+ (build_x_compound_expr_from_list): Use expr_list_kind and emit the
+ diagnostics for easy translation. Change caller.
+ * decl.c (bad_spec_place): New enum.
+ (bad_specifiers): Use it and emit the diagnostics for easy
+ translation. Change caller.
+ * pt.c (coerce_template_parms): Put the diagnostics in full sentence.
+
+2010-06-09 Nathan Froyd <froydnj@codesourcery.com>
+
+ * cp-tree.h (struct saved_scope): Change decl_ns_list field type
+ to a VEC.
+ * decl2.c (cp_write_global_declarations): Adjust for new type of
+ decl_namespace_list.
+ * name-lookup.c (current_decl_namespace): Likewise.
+ (push_decl_namespace): Likewise.
+ (pop_decl_namespace): Likewise.
+
+2010-06-09 Nathan Froyd <froydnj@codesourcery.com>
+
+ * call.c (build_java_interface_fn_ref): Call build_function_type_list
+ instead of build_function_type.
+ * decl.c (cxx_init_decl_processing): Likewise.
+ (declare_global_var): Likewise.
+ (get_atexit_node): Likewise.
+ (expand_static_init): Likewise.
+ * decl2.c (start_objects): Likewise.
+ (start_static_storage_duration_function): Likewise.
+ * except.c (init_exception_processing): Likewise.
+ (build_exc_ptr): Likewise.
+ (build_throw): Likewise.
+ * rtti.c (throw_bad_cast): Likewise.
+ (throw_bad_typeid): Likewise.
+ (build_dynamic_cast_1): Likewise.
+
+2010-06-09 Nathan Froyd <froydnj@codesourcery.com>
+
+ * call.c (build_call_n): Call XALLOCAVEC instead of alloca.
+ (build_op_delete_call): Likewise.
+ (build_over_call): Likewise.
+ * cp-gimplify.c (cxx_omp_clause_apply_fn): Likewise.
+ * pt.c (process_partial_specialization): Likewise.
+ (tsubst_template_args): Likewise.
+ * semantics.c (finish_asm_stmt): Likewise.
+
+2010-06-08 Nathan Sidwell <nathan@codesourcery.com>
+
+ * decl.c (record_key_method_defined): New, broken out of ...
+ (finish_function): ... here. Call it.
+ (start_decl): Treat aliases as definitions.
+
+2010-06-08 Laurynas Biveinis <laurynas.biveinis@gmail.com>
+
+ * typeck2.c (abstract_virtuals_error): Use typed GC allocation.
+
+ * pt.c (maybe_process_partial_specialization): Likewise.
+ (register_specialization): Likewise.
+ (add_pending_template): Likewise.
+ (lookup_template_class): Likewise.
+ (push_tinst_level): Likewise.
+
+ * parser.c (cp_lexer_new_main): Likewise.
+ (cp_lexer_new_from_tokens): Likewise.
+ (cp_token_cache_new): Likewise.
+ (cp_parser_context_new): Likewise.
+ (cp_parser_new): Likewise.
+ (cp_parser_nested_name_specifier_opt): Likewise.
+ (cp_parser_template_id): Likewise.
+
+ * name-lookup.c (binding_entry_make): Likewise.
+ (binding_table_construct): Likewise.
+ (binding_table_new): Likewise.
+ (cxx_binding_make): Likewise.
+ (pushdecl_maybe_friend): Likewise.
+ (begin_scope): Likewise.
+ (push_to_top_level): Likewise.
+
+ * lex.c (init_reswords): Likewise.
+ (retrofit_lang_decl): Likewise.
+ (cxx_dup_lang_specific_decl): Likewise.
+ (copy_lang_type): Likewise.
+ (cxx_make_type): Likewise.
+
+ * decl.c (make_label_decl): Likewise.
+ (check_goto): Likewise.
+ (start_preparsed_function): Likewise.
+ (save_function_data): Likewise.
+
+ * cp-tree.h (TYPE_SET_PTRMEMFUNC_TYPE): Likewise.
+
+ * cp-objcp-common.c (decl_shadowed_for_var_insert): Likewise.
+
+ * class.c (finish_struct_1): Likewise.
+
+ * cp-tree.h (struct lang_type): Add variable_size GTY option.
+ (struct lang_decl): Likewise.
+
+ * parser.c (cp_parser_new): Update comment to not reference
+ ggc_alloc.
+
+2010-06-07 Jason Merrill <jason@redhat.com>
+
+ PR c++/44366
+ * error.c (dump_parameters): Mask out TFF_SCOPE.
+ (dump_simple_decl): Don't print the scope of a PARM_DECL.
+ (dump_scope): Remove no-op mask.
+
+ PR c++/44401
+ * parser.c (cp_parser_lookup_name): Fix naming the constructor.
+
+ * cp-tree.h (COMPLETE_OR_OPEN_TYPE_P): New macro.
+ * init.c (build_offset_ref): Use it.
+ * pt.c (maybe_process_partial_specialization): Use it.
+ (instantiate_class_template): Use it.
+ * search.c (lookup_base): Use it.
+
+2010-06-07 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/44444
+ * expr.c (mark_exp_read): Handle INDIRECT_REF.
+ * cvt.c (convert_to_void): Handle INDIRECT_REF like
+ handled_component_p.
+
+ PR c++/44443
+ * decl.c (initialize_local_var): If TREE_USED is set on the type,
+ set also DECL_READ_P on the decl.
+
+2010-05-25 Dodji Seketeli <dodji@redhat.com>
+
+ PR c++/44188
+ * cp-tree.h (typedef_variant_p): Move this declaration to
+ gcc/tree.h.
+ * tree.c (typedef_variant_p): Move this definition to gcc/tree.c.
+ * decl.c (grokdeclarator): Do not rename debug info of an
+ anonymous tagged type named by a typedef.
+
+2010-06-05 Fabien Chêne <fabien@gcc.gnu.org>
+
+ PR c++/44086
+ * class.c (check_field_decls): Move the call to
+ check_bitfield_decl before trying to set the
+ CLASSTYPE_READONLY_FIELDS_NEED_INIT flag.
+
+2010-06-05 Steven Bosscher <steven@gcc.gnu.org>
+
+ * typeck.c: Update include path for moved files.
+ * decl.c: Likewise.
+ * rtti.c: Likewise.
+ * cp-gimplify.c: Likewise.
+ * cp-lang.c: Likewise.
+ * pt.c: Likewise.
+ * semantics.c: Likewise.
+ * cxx-pretty-print.h: Likewise.
+ * decl2.c: Likewise.
+ * parser.c: Likewise.
+ * cp-objcp-common.c: Likewise.
+ * cp-tree.h: Likewise.
+ * name-lookup.c: Likewise.
+ * lex.c: Likewise.
+ * name-lookup.h: Likewise.
+ * config-lang.in: Update paths in gtfiles for files in c-family/.
+ * Make-lang.in: Likewise.
+
+2010-06-04 Magnus Fromreide <magfr@lysator.liu.se>
+
+ * cvt.c (cp_convert_to_pointer): Use null_ptr_cst_p.
+ * typeck.c (build_ptrmemfunc): Likewise.
+
+2010-06-04 Jason Merrill <jason@redhat.com>
+
+ * typeck2.c (merge_exception_specifiers): Adjust merging of
+ throw() and noexcept(true).
+
+ * pt.c (value_dependent_expression_p) [NOEXCEPT_EXPR]: Avoid
+ using an uninitialized variable.
+
+ * cxx-pretty-print.c (pp_cxx_unary_expression): Handle NOEXCEPT_EXPR.
+ (pp_cxx_expression): Likewise.
+
+ Implement noexcept-specification (15.4)
+ * parser.c (cp_parser_exception_specification_opt): Parse it.
+ Give -Wdeprecated warning about throw() specs.
+ * pt.c (tsubst_exception_specification): Handle it.
+ * error.c (dump_exception_spec): Handle it.
+ (dump_expr): Handle NOEXCEPT_EXPR.
+ * cxx-pretty-print.c (pp_cxx_exception_specification): Likewise.
+ * typeck.c (comp_except_specs): Handle compatibility rules.
+ Change exact parm to take an enum.
+ * typeck2.c (merge_exception_specifiers): Handle noexcept.
+ * except.c (nothrow_spec_p, type_noexcept_p): New fns.
+ (type_throw_all_p, build_noexcept_spec): New fns.
+ * cp-tree.h (TYPE_NOTHROW_P, TYPE_NOEXCEPT_P): Use them.
+ (comp_except_specs): Define ce_derived, ce_normal, ce_exact enums.
+ (cp_tree_index): Add CPTI_NOEXCEPT_TRUE_SPEC, CPTI_NOEXCEPT_FALSE_SPEC.
+ (noexcept_true_spec, noexcept_false_spec): New macros.
+ * name-lookup.c (pushdecl_maybe_friend): Adjust.
+ * search.c (check_final_overrider): Adjust.
+ * decl.c (check_redeclaration_exception_specification): Adjust.
+ (use_eh_spec_block): Use type_throw_all_p.
+ (cxx_init_decl_processing): Set noexcept_false_spec,noexcept_true_spec.
+ Give operator new a noexcept-specification in C++0x mode.
+ * tree.c (build_exception_variant, cxx_type_hash_eq): Adjust.
+ (cp_build_type_attribute_variant): Don't test TYPE_RAISES_EXCEPTIONS.
+
+ Implement noexcept operator (5.3.7)
+ * cp-tree.def (NOEXCEPT_EXPR): New.
+ * except.c (check_noexcept_r, finish_noexcept_expr): New.
+ * cp-tree.h: Declare finish_noexcept_expr.
+ * parser.c (cp_parser_unary_expression): Parse noexcept-expression.
+ * pt.c (tsubst_copy_and_build): And tsubst it.
+ (type_dependent_expression_p): Handle it.
+ (value_dependent_expression_p): Handle it.
+
+ * call.c (build_conditional_expr): Never fold in unevaluated context.
+ * tree.c (build_aggr_init_expr): Propagate TREE_NOTHROW.
+ * semantics.c (simplify_aggr_init_expr): Likewise.
+ * typeck.c (merge_types): Call merge_exception_specifiers.
+ * decl.c (duplicate_decls): Check DECL_SOURCE_LOCATION rather than
+ DECL_ANTICIPATED for preferring new type.
+
+2010-06-04 Joseph Myers <joseph@codesourcery.com>
+
+ * g++spec.c (lang_specific_driver): Use GCC-specific formats in
+ diagnostics.
+
+2010-06-04 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/44412
+ * typeck.c (build_class_member_access_expr): Call mark_exp_read
+ on object for static data members.
+
+2010-06-04 Jakub Jelinek <jakub@redhat.com>
+ Jason Merrill <jason@redhat.com>
+
+ PR c++/44362
+ * call.c (build_conditional_expr): If both arg2 and arg3 are lvalues
+ with the same type, call mark_lvalue_use on both.
+
+2010-06-03 Nathan Froyd <froydnj@codesourcery.com>
+
+ * class.c (struct vtbl_init_data_s): Remove last_init field.
+ (struct secondary_vptr_vtt_init_data_s): Change type of inits field
+ to a VEC.
+ (finish_vtbls): Use a VEC rather than a TREE_LIST for the accumulated
+ initializers.
+ (build_vtt): Likewise.
+ (initialize_vtable): Take a VEC instead of a tree.
+ (build_vtt_inits): Change return type to void. Take a VEC **
+ instead of a tree *; accumulate results into said VEC.
+ (build_ctor_vtbl_group): Use a VEC rather than a TREE_LIST for the
+ accumulated initializers. Pass the vtable to accumulate_vtbl_inits.
+ (accumulate_vtbl_inits): Add extra vtable tree parameter; take a VEC
+ instead of a tree.
+ (dfs_accumulate_vtbl_inits): Likewise. Change return type to void.
+ (build_vtbl_initializer): Add VEC parameter; accumulate initializers
+ into it.
+ (dfs_build_secondary_vptr_vtt_inits): Use CONSTRUCTOR_APPEND_ELT
+ rather than tree_cons.
+ (build_vbase_offset_vtbl_entries): Likewise.
+ (add_vcall_offset): Likewise.
+ (build_rtti_vtbl_entries): Likewise.
+ * cp-tree.h (initialize_artificial_var): Take a VEC instead of a tree.
+ * decl.c (initialize_artificial_var): Use build_constructor instead
+ of build_constructor_from_list.
+
+2010-06-03 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR c++/44294
+ * class.c (layout_class_type): Check MAX_FIXED_MODE_SIZE on
+ bit-field.
+
+2010-06-02 Jonathan Wakely <jwakely.gcc@gmail.com>
+
+ * parser.c (cp_parser_mem_initializer_list): Change error text.
+
2010-06-02 Jakub Jelinek <jakub@redhat.com>
* cp-objcp-common.c (shadowed_var_for_decl): Change into
@@ -1469,3 +2031,4 @@ Copyright (C) 2010 Free Software Foundation, Inc.
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.
+
diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in
index d726ead2d80..7a605b743aa 100644
--- a/gcc/cp/Make-lang.in
+++ b/gcc/cp/Make-lang.in
@@ -71,10 +71,8 @@ g++-cross$(exeext): g++$(exeext)
# The compiler itself.
# Shared with C front end:
-CXX_C_OBJS = attribs.o c-common.o c-format.o c-pragma.o c-semantics.o c-lex.o \
- c-dump.o $(CXX_TARGET_OBJS) c-pretty-print.o c-opts.o c-pch.o \
- incpath.o c-ppoutput.o c-cppbuiltin.o prefix.o \
- c-gimplify.o c-omp.o c-ada-spec.o
+CXX_C_OBJS = attribs.o incpath.o prefix.o \
+ $(C_COMMON_OBJS) $(CXX_TARGET_OBJS)
# Language-specific object files for C++ and Objective C++.
CXX_AND_OBJCXX_OBJS = cp/call.o cp/decl.o cp/expr.o cp/pt.o cp/typeck2.o \
@@ -85,7 +83,7 @@ CXX_AND_OBJCXX_OBJS = cp/call.o cp/decl.o cp/expr.o cp/pt.o cp/typeck2.o \
cp/cp-gimplify.o tree-mudflap.o $(CXX_C_OBJS)
# Language-specific object files for C++.
-CXX_OBJS = cp/cp-lang.o stub-objc.o $(CXX_AND_OBJCXX_OBJS)
+CXX_OBJS = cp/cp-lang.o c-family/stub-objc.o $(CXX_AND_OBJCXX_OBJS)
c++_OBJS = $(CXX_OBJS) dummy-checksum.o cc1plus-checksum.o cp/g++spec.o
@@ -251,16 +249,16 @@ cp/lex.o: cp/lex.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) \
$(C_PRAGMA_H) toplev.h output.h input.h cp/operators.def $(TM_P_H)
cp/cp-lang.o: cp/cp-lang.c $(CXX_TREE_H) $(TM_H) toplev.h debug.h langhooks.h \
$(LANGHOOKS_DEF_H) $(C_COMMON_H) gtype-cp.h gt-cp-cp-lang.h \
- cp/cp-objcp-common.h $(EXPR_H) $(EXCEPT_H)
+ cp/cp-objcp-common.h $(EXPR_H)
cp/decl.o: cp/decl.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) cp/decl.h \
- output.h $(EXCEPT_H) toplev.h $(HASHTAB_H) $(RTL_H) \
+ output.h toplev.h $(HASHTAB_H) $(RTL_H) \
cp/operators.def $(TM_P_H) $(TREE_INLINE_H) $(DIAGNOSTIC_H) $(C_PRAGMA_H) \
- debug.h gt-cp-decl.h $(TIMEVAR_H) $(TREE_FLOW_H) $(TARGET_H) $(PLUGIN_H) \
+ debug.h gt-cp-decl.h $(TIMEVAR_H) $(TARGET_H) $(PLUGIN_H) \
intl.h tree-iterator.h $(SPLAY_TREE_H)
cp/decl2.o: cp/decl2.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) cp/decl.h \
- output.h $(EXCEPT_H) toplev.h $(C_COMMON_H) gt-cp-decl2.h $(CGRAPH_H) \
+ output.h toplev.h $(C_COMMON_H) gt-cp-decl2.h $(CGRAPH_H) \
$(C_PRAGMA_H) $(TREE_DUMP_H) intl.h $(TARGET_H) $(GIMPLE_H) $(POINTER_SET_H) \
- $(SPLAY_TREE_H) c-ada-spec.h
+ $(SPLAY_TREE_H) c-family/c-ada-spec.h
cp/cp-objcp-common.o : cp/cp-objcp-common.c $(CONFIG_H) $(SYSTEM_H) \
coretypes.h $(TM_H) $(TREE_H) $(CXX_TREE_H) $(C_COMMON_H) toplev.h \
langhooks.h $(LANGHOOKS_DEF_H) $(DIAGNOSTIC_H) debug.h \
@@ -286,23 +284,21 @@ cp/search.o: cp/search.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) toplev.h \
intl.h
cp/tree.o: cp/tree.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) toplev.h \
$(TREE_INLINE_H) $(REAL_H) gt-cp-tree.h \
- $(TARGET_H) debug.h $(TREE_FLOW_H) $(CGRAPH_H) $(SPLAY_TREE_H)
+ $(TARGET_H) debug.h $(CGRAPH_H) $(SPLAY_TREE_H) $(GIMPLE_H)
cp/ptree.o: cp/ptree.c $(CXX_TREE_H) $(TM_H)
cp/rtti.o: cp/rtti.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) toplev.h convert.h \
$(TARGET_H) $(C_PRAGMA_H) gt-cp-rtti.h intl.h
-cp/except.o: cp/except.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) $(EXCEPT_H) \
+cp/except.o: cp/except.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) \
toplev.h cp/cfns.h $(TREE_INLINE_H) $(TARGET_H)
-cp/expr.o: cp/expr.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) \
- toplev.h $(EXCEPT_H) $(TM_P_H)
+cp/expr.o: cp/expr.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) toplev.h $(TM_P_H)
cp/pt.o: cp/pt.c $(CXX_TREE_H) $(TM_H) cp/decl.h cp/cp-objcp-common.h \
- toplev.h $(EXCEPT_H) $(TREE_INLINE_H) pointer-set.h gt-cp-pt.h \
- vecprim.h intl.h
+ toplev.h $(TREE_INLINE_H) pointer-set.h gt-cp-pt.h vecprim.h intl.h
cp/error.o: cp/error.c $(CXX_TREE_H) $(TM_H) toplev.h $(DIAGNOSTIC_H) \
$(FLAGS_H) $(REAL_H) $(LANGHOOKS_DEF_H) $(CXX_PRETTY_PRINT_H) \
tree-diagnostic.h tree-pretty-print.h
cp/repo.o: cp/repo.c $(CXX_TREE_H) $(TM_H) toplev.h $(DIAGNOSTIC_CORE_H) \
gt-cp-repo.h
-cp/semantics.o: cp/semantics.c $(CXX_TREE_H) $(TM_H) $(EXCEPT_H) toplev.h \
+cp/semantics.o: cp/semantics.c $(CXX_TREE_H) $(TM_H) toplev.h \
$(FLAGS_H) output.h $(RTL_H) $(TIMEVAR_H) \
$(TREE_INLINE_H) $(CGRAPH_H) $(TARGET_H) $(C_COMMON_H) $(GIMPLE_H) \
bitmap.h gt-cp-semantics.h
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index b9f1c7fd4ec..d03ecb161af 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -122,6 +122,11 @@ struct conversion {
: (NODE)->user_conv_p ? cr_user \
: (NODE)->rank)
+#define BAD_CONVERSION_RANK(NODE) \
+ ((NODE)->ellipsis_p ? cr_ellipsis \
+ : (NODE)->user_conv_p ? cr_user \
+ : (NODE)->rank)
+
static struct obstack conversion_obstack;
static bool conversion_obstack_initialized;
@@ -282,7 +287,7 @@ build_call_n (tree function, int n, ...)
return build_call_a (function, 0, NULL);
else
{
- tree *argarray = (tree *) alloca (n * sizeof (tree));
+ tree *argarray = XALLOCAVEC (tree, n);
va_list ap;
int i;
@@ -1035,6 +1040,9 @@ convert_class_to_reference (tree reference_type, tree s, tree expr, int flags)
struct z_candidate *cand;
bool any_viable_p;
+ if (!expr)
+ return NULL;
+
conversions = lookup_conversions (s, /*lookup_template_convs_p=*/true);
if (!conversions)
return NULL;
@@ -1386,9 +1394,12 @@ reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags)
conversion operator). */
flags |= LOOKUP_NO_TEMP_BIND;
- /* Temporaries are copy-initialized, except for this hack to allow
- explicit conversion ops to the copy ctor. See also
- add_function_candidate. */
+ /* Core issue 899: When [copy-]initializing a temporary to be bound
+ to the first parameter of a copy constructor (12.8) called with
+ a single argument in the context of direct-initialization,
+ explicit conversion functions are also considered.
+
+ So don't set LOOKUP_ONLYCONVERTING in that case. */
if (!(flags & LOOKUP_COPY_PARM))
flags |= LOOKUP_ONLYCONVERTING;
@@ -1618,6 +1629,8 @@ add_function_candidate (struct z_candidate **candidates,
tree parmtype = TREE_VALUE (parmnode);
int lflags = flags;
+ parmnode = TREE_CHAIN (parmnode);
+
/* The type of the implicit object parameter ('this') for
overload resolution is not always the same as for the
function itself; conversion functions are considered to
@@ -1634,13 +1647,25 @@ add_function_candidate (struct z_candidate **candidates,
parmtype = build_pointer_type (parmtype);
}
- if (ctype && i == 0 && DECL_COPY_CONSTRUCTOR_P (fn)
- && (len-skip == 1))
+ /* Core issue 899: When [copy-]initializing a temporary to be bound
+ to the first parameter of a copy constructor (12.8) called with
+ a single argument in the context of direct-initialization,
+ explicit conversion functions are also considered.
+
+ So set LOOKUP_COPY_PARM to let reference_binding know that
+ it's being called in that context. We generalize the above
+ to handle move constructors and template constructors as well;
+ the standardese should soon be updated similarly. */
+ if (ctype && i == 0 && (len-skip == 1)
+ && !(flags & LOOKUP_ONLYCONVERTING)
+ && DECL_CONSTRUCTOR_P (fn)
+ && parmtype != error_mark_node
+ && (same_type_ignoring_top_level_qualifiers_p
+ (non_reference (parmtype), ctype)))
{
- /* Hack: Direct-initialize copy parm (i.e. suppress
- LOOKUP_ONLYCONVERTING) to make explicit conversion ops
- work. See also reference_binding. */
lflags |= LOOKUP_COPY_PARM;
+ /* We allow user-defined conversions within init-lists, but
+ not for the copy constructor. */
if (flags & LOOKUP_NO_COPY_CTOR_CONVERSION)
lflags |= LOOKUP_NO_CONVERSION;
}
@@ -1668,9 +1693,6 @@ add_function_candidate (struct z_candidate **candidates,
if (t->bad_p)
viable = -1;
-
- if (parmnode)
- parmnode = TREE_CHAIN (parmnode);
}
out:
@@ -2747,11 +2769,12 @@ print_z_candidates (struct z_candidate *candidates)
if (!candidates)
return;
- /* Remove deleted candidates. */
+ /* Remove non-viable deleted candidates. */
cand1 = candidates;
for (cand2 = &cand1; *cand2; )
{
if (TREE_CODE ((*cand2)->fn) == FUNCTION_DECL
+ && !(*cand2)->viable
&& DECL_DELETED_FN ((*cand2)->fn))
*cand2 = (*cand2)->next;
else
@@ -3631,7 +3654,6 @@ build_conditional_expr (tree arg1, tree arg2, tree arg3,
tree arg2_type;
tree arg3_type;
tree result = NULL_TREE;
- tree result_save;
tree result_type = NULL_TREE;
bool lvalue_p = true;
struct z_candidate *candidates = 0;
@@ -3839,6 +3861,8 @@ build_conditional_expr (tree arg1, tree arg2, tree arg3,
&& same_type_p (arg2_type, arg3_type))
{
result_type = arg2_type;
+ mark_lvalue_use (arg2);
+ mark_lvalue_use (arg3);
goto valid_operands;
}
@@ -4018,12 +4042,10 @@ build_conditional_expr (tree arg1, tree arg2, tree arg3,
}
valid_operands:
- result_save = build3 (COND_EXPR, result_type, arg1, arg2, arg3);
- result = fold_if_not_in_template (result_save);
-
- if (cp_unevaluated_operand && TREE_CODE (result) == CALL_EXPR)
- /* Avoid folding to a CALL_EXPR within decltype (c++/42013). */
- result = result_save;
+ result = build3 (COND_EXPR, result_type, arg1, arg2, arg3);
+ if (!cp_unevaluated_operand)
+ /* Avoid folding within decltype (c++/42013) and noexcept. */
+ result = fold_if_not_in_template (result);
/* We can't use result_type below, as fold might have returned a
throw_expr. */
@@ -4757,7 +4779,7 @@ build_op_delete_call (enum tree_code code, tree addr, tree size,
/* The placement args might not be suitable for overload
resolution at this point, so build the call directly. */
int nargs = call_expr_nargs (placement);
- tree *argarray = (tree *) alloca (nargs * sizeof (tree));
+ tree *argarray = XALLOCAVEC (tree, nargs);
int i;
argarray[0] = addr;
for (i = 1; i < nargs; i++)
@@ -4934,7 +4956,8 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
{
permerror (input_location, "invalid conversion from %qT to %qT", TREE_TYPE (expr), totype);
if (fn)
- permerror (input_location, " initializing argument %P of %qD", argnum, fn);
+ permerror (DECL_SOURCE_LOCATION (fn),
+ " initializing argument %P of %qD", argnum, fn);
}
else
return error_mark_node;
@@ -4957,7 +4980,10 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
/* When converting from an init list we consider explicit
constructors, but actually trying to call one is an error. */
- if (DECL_NONCONVERTING_P (convfn) && DECL_CONSTRUCTOR_P (convfn))
+ if (DECL_NONCONVERTING_P (convfn) && DECL_CONSTRUCTOR_P (convfn)
+ /* Unless we're calling it for value-initialization from an
+ empty list, since that is handled separately in 8.5.4. */
+ && cand->num_convs > 0)
{
if (complain & tf_error)
error ("converting to %qT from initializer list would use "
@@ -5015,11 +5041,14 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
}
return expr;
case ck_ambig:
- if (!(complain & tf_error))
- return error_mark_node;
- /* Call build_user_type_conversion again for the error. */
- return build_user_type_conversion
- (totype, convs->u.expr, LOOKUP_NORMAL);
+ if (complain & tf_error)
+ {
+ /* Call build_user_type_conversion again for the error. */
+ build_user_type_conversion (totype, convs->u.expr, LOOKUP_NORMAL);
+ if (fn)
+ error (" initializing argument %P of %q+D", argnum, fn);
+ }
+ return error_mark_node;
case ck_list:
{
@@ -5107,7 +5136,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
if (diag_kind && fn)
{
if ((complain & tf_error))
- emit_diagnostic (diag_kind, input_location, 0,
+ emit_diagnostic (diag_kind, DECL_SOURCE_LOCATION (fn), 0,
" initializing argument %P of %qD", argnum, fn);
else if (diag_kind == DK_ERROR)
return error_mark_node;
@@ -5171,7 +5200,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
OK. */
if ((lvalue & clk_packed)
&& CLASS_TYPE_P (type)
- && !TYPE_HAS_TRIVIAL_INIT_REF (type))
+ && type_has_nontrivial_copy_init (type))
{
if (complain & tf_error)
error ("cannot bind packed field %qE to %qT",
@@ -5388,7 +5417,7 @@ convert_default_arg (tree type, tree arg, tree fn, int parmnum)
{
arg = digest_init (type, arg);
arg = convert_for_initialization (0, type, arg, LOOKUP_NORMAL,
- "default argument", fn, parmnum,
+ ICR_DEFAULT_ARGUMENT, fn, parmnum,
tf_warning_or_error);
}
else
@@ -5402,7 +5431,7 @@ convert_default_arg (tree type, tree arg, tree fn, int parmnum)
if (!CONSTANT_CLASS_P (arg))
arg = unshare_expr (arg);
arg = convert_for_initialization (0, type, arg, LOOKUP_NORMAL,
- "default argument", fn, parmnum,
+ ICR_DEFAULT_ARGUMENT, fn, parmnum,
tf_warning_or_error);
arg = convert_for_arg_passing (type, arg);
}
@@ -5574,7 +5603,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
}
/* Give any warnings we noticed during overload resolution. */
- if (cand->warnings)
+ if (cand->warnings && (complain & tf_warning))
{
struct candidate_warning *w;
for (w = cand->warnings; w; w = w->next)
@@ -5587,6 +5616,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
if (DECL_FUNCTION_MEMBER_P (fn))
{
+ tree access_fn;
/* If FN is a template function, two cases must be considered.
For example:
@@ -5614,10 +5644,41 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
different access. */
if (DECL_TEMPLATE_INFO (fn)
&& DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (fn)))
- perform_or_defer_access_check (cand->access_path,
- DECL_TI_TEMPLATE (fn), fn);
+ access_fn = DECL_TI_TEMPLATE (fn);
+ else
+ access_fn = fn;
+ if (flags & LOOKUP_SPECULATIVE)
+ {
+ /* If we're checking for implicit delete, we don't want access
+ control errors. */
+ if (!accessible_p (cand->access_path, access_fn, true))
+ {
+ /* Unless we're under maybe_explain_implicit_delete. */
+ if (flags & LOOKUP_COMPLAIN)
+ enforce_access (cand->access_path, access_fn, fn);
+ return error_mark_node;
+ }
+ }
else
- perform_or_defer_access_check (cand->access_path, fn, fn);
+ perform_or_defer_access_check (cand->access_path, access_fn, fn);
+ }
+
+ /* If we're checking for implicit delete, don't bother with argument
+ conversions. */
+ if (flags & LOOKUP_SPECULATIVE)
+ {
+ if (DECL_DELETED_FN (fn))
+ {
+ if (flags & LOOKUP_COMPLAIN)
+ mark_used (fn);
+ return error_mark_node;
+ }
+ if (cand->viable == 1)
+ return fn;
+ else if (!(flags & LOOKUP_COMPLAIN))
+ /* Reject bad conversions now. */
+ return error_mark_node;
+ /* else continue to get conversion error. */
}
/* Find maximum size of vector to hold converted arguments. */
@@ -5625,7 +5686,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
nargs = VEC_length (tree, args) + (first_arg != NULL_TREE ? 1 : 0);
if (parmlen > nargs)
nargs = parmlen;
- argarray = (tree *) alloca (nargs * sizeof (tree));
+ argarray = XALLOCAVEC (tree, nargs);
/* The implicit parameters to a constructor are not considered by overload
resolution, and must be of the proper type. */
@@ -5798,6 +5859,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
tree targ;
tree arg = argarray[num_artificial_parms_for (fn)];
tree fa;
+ bool trivial = trivial_fn_p (fn);
/* Pull out the real argument, disregarding const-correctness. */
targ = arg;
@@ -5822,13 +5884,12 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
if (TREE_CODE (arg) == TARGET_EXPR
&& TARGET_EXPR_LIST_INIT_P (arg))
{
- /* Copy-list-initialization doesn't require the copy constructor
+ /* Copy-list-initialization doesn't require the constructor
to be defined. */
}
/* [class.copy]: the copy constructor is implicitly defined even if
the implementation elided its use. */
- else if (TYPE_HAS_COMPLEX_INIT_REF (DECL_CONTEXT (fn))
- || move_fn_p (fn))
+ else if (!trivial)
{
mark_used (fn);
already_used = true;
@@ -5846,13 +5907,10 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
{
if (TREE_CODE (arg) == TARGET_EXPR)
return arg;
- else if (TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn))
- && !move_fn_p (fn))
- return build_target_expr_with_type (arg, DECL_CONTEXT (fn));
+ else if (trivial)
+ return force_target_expr (DECL_CONTEXT (fn), arg);
}
- else if (TREE_CODE (arg) == TARGET_EXPR
- || (TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn))
- && !move_fn_p (fn)))
+ else if (TREE_CODE (arg) == TARGET_EXPR || trivial)
{
tree to = stabilize_reference (cp_build_indirect_ref (fa, RO_NULL,
complain));
@@ -5862,8 +5920,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
}
}
else if (DECL_OVERLOADED_OPERATOR_P (fn) == NOP_EXPR
- && copy_fn_p (fn)
- && TYPE_HAS_TRIVIAL_ASSIGN_REF (DECL_CONTEXT (fn)))
+ && trivial_fn_p (fn))
{
tree to = stabilize_reference
(cp_build_indirect_ref (argarray[0], RO_NULL, complain));
@@ -6009,14 +6066,11 @@ build_java_interface_fn_ref (tree fn, tree instance)
if (!java_iface_lookup_fn)
{
- tree endlink = build_void_list_node ();
- tree t = tree_cons (NULL_TREE, ptr_type_node,
- tree_cons (NULL_TREE, ptr_type_node,
- tree_cons (NULL_TREE, java_int_type_node,
- endlink)));
+ tree ftype = build_function_type_list (ptr_type_node,
+ ptr_type_node, ptr_type_node,
+ java_int_type_node, NULL_TREE);
java_iface_lookup_fn
- = add_builtin_function ("_Jv_LookupInterfaceMethodIdx",
- build_function_type (ptr_type_node, t),
+ = add_builtin_function ("_Jv_LookupInterfaceMethodIdx", ftype,
0, NOT_BUILT_IN, NULL, NULL_TREE);
}
@@ -6582,6 +6636,8 @@ is_subseq (conversion *ics1, conversion *ics2)
if (ics2->kind == ck_user
|| ics2->kind == ck_ambig
+ || ics2->kind == ck_aggr
+ || ics2->kind == ck_list
|| ics2->kind == ck_identity)
/* At this point, ICS1 cannot be a proper subsequence of
ICS2. We can get a USER_CONV when we are comparing the
@@ -6735,14 +6791,16 @@ compare_ics (conversion *ics1, conversion *ics2)
if (rank1 == cr_bad)
{
- /* XXX Isn't this an extension? */
- /* Both ICS are bad. We try to make a decision based on what
- would have happened if they'd been good. */
- if (ics1->user_conv_p > ics2->user_conv_p
- || ics1->rank > ics2->rank)
+ /* Both ICS are bad. We try to make a decision based on what would
+ have happened if they'd been good. This is not an extension,
+ we'll still give an error when we build up the call; this just
+ helps us give a more helpful error message. */
+ rank1 = BAD_CONVERSION_RANK (ics1);
+ rank2 = BAD_CONVERSION_RANK (ics2);
+
+ if (rank1 > rank2)
return -1;
- else if (ics1->user_conv_p < ics2->user_conv_p
- || ics1->rank < ics2->rank)
+ else if (rank1 < rank2)
return 1;
/* We couldn't make up our minds; try to figure it out below. */
@@ -6766,13 +6824,25 @@ compare_ics (conversion *ics1, conversion *ics2)
for (t1 = ics1; t1->kind != ck_user; t1 = t1->u.next)
if (t1->kind == ck_ambig || t1->kind == ck_aggr)
- return 0;
+ break;
for (t2 = ics2; t2->kind != ck_user; t2 = t2->u.next)
if (t2->kind == ck_ambig || t2->kind == ck_aggr)
- return 0;
+ break;
- if (t1->cand->fn != t2->cand->fn)
+ if (t1->kind != t2->kind)
return 0;
+ else if (t1->kind == ck_user)
+ {
+ if (t1->cand->fn != t2->cand->fn)
+ return 0;
+ }
+ else
+ {
+ /* For ambiguous or aggregate conversions, use the target type as
+ a proxy for the conversion function. */
+ if (!same_type_ignoring_top_level_qualifiers_p (t1->type, t2->type))
+ return 0;
+ }
/* We can just fall through here, after setting up
FROM_TYPE1 and FROM_TYPE2. */
@@ -7394,6 +7464,9 @@ tweak:
winner = -1, w = cand2, l = cand1;
if (winner)
{
+ /* Don't choose a deleted function over ambiguity. */
+ if (DECL_P (w->fn) && DECL_DELETED_FN (w->fn))
+ return 0;
if (warn)
{
pedwarn (input_location, 0,
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index c2831c1a485..a2ed86334b5 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -77,9 +77,7 @@ typedef struct vtbl_init_data_s
tree rtti_binfo;
/* The negative-index vtable initializers built up so far. These
are in order from least negative index to most negative index. */
- tree inits;
- /* The last (i.e., most negative) entry in INITS. */
- tree* last_init;
+ VEC(constructor_elt,gc) *inits;
/* The binfo for the virtual base for which we're building
vcall offset initializers. */
tree vbase;
@@ -136,7 +134,8 @@ static void add_implicitly_declared_members (tree, int, int);
static tree fixed_type_or_null (tree, int *, int *);
static tree build_simple_base_path (tree expr, tree binfo);
static tree build_vtbl_ref_1 (tree, tree);
-static tree build_vtbl_initializer (tree, tree, tree, tree, int *);
+static void build_vtbl_initializer (tree, tree, tree, tree, int *,
+ VEC(constructor_elt,gc) **);
static int count_fields (tree);
static int add_fields_to_record_type (tree, struct sorted_fields_type*, int);
static bool check_bitfield_decl (tree);
@@ -173,14 +172,15 @@ static void dump_vtable (tree, tree, tree);
static void dump_vtt (tree, tree);
static void dump_thunk (FILE *, int, tree);
static tree build_vtable (tree, tree, tree);
-static void initialize_vtable (tree, tree);
+static void initialize_vtable (tree, VEC(constructor_elt,gc) *);
static void layout_nonempty_base_or_field (record_layout_info,
tree, tree, splay_tree);
static tree end_of_class (tree, int);
static bool layout_empty_base (record_layout_info, tree, tree, splay_tree);
-static void accumulate_vtbl_inits (tree, tree, tree, tree, tree);
-static tree dfs_accumulate_vtbl_inits (tree, tree, tree, tree,
- tree);
+static void accumulate_vtbl_inits (tree, tree, tree, tree, tree,
+ VEC(constructor_elt,gc) **);
+static void dfs_accumulate_vtbl_inits (tree, tree, tree, tree, tree,
+ VEC(constructor_elt,gc) **);
static void build_rtti_vtbl_entries (tree, vtbl_init_data *);
static void build_vcall_and_vbase_vtbl_entries (tree, vtbl_init_data *);
static void clone_constructors_and_destructors (tree);
@@ -189,7 +189,7 @@ static void update_vtable_entry_for_fn (tree, tree, tree, tree *, unsigned);
static void build_ctor_vtbl_group (tree, tree);
static void build_vtt (tree);
static tree binfo_ctor_vtable (tree);
-static tree *build_vtt_inits (tree, tree, tree *, tree *);
+static void build_vtt_inits (tree, tree, VEC(constructor_elt,gc) **, tree *);
static tree dfs_build_secondary_vptr_vtt_inits (tree, void *);
static tree dfs_fixup_binfo_vtbls (tree, void *);
static int record_subobject_offset (tree, tree, splay_tree);
@@ -283,6 +283,8 @@ build_base_path (enum tree_code code,
if (!want_pointer)
/* This must happen before the call to save_expr. */
expr = cp_build_unary_op (ADDR_EXPR, expr, 0, tf_warning_or_error);
+ else
+ mark_rvalue_use (expr);
offset = BINFO_OFFSET (binfo);
fixed_type_p = resolves_to_fixed_type_p (expr, &nonnull);
@@ -1280,10 +1282,11 @@ check_bases (tree t,
assignment operators that take const references, then the
derived class cannot have such a member automatically
generated. */
- if (! TYPE_HAS_CONST_INIT_REF (basetype))
+ if (TYPE_HAS_COPY_CTOR (basetype)
+ && ! TYPE_HAS_CONST_COPY_CTOR (basetype))
*cant_have_const_ctor_p = 1;
- if (TYPE_HAS_ASSIGN_REF (basetype)
- && !TYPE_HAS_CONST_ASSIGN_REF (basetype))
+ if (TYPE_HAS_COPY_ASSIGN (basetype)
+ && !TYPE_HAS_CONST_COPY_ASSIGN (basetype))
*no_const_asn_ref_p = 1;
if (BINFO_VIRTUAL_P (base_binfo))
@@ -1309,13 +1312,19 @@ check_bases (tree t,
TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (basetype);
TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
|= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (basetype);
- TYPE_HAS_COMPLEX_ASSIGN_REF (t)
- |= TYPE_HAS_COMPLEX_ASSIGN_REF (basetype);
- TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (basetype);
+ TYPE_HAS_COMPLEX_COPY_ASSIGN (t)
+ |= (TYPE_HAS_COMPLEX_COPY_ASSIGN (basetype)
+ || !TYPE_HAS_COPY_ASSIGN (basetype));
+ TYPE_HAS_COMPLEX_COPY_CTOR (t) |= (TYPE_HAS_COMPLEX_COPY_CTOR (basetype)
+ || !TYPE_HAS_COPY_CTOR (basetype));
+ TYPE_HAS_COMPLEX_MOVE_ASSIGN (t)
+ |= TYPE_HAS_COMPLEX_MOVE_ASSIGN (basetype);
+ TYPE_HAS_COMPLEX_MOVE_CTOR (t) |= TYPE_HAS_COMPLEX_MOVE_CTOR (basetype);
TYPE_POLYMORPHIC_P (t) |= TYPE_POLYMORPHIC_P (basetype);
CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t)
|= CLASSTYPE_CONTAINS_EMPTY_CLASS_P (basetype);
- TYPE_HAS_COMPLEX_DFLT (t) |= TYPE_HAS_COMPLEX_DFLT (basetype);
+ TYPE_HAS_COMPLEX_DFLT (t) |= (!TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
+ || TYPE_HAS_COMPLEX_DFLT (basetype));
/* A standard-layout class is a class that:
...
@@ -1539,7 +1548,8 @@ finish_struct_bits (tree t)
mode to be BLKmode, and force its TREE_ADDRESSABLE bit to be
nonzero. This will cause it to be passed by invisible reference
and prevent it from being returned in a register. */
- if (! TYPE_HAS_TRIVIAL_INIT_REF (t) || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
+ if (type_has_nontrivial_copy_init (t)
+ || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
{
tree variants;
DECL_MODE (TYPE_MAIN_DECL (t)) = BLKmode;
@@ -1666,10 +1676,10 @@ maybe_warn_about_overly_private_class (tree t)
template <class T> class C { private: C(); };
- To avoid this asymmetry, we check TYPE_HAS_INIT_REF. All
+ To avoid this asymmetry, we check TYPE_HAS_COPY_CTOR. All
complete non-template or fully instantiated classes have this
flag set. */
- if (!TYPE_HAS_INIT_REF (t))
+ if (!TYPE_HAS_COPY_CTOR (t))
nonprivate_ctor = 1;
else
for (fn = CLASSTYPE_CONSTRUCTORS (t); fn; fn = OVL_NEXT (fn))
@@ -2618,47 +2628,13 @@ add_implicitly_declared_members (tree t,
{
/* In general, we create destructors lazily. */
CLASSTYPE_LAZY_DESTRUCTOR (t) = 1;
- /* However, if the implicit destructor is non-trivial
- destructor, we sometimes have to create it at this point. */
- if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
- {
- bool lazy_p = true;
-
- if (TYPE_FOR_JAVA (t))
- /* If this a Java class, any non-trivial destructor is
- invalid, even if compiler-generated. Therefore, if the
- destructor is non-trivial we create it now. */
- lazy_p = false;
- else
- {
- tree binfo;
- tree base_binfo;
- int ix;
-
- /* If the implicit destructor will be virtual, then we must
- generate it now because (unfortunately) we do not
- generate virtual tables lazily. */
- binfo = TYPE_BINFO (t);
- for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
- {
- tree base_type;
- tree dtor;
-
- base_type = BINFO_TYPE (base_binfo);
- dtor = CLASSTYPE_DESTRUCTORS (base_type);
- if (dtor && DECL_VIRTUAL_P (dtor))
- {
- lazy_p = false;
- break;
- }
- }
- }
- /* If we can't get away with being lazy, generate the destructor
- now. */
- if (!lazy_p)
- lazily_declare_fn (sfk_destructor, t);
- }
+ if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
+ && TYPE_FOR_JAVA (t))
+ /* But if this is a Java class, any non-trivial destructor is
+ invalid, even if compiler-generated. Therefore, if the
+ destructor is non-trivial we create it now. */
+ lazily_declare_fn (sfk_destructor, t);
}
/* [class.ctor]
@@ -2675,27 +2651,59 @@ add_implicitly_declared_members (tree t,
If a class definition does not explicitly declare a copy
constructor, one is declared implicitly. */
- if (! TYPE_HAS_INIT_REF (t) && ! TYPE_FOR_JAVA (t))
+ if (! TYPE_HAS_COPY_CTOR (t) && ! TYPE_FOR_JAVA (t)
+ && !type_has_move_constructor (t))
{
- TYPE_HAS_INIT_REF (t) = 1;
- TYPE_HAS_CONST_INIT_REF (t) = !cant_have_const_cctor;
+ TYPE_HAS_COPY_CTOR (t) = 1;
+ TYPE_HAS_CONST_COPY_CTOR (t) = !cant_have_const_cctor;
CLASSTYPE_LAZY_COPY_CTOR (t) = 1;
+ if (cxx_dialect >= cxx0x)
+ CLASSTYPE_LAZY_MOVE_CTOR (t) = 1;
}
- /* Currently only lambdas get a lazy move ctor, but N2987 adds them for
- other classes. */
- if (LAMBDA_TYPE_P (t))
- CLASSTYPE_LAZY_MOVE_CTOR (t) = 1;
-
/* If there is no assignment operator, one will be created if and
when it is needed. For now, just record whether or not the type
of the parameter to the assignment operator will be a const or
non-const reference. */
- if (!TYPE_HAS_ASSIGN_REF (t) && !TYPE_FOR_JAVA (t))
+ if (!TYPE_HAS_COPY_ASSIGN (t) && !TYPE_FOR_JAVA (t)
+ && !type_has_move_assign (t))
{
- TYPE_HAS_ASSIGN_REF (t) = 1;
- TYPE_HAS_CONST_ASSIGN_REF (t) = !cant_have_const_assignment;
- CLASSTYPE_LAZY_ASSIGNMENT_OP (t) = 1;
+ TYPE_HAS_COPY_ASSIGN (t) = 1;
+ TYPE_HAS_CONST_COPY_ASSIGN (t) = !cant_have_const_assignment;
+ CLASSTYPE_LAZY_COPY_ASSIGN (t) = 1;
+ if (cxx_dialect >= cxx0x)
+ CLASSTYPE_LAZY_MOVE_ASSIGN (t) = 1;
+ }
+
+ /* We can't be lazy about declaring functions that might override
+ a virtual function from a base class. */
+ if (TYPE_POLYMORPHIC_P (t)
+ && (CLASSTYPE_LAZY_COPY_ASSIGN (t)
+ || CLASSTYPE_LAZY_MOVE_ASSIGN (t)
+ || CLASSTYPE_LAZY_DESTRUCTOR (t)))
+ {
+ tree binfo = TYPE_BINFO (t);
+ tree base_binfo;
+ int ix;
+ tree opname = ansi_assopname (NOP_EXPR);
+ for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ++ix)
+ {
+ tree bv;
+ for (bv = BINFO_VIRTUALS (base_binfo); bv; bv = TREE_CHAIN (bv))
+ {
+ tree fn = BV_FN (bv);
+ if (DECL_NAME (fn) == opname)
+ {
+ if (CLASSTYPE_LAZY_COPY_ASSIGN (t))
+ lazily_declare_fn (sfk_copy_assignment, t);
+ if (CLASSTYPE_LAZY_MOVE_ASSIGN (t))
+ lazily_declare_fn (sfk_move_assignment, t);
+ }
+ else if (DECL_DESTRUCTOR_P (fn)
+ && CLASSTYPE_LAZY_DESTRUCTOR (t))
+ lazily_declare_fn (sfk_destructor, t);
+ }
+ }
}
}
@@ -2823,7 +2831,7 @@ check_field_decl (tree field,
the settings of CANT_HAVE_CONST_CTOR and friends. */
if (ANON_UNION_TYPE_P (type))
;
- /* And, we don't set TYPE_HAS_CONST_INIT_REF, etc., for anonymous
+ /* And, we don't set TYPE_HAS_CONST_COPY_CTOR, etc., for anonymous
structs. So, we recurse through their fields here. */
else if (ANON_AGGR_TYPE_P (type))
{
@@ -2849,24 +2857,34 @@ check_field_decl (tree field,
field);
if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
error ("member %q+#D with destructor not allowed in union", field);
- if (TYPE_HAS_COMPLEX_ASSIGN_REF (type))
+ if (TYPE_HAS_COMPLEX_COPY_ASSIGN (type))
error ("member %q+#D with copy assignment operator not allowed in union",
field);
+ /* Don't bother diagnosing move assop now; C++0x has more
+ flexible unions. */
}
else
{
TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (type);
TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
|= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type);
- TYPE_HAS_COMPLEX_ASSIGN_REF (t) |= TYPE_HAS_COMPLEX_ASSIGN_REF (type);
- TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (type);
- TYPE_HAS_COMPLEX_DFLT (t) |= TYPE_HAS_COMPLEX_DFLT (type);
+ TYPE_HAS_COMPLEX_COPY_ASSIGN (t)
+ |= (TYPE_HAS_COMPLEX_COPY_ASSIGN (type)
+ || !TYPE_HAS_COPY_ASSIGN (type));
+ TYPE_HAS_COMPLEX_COPY_CTOR (t) |= (TYPE_HAS_COMPLEX_COPY_CTOR (type)
+ || !TYPE_HAS_COPY_CTOR (type));
+ TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) |= TYPE_HAS_COMPLEX_MOVE_ASSIGN (type);
+ TYPE_HAS_COMPLEX_MOVE_CTOR (t) |= TYPE_HAS_COMPLEX_MOVE_CTOR (type);
+ TYPE_HAS_COMPLEX_DFLT (t) |= (!TYPE_HAS_DEFAULT_CONSTRUCTOR (type)
+ || TYPE_HAS_COMPLEX_DFLT (type));
}
- if (!TYPE_HAS_CONST_INIT_REF (type))
+ if (TYPE_HAS_COPY_CTOR (type)
+ && !TYPE_HAS_CONST_COPY_CTOR (type))
*cant_have_const_ctor = 1;
- if (!TYPE_HAS_CONST_ASSIGN_REF (type))
+ if (TYPE_HAS_COPY_ASSIGN (type)
+ && !TYPE_HAS_CONST_COPY_ASSIGN (type))
*no_const_asn_ref = 1;
}
if (DECL_INITIAL (field) != NULL_TREE)
@@ -3025,7 +3043,8 @@ check_field_decls (tree t, tree *access_decls,
aggregate, initialization by a brace-enclosed list) is the
only way to initialize nonstatic const and reference
members. */
- TYPE_HAS_COMPLEX_ASSIGN_REF (t) = 1;
+ TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = 1;
+ TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) = 1;
}
type = strip_array_types (type);
@@ -3092,6 +3111,14 @@ check_field_decls (tree t, tree *access_decls,
if (! zero_init_p (type))
CLASSTYPE_NON_ZERO_INIT_P (t) = 1;
+ /* We set DECL_C_BIT_FIELD in grokbitfield.
+ If the type and width are valid, we'll also set DECL_BIT_FIELD. */
+ if (! DECL_C_BIT_FIELD (x) || ! check_bitfield_decl (x))
+ check_field_decl (x, t,
+ cant_have_const_ctor_p,
+ no_const_asn_ref_p,
+ &any_default_members);
+
/* If any field is const, the structure type is pseudo-const. */
if (CP_TYPE_CONST_P (type))
{
@@ -3103,7 +3130,8 @@ check_field_decls (tree t, tree *access_decls,
aggregate, initialization by a brace-enclosed list) is the
only way to initialize nonstatic const and reference
members. */
- TYPE_HAS_COMPLEX_ASSIGN_REF (t) = 1;
+ TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = 1;
+ TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) = 1;
}
/* A field that is pseudo-const makes the structure likewise. */
else if (CLASS_TYPE_P (type))
@@ -3120,14 +3148,6 @@ check_field_decls (tree t, tree *access_decls,
if (constructor_name_p (DECL_NAME (x), t)
&& TYPE_HAS_USER_CONSTRUCTOR (t))
permerror (input_location, "field %q+#D with same name as class", x);
-
- /* We set DECL_C_BIT_FIELD in grokbitfield.
- If the type and width are valid, we'll also set DECL_BIT_FIELD. */
- if (! DECL_C_BIT_FIELD (x) || ! check_bitfield_decl (x))
- check_field_decl (x, t,
- cant_have_const_ctor_p,
- no_const_asn_ref_p,
- &any_default_members);
}
/* Effective C++ rule 11: if a class has dynamic memory held by pointers,
@@ -3148,18 +3168,18 @@ check_field_decls (tree t, tree *access_decls,
&& has_pointers
&& TYPE_HAS_USER_CONSTRUCTOR (t)
&& TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
- && !(TYPE_HAS_INIT_REF (t) && TYPE_HAS_ASSIGN_REF (t)))
+ && !(TYPE_HAS_COPY_CTOR (t) && TYPE_HAS_COPY_ASSIGN (t)))
{
warning (OPT_Weffc__, "%q#T has pointer data members", t);
- if (! TYPE_HAS_INIT_REF (t))
+ if (! TYPE_HAS_COPY_CTOR (t))
{
warning (OPT_Weffc__,
" but does not override %<%T(const %T&)%>", t, t);
- if (!TYPE_HAS_ASSIGN_REF (t))
+ if (!TYPE_HAS_COPY_ASSIGN (t))
warning (OPT_Weffc__, " or %<operator=(const %T&)%>", t);
}
- else if (! TYPE_HAS_ASSIGN_REF (t))
+ else if (! TYPE_HAS_COPY_ASSIGN (t))
warning (OPT_Weffc__,
" but does not override %<operator=(const %T&)%>", t);
}
@@ -3842,7 +3862,9 @@ check_methods (tree t)
if (DECL_PURE_VIRTUAL_P (x))
VEC_safe_push (tree, gc, CLASSTYPE_PURE_VIRTUALS (t), x);
}
- /* All user-provided destructors are non-trivial. */
+ /* All user-provided destructors are non-trivial.
+ Constructors and assignment ops are handled in
+ grok_special_member_properties. */
if (DECL_DESTRUCTOR_P (x) && user_provided_p (x))
TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = 1;
}
@@ -4247,7 +4269,7 @@ type_has_user_provided_constructor (tree t)
bool
type_has_user_provided_default_constructor (tree t)
{
- tree fns, args;
+ tree fns;
if (!TYPE_HAS_USER_CONSTRUCTOR (t))
return false;
@@ -4256,16 +4278,70 @@ type_has_user_provided_default_constructor (tree t)
{
tree fn = OVL_CURRENT (fns);
if (TREE_CODE (fn) == FUNCTION_DECL
- && user_provided_p (fn))
- {
- args = FUNCTION_FIRST_USER_PARMTYPE (fn);
- while (args && TREE_PURPOSE (args))
- args = TREE_CHAIN (args);
- if (!args || args == void_list_node)
- return true;
- }
+ && user_provided_p (fn)
+ && sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (fn)))
+ return true;
+ }
+
+ return false;
+}
+
+/* Returns true iff class TYPE has a virtual destructor. */
+
+bool
+type_has_virtual_destructor (tree type)
+{
+ tree dtor;
+
+ if (!CLASS_TYPE_P (type))
+ return false;
+
+ gcc_assert (COMPLETE_TYPE_P (type));
+ dtor = CLASSTYPE_DESTRUCTORS (type);
+ return (dtor && DECL_VIRTUAL_P (dtor));
+}
+
+/* Returns true iff class T has a move constructor. */
+
+bool
+type_has_move_constructor (tree t)
+{
+ tree fns;
+
+ if (CLASSTYPE_LAZY_MOVE_CTOR (t))
+ {
+ gcc_assert (COMPLETE_TYPE_P (t));
+ lazily_declare_fn (sfk_move_constructor, t);
}
+ if (!CLASSTYPE_METHOD_VEC (t))
+ return false;
+
+ for (fns = CLASSTYPE_CONSTRUCTORS (t); fns; fns = OVL_NEXT (fns))
+ if (move_fn_p (OVL_CURRENT (fns)))
+ return true;
+
+ return false;
+}
+
+/* Returns true iff class T has a move assignment operator. */
+
+bool
+type_has_move_assign (tree t)
+{
+ tree fns;
+
+ if (CLASSTYPE_LAZY_MOVE_ASSIGN (t))
+ {
+ gcc_assert (COMPLETE_TYPE_P (t));
+ lazily_declare_fn (sfk_move_assignment, t);
+ }
+
+ for (fns = lookup_fnfields_slot (t, ansi_assopname (NOP_EXPR));
+ fns; fns = OVL_NEXT (fns))
+ if (move_fn_p (OVL_CURRENT (fns)))
+ return true;
+
return false;
}
@@ -4384,7 +4460,7 @@ check_bases_and_members (tree t)
/* Save the initial values of these flags which only indicate whether
or not the class has user-provided functions. As we analyze the
bases and members we can set these flags for other reasons. */
- saved_complex_asn_ref = TYPE_HAS_COMPLEX_ASSIGN_REF (t);
+ saved_complex_asn_ref = TYPE_HAS_COMPLEX_COPY_ASSIGN (t);
saved_nontrivial_dtor = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t);
/* Check all the data member declarations. We cannot call
@@ -4402,7 +4478,8 @@ check_bases_and_members (tree t)
/* Do some bookkeeping that will guide the generation of implicitly
declared member functions. */
- TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_CONTAINS_VPTR_P (t);
+ TYPE_HAS_COMPLEX_COPY_CTOR (t) |= TYPE_CONTAINS_VPTR_P (t);
+ TYPE_HAS_COMPLEX_MOVE_CTOR (t) |= TYPE_CONTAINS_VPTR_P (t);
/* We need to call a constructor for this class if it has a
user-provided constructor, or if the default constructor is going
to initialize the vptr. (This is not an if-and-only-if;
@@ -4425,7 +4502,8 @@ check_bases_and_members (tree t)
|= (CLASSTYPE_NON_AGGREGATE (t)
|| saved_nontrivial_dtor || saved_complex_asn_ref);
CLASSTYPE_NON_STD_LAYOUT (t) |= TYPE_CONTAINS_VPTR_P (t);
- TYPE_HAS_COMPLEX_ASSIGN_REF (t) |= TYPE_CONTAINS_VPTR_P (t);
+ TYPE_HAS_COMPLEX_COPY_ASSIGN (t) |= TYPE_CONTAINS_VPTR_P (t);
+ TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) |= TYPE_CONTAINS_VPTR_P (t);
TYPE_HAS_COMPLEX_DFLT (t) |= TYPE_CONTAINS_VPTR_P (t);
/* If the class has no user-declared constructor, but does have
@@ -4495,10 +4573,9 @@ check_bases_and_members (tree t)
/* "The closure type associated with a lambda-expression has a deleted
default constructor and a deleted copy assignment operator." */
TYPE_NEEDS_CONSTRUCTING (t) = 1;
- TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
- CLASSTYPE_LAZY_DEFAULT_CTOR (t) = 0;
- TYPE_HAS_ASSIGN_REF (t) = 0;
- CLASSTYPE_LAZY_ASSIGNMENT_OP (t) = 0;
+ TYPE_HAS_COMPLEX_DFLT (t) = 1;
+ TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = 1;
+ CLASSTYPE_LAZY_MOVE_ASSIGN (t) = 0;
/* "This class type is not an aggregate." */
CLASSTYPE_NON_AGGREGATE (t) = 1;
@@ -4976,8 +5053,10 @@ layout_class_type (tree t, tree *virtuals_p)
bits as additional padding. */
for (itk = itk_char; itk != itk_none; ++itk)
if (integer_types[itk] != NULL_TREE
- && INT_CST_LT (DECL_SIZE (field),
- TYPE_SIZE (integer_types[itk])))
+ && (INT_CST_LT (size_int (MAX_FIXED_MODE_SIZE),
+ TYPE_SIZE (integer_types[itk]))
+ || INT_CST_LT (DECL_SIZE (field),
+ TYPE_SIZE (integer_types[itk]))))
break;
/* ITK now indicates a type that is too large for the
@@ -5435,9 +5514,8 @@ finish_struct_1 (tree t)
n_fields = count_fields (TYPE_FIELDS (t));
if (n_fields > 7)
{
- struct sorted_fields_type *field_vec = GGC_NEWVAR
- (struct sorted_fields_type,
- sizeof (struct sorted_fields_type) + n_fields * sizeof (tree));
+ struct sorted_fields_type *field_vec = ggc_alloc_sorted_fields_type
+ (sizeof (struct sorted_fields_type) + n_fields * sizeof (tree));
field_vec->len = n_fields;
add_fields_to_record_type (TYPE_FIELDS (t), field_vec, 0);
qsort (field_vec->elts, n_fields, sizeof (tree),
@@ -7040,36 +7118,36 @@ debug_thunks (tree fn)
static void
finish_vtbls (tree t)
{
- tree list;
tree vbase;
+ VEC(constructor_elt,gc) *v = NULL;
+ tree vtable = BINFO_VTABLE (TYPE_BINFO (t));
/* We lay out the primary and secondary vtables in one contiguous
vtable. The primary vtable is first, followed by the non-virtual
secondary vtables in inheritance graph order. */
- list = build_tree_list (BINFO_VTABLE (TYPE_BINFO (t)), NULL_TREE);
- accumulate_vtbl_inits (TYPE_BINFO (t), TYPE_BINFO (t),
- TYPE_BINFO (t), t, list);
+ accumulate_vtbl_inits (TYPE_BINFO (t), TYPE_BINFO (t), TYPE_BINFO (t),
+ vtable, t, &v);
/* Then come the virtual bases, also in inheritance graph order. */
for (vbase = TYPE_BINFO (t); vbase; vbase = TREE_CHAIN (vbase))
{
if (!BINFO_VIRTUAL_P (vbase))
continue;
- accumulate_vtbl_inits (vbase, vbase, TYPE_BINFO (t), t, list);
+ accumulate_vtbl_inits (vbase, vbase, TYPE_BINFO (t), vtable, t, &v);
}
if (BINFO_VTABLE (TYPE_BINFO (t)))
- initialize_vtable (TYPE_BINFO (t), TREE_VALUE (list));
+ initialize_vtable (TYPE_BINFO (t), v);
}
/* Initialize the vtable for BINFO with the INITS. */
static void
-initialize_vtable (tree binfo, tree inits)
+initialize_vtable (tree binfo, VEC(constructor_elt,gc) *inits)
{
tree decl;
- layout_vtable_decl (binfo, list_length (inits));
+ layout_vtable_decl (binfo, VEC_length (constructor_elt, inits));
decl = get_vtbl_decl_for_binfo (binfo);
initialize_artificial_var (decl, inits);
dump_vtable (BINFO_TYPE (binfo), binfo, decl);
@@ -7091,13 +7169,13 @@ initialize_vtable (tree binfo, tree inits)
static void
build_vtt (tree t)
{
- tree inits;
tree type;
tree vtt;
tree index;
+ VEC(constructor_elt,gc) *inits;
/* Build up the initializers for the VTT. */
- inits = NULL_TREE;
+ inits = NULL;
index = size_zero_node;
build_vtt_inits (TYPE_BINFO (t), t, &inits, &index);
@@ -7106,7 +7184,7 @@ build_vtt (tree t)
return;
/* Figure out the type of the VTT. */
- type = build_index_type (size_int (list_length (inits) - 1));
+ type = build_index_type (size_int (VEC_length (constructor_elt, inits) - 1));
type = build_cplus_array_type (const_ptr_type_node, type);
/* Now, build the VTT object itself. */
@@ -7152,8 +7230,8 @@ typedef struct secondary_vptr_vtt_init_data_s
/* Current index into the VTT. */
tree index;
- /* TREE_LIST of initializers built up. */
- tree inits;
+ /* Vector of initializers built up. */
+ VEC(constructor_elt,gc) *inits;
/* The type being constructed by this secondary VTT. */
tree type_being_constructed;
@@ -7167,19 +7245,18 @@ typedef struct secondary_vptr_vtt_init_data_s
for virtual bases of T. When it is not so, we build the constructor
vtables for the BINFO-in-T variant. */
-static tree *
-build_vtt_inits (tree binfo, tree t, tree *inits, tree *index)
+static void
+build_vtt_inits (tree binfo, tree t, VEC(constructor_elt,gc) **inits, tree *index)
{
int i;
tree b;
tree init;
- tree secondary_vptrs;
secondary_vptr_vtt_init_data data;
int top_level_p = SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t);
/* We only need VTTs for subobjects with virtual bases. */
if (!CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo)))
- return inits;
+ return;
/* We need to use a construction vtable if this is not the primary
VTT. */
@@ -7193,8 +7270,7 @@ build_vtt_inits (tree binfo, tree t, tree *inits, tree *index)
/* Add the address of the primary vtable for the complete object. */
init = binfo_ctor_vtable (binfo);
- *inits = build_tree_list (NULL_TREE, init);
- inits = &TREE_CHAIN (*inits);
+ CONSTRUCTOR_APPEND_ELT (*inits, NULL_TREE, init);
if (top_level_p)
{
gcc_assert (!BINFO_VPTR_INDEX (binfo));
@@ -7205,30 +7281,23 @@ build_vtt_inits (tree binfo, tree t, tree *inits, tree *index)
/* Recursively add the secondary VTTs for non-virtual bases. */
for (i = 0; BINFO_BASE_ITERATE (binfo, i, b); ++i)
if (!BINFO_VIRTUAL_P (b))
- inits = build_vtt_inits (b, t, inits, index);
+ build_vtt_inits (b, t, inits, index);
/* Add secondary virtual pointers for all subobjects of BINFO with
either virtual bases or reachable along a virtual path, except
subobjects that are non-virtual primary bases. */
data.top_level_p = top_level_p;
data.index = *index;
- data.inits = NULL;
+ data.inits = *inits;
data.type_being_constructed = BINFO_TYPE (binfo);
dfs_walk_once (binfo, dfs_build_secondary_vptr_vtt_inits, NULL, &data);
*index = data.index;
- /* The secondary vptrs come back in reverse order. After we reverse
- them, and add the INITS, the last init will be the first element
- of the chain. */
- secondary_vptrs = data.inits;
- if (secondary_vptrs)
- {
- *inits = nreverse (secondary_vptrs);
- inits = &TREE_CHAIN (secondary_vptrs);
- gcc_assert (*inits == NULL_TREE);
- }
+ /* data.inits might have grown as we added secondary virtual pointers.
+ Make sure our caller knows about the new vector. */
+ *inits = data.inits;
if (top_level_p)
/* Add the secondary VTTs for virtual bases in inheritance graph
@@ -7238,13 +7307,11 @@ build_vtt_inits (tree binfo, tree t, tree *inits, tree *index)
if (!BINFO_VIRTUAL_P (b))
continue;
- inits = build_vtt_inits (b, t, inits, index);
+ build_vtt_inits (b, t, inits, index);
}
else
/* Remove the ctor vtables we created. */
dfs_walk_all (binfo, dfs_fixup_binfo_vtbls, NULL, binfo);
-
- return inits;
}
/* Called from build_vtt_inits via dfs_walk. BINFO is the binfo for the base
@@ -7292,7 +7359,7 @@ dfs_build_secondary_vptr_vtt_inits (tree binfo, void *data_)
}
/* Add the initializer for the secondary vptr itself. */
- data->inits = tree_cons (NULL_TREE, binfo_ctor_vtable (binfo), data->inits);
+ CONSTRUCTOR_APPEND_ELT (data->inits, NULL_TREE, binfo_ctor_vtable (binfo));
/* Advance the vtt index. */
data->index = size_binop (PLUS_EXPR, data->index,
@@ -7335,12 +7402,11 @@ dfs_fixup_binfo_vtbls (tree binfo, void* data)
static void
build_ctor_vtbl_group (tree binfo, tree t)
{
- tree list;
tree type;
tree vtbl;
- tree inits;
tree id;
tree vbase;
+ VEC(constructor_elt,gc) *v;
/* See if we've already created this construction vtable group. */
id = mangle_ctor_vtbl_for_type (t, binfo);
@@ -7353,9 +7419,10 @@ build_ctor_vtbl_group (tree binfo, tree t)
construction vtable group. */
vtbl = build_vtable (t, id, ptr_type_node);
DECL_CONSTRUCTION_VTABLE_P (vtbl) = 1;
- list = build_tree_list (vtbl, NULL_TREE);
+
+ v = NULL;
accumulate_vtbl_inits (binfo, TYPE_BINFO (TREE_TYPE (binfo)),
- binfo, t, list);
+ binfo, vtbl, t, &v);
/* Add the vtables for each of our virtual bases using the vbase in T
binfo. */
@@ -7369,12 +7436,11 @@ build_ctor_vtbl_group (tree binfo, tree t)
continue;
b = copied_binfo (vbase, binfo);
- accumulate_vtbl_inits (b, vbase, binfo, t, list);
+ accumulate_vtbl_inits (b, vbase, binfo, vtbl, t, &v);
}
- inits = TREE_VALUE (list);
/* Figure out the type of the construction vtable. */
- type = build_index_type (size_int (list_length (inits) - 1));
+ type = build_index_type (size_int (VEC_length (constructor_elt, v) - 1));
type = build_cplus_array_type (vtable_entry_type, type);
layout_type (type);
TREE_TYPE (vtbl) = type;
@@ -7383,7 +7449,7 @@ build_ctor_vtbl_group (tree binfo, tree t)
/* Initialize the construction vtable. */
CLASSTYPE_VTABLES (t) = chainon (CLASSTYPE_VTABLES (t), vtbl);
- initialize_artificial_var (vtbl, inits);
+ initialize_artificial_var (vtbl, v);
dump_vtable (t, binfo, vtbl);
}
@@ -7401,8 +7467,9 @@ static void
accumulate_vtbl_inits (tree binfo,
tree orig_binfo,
tree rtti_binfo,
+ tree vtbl,
tree t,
- tree inits)
+ VEC(constructor_elt,gc) **inits)
{
int i;
tree base_binfo;
@@ -7422,10 +7489,7 @@ accumulate_vtbl_inits (tree binfo,
return;
/* Build the initializers for the BINFO-in-T vtable. */
- TREE_VALUE (inits)
- = chainon (TREE_VALUE (inits),
- dfs_accumulate_vtbl_inits (binfo, orig_binfo,
- rtti_binfo, t, inits));
+ dfs_accumulate_vtbl_inits (binfo, orig_binfo, rtti_binfo, vtbl, t, inits);
/* Walk the BINFO and its bases. We walk in preorder so that as we
initialize each vtable we can figure out at what offset the
@@ -7439,24 +7503,25 @@ accumulate_vtbl_inits (tree binfo,
continue;
accumulate_vtbl_inits (base_binfo,
BINFO_BASE_BINFO (orig_binfo, i),
- rtti_binfo, t,
+ rtti_binfo, vtbl, t,
inits);
}
}
-/* Called from accumulate_vtbl_inits. Returns the initializers for
- the BINFO vtable. */
+/* Called from accumulate_vtbl_inits. Adds the initializers for the
+ BINFO vtable to L. */
-static tree
+static void
dfs_accumulate_vtbl_inits (tree binfo,
tree orig_binfo,
tree rtti_binfo,
+ tree orig_vtbl,
tree t,
- tree l)
+ VEC(constructor_elt,gc) **l)
{
- tree inits = NULL_TREE;
tree vtbl = NULL_TREE;
int ctor_vtbl_p = !SAME_BINFO_TYPE_P (BINFO_TYPE (rtti_binfo), t);
+ int n_inits;
if (ctor_vtbl_p
&& BINFO_VIRTUAL_P (orig_binfo) && BINFO_PRIMARY_P (orig_binfo))
@@ -7510,23 +7575,24 @@ dfs_accumulate_vtbl_inits (tree binfo,
/* Otherwise, this is case 3 and we get our own. */
}
else if (!BINFO_NEW_VTABLE_MARKED (orig_binfo))
- return inits;
+ return;
+
+ n_inits = VEC_length (constructor_elt, *l);
if (!vtbl)
{
tree index;
int non_fn_entries;
- /* Compute the initializer for this vtable. */
- inits = build_vtbl_initializer (binfo, orig_binfo, t, rtti_binfo,
- &non_fn_entries);
+ /* Add the initializer for this vtable. */
+ build_vtbl_initializer (binfo, orig_binfo, t, rtti_binfo,
+ &non_fn_entries, l);
/* Figure out the position to which the VPTR should point. */
- vtbl = TREE_PURPOSE (l);
- vtbl = build1 (ADDR_EXPR, vtbl_ptr_type_node, vtbl);
+ vtbl = build1 (ADDR_EXPR, vtbl_ptr_type_node, orig_vtbl);
index = size_binop (PLUS_EXPR,
size_int (non_fn_entries),
- size_int (list_length (TREE_VALUE (l))));
+ size_int (n_inits));
index = size_binop (MULT_EXPR,
TYPE_SIZE_UNIT (vtable_entry_type),
index);
@@ -7539,12 +7605,11 @@ dfs_accumulate_vtbl_inits (tree binfo,
straighten this out. */
BINFO_VTABLE (binfo) = tree_cons (rtti_binfo, vtbl, BINFO_VTABLE (binfo));
else if (BINFO_PRIMARY_P (binfo) && BINFO_VIRTUAL_P (binfo))
- inits = NULL_TREE;
+ /* Throw away any unneeded intializers. */
+ VEC_truncate (constructor_elt, *l, n_inits);
else
/* For an ordinary vtable, set BINFO_VTABLE. */
BINFO_VTABLE (binfo) = vtbl;
-
- return inits;
}
static GTY(()) tree abort_fndecl_addr;
@@ -7572,26 +7637,26 @@ static GTY(()) tree abort_fndecl_addr;
primary bases; we need these while the primary base is being
constructed. */
-static tree
+static void
build_vtbl_initializer (tree binfo,
tree orig_binfo,
tree t,
tree rtti_binfo,
- int* non_fn_entries_p)
+ int* non_fn_entries_p,
+ VEC(constructor_elt,gc) **inits)
{
tree v, b;
- tree vfun_inits;
vtbl_init_data vid;
- unsigned ix;
+ unsigned ix, jx;
tree vbinfo;
VEC(tree,gc) *vbases;
+ constructor_elt *e;
/* Initialize VID. */
memset (&vid, 0, sizeof (vid));
vid.binfo = binfo;
vid.derived = t;
vid.rtti_binfo = rtti_binfo;
- vid.last_init = &vid.inits;
vid.primary_vtbl_p = SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t);
vid.ctor_vtbl_p = !SAME_BINFO_TYPE_P (BINFO_TYPE (rtti_binfo), t);
vid.generate_vcall_entries = true;
@@ -7617,28 +7682,52 @@ build_vtbl_initializer (tree binfo,
/* If the target requires padding between data entries, add that now. */
if (TARGET_VTABLE_DATA_ENTRY_DISTANCE > 1)
{
- tree cur, *prev;
+ int n_entries = VEC_length (constructor_elt, vid.inits);
- for (prev = &vid.inits; (cur = *prev); prev = &TREE_CHAIN (cur))
+ VEC_safe_grow (constructor_elt, gc, vid.inits,
+ TARGET_VTABLE_DATA_ENTRY_DISTANCE * n_entries);
+
+ /* Move data entries into their new positions and add padding
+ after the new positions. Iterate backwards so we don't
+ overwrite entries that we would need to process later. */
+ for (ix = n_entries - 1;
+ VEC_iterate (constructor_elt, vid.inits, ix, e);
+ ix--)
{
- tree add = cur;
- int i;
+ int j;
+ int new_position = (TARGET_VTABLE_DATA_ENTRY_DISTANCE * ix
+ + (TARGET_VTABLE_DATA_ENTRY_DISTANCE - 1));
- for (i = 1; i < TARGET_VTABLE_DATA_ENTRY_DISTANCE; ++i)
- add = tree_cons (NULL_TREE,
- build1 (NOP_EXPR, vtable_entry_type,
- null_pointer_node),
- add);
- *prev = add;
+ VEC_replace (constructor_elt, vid.inits, new_position, e);
+
+ for (j = 1; j < TARGET_VTABLE_DATA_ENTRY_DISTANCE; ++j)
+ {
+ constructor_elt *f = VEC_index (constructor_elt, vid.inits,
+ new_position - j);
+ f->index = NULL_TREE;
+ f->value = build1 (NOP_EXPR, vtable_entry_type,
+ null_pointer_node);
+ }
}
}
if (non_fn_entries_p)
- *non_fn_entries_p = list_length (vid.inits);
+ *non_fn_entries_p = VEC_length (constructor_elt, vid.inits);
+
+ /* The initializers for virtual functions were built up in reverse
+ order. Straighten them out and add them to the running list in one
+ step. */
+ jx = VEC_length (constructor_elt, *inits);
+ VEC_safe_grow (constructor_elt, gc, *inits,
+ (jx + VEC_length (constructor_elt, vid.inits)));
+
+ for (ix = VEC_length (constructor_elt, vid.inits) - 1;
+ VEC_iterate (constructor_elt, vid.inits, ix, e);
+ ix--, jx++)
+ VEC_replace (constructor_elt, *inits, jx, e);
/* Go through all the ordinary virtual functions, building up
initializers. */
- vfun_inits = NULL_TREE;
for (v = BINFO_VIRTUALS (orig_binfo); v; v = TREE_CHAIN (v))
{
tree delta;
@@ -7724,7 +7813,7 @@ build_vtbl_initializer (tree binfo,
int i;
if (init == size_zero_node)
for (i = 0; i < TARGET_VTABLE_USES_DESCRIPTORS; ++i)
- vfun_inits = tree_cons (NULL_TREE, init, vfun_inits);
+ CONSTRUCTOR_APPEND_ELT (*inits, NULL_TREE, init);
else
for (i = 0; i < TARGET_VTABLE_USES_DESCRIPTORS; ++i)
{
@@ -7733,22 +7822,12 @@ build_vtbl_initializer (tree binfo,
build_int_cst (NULL_TREE, i));
TREE_CONSTANT (fdesc) = 1;
- vfun_inits = tree_cons (NULL_TREE, fdesc, vfun_inits);
+ CONSTRUCTOR_APPEND_ELT (*inits, NULL_TREE, fdesc);
}
}
else
- vfun_inits = tree_cons (NULL_TREE, init, vfun_inits);
+ CONSTRUCTOR_APPEND_ELT (*inits, NULL_TREE, init);
}
-
- /* The initializers for virtual functions were built up in reverse
- order; straighten them out now. */
- vfun_inits = nreverse (vfun_inits);
-
- /* The negative offset initializers are also in reverse order. */
- vid.inits = nreverse (vid.inits);
-
- /* Chain the two together. */
- return chainon (vid.inits, vfun_inits);
}
/* Adds to vid->inits the initializers for the vbase and vcall
@@ -7858,12 +7937,9 @@ build_vbase_offset_vtbl_entries (tree binfo, vtbl_init_data* vid)
delta = size_diffop_loc (input_location,
BINFO_OFFSET (b), BINFO_OFFSET (non_primary_binfo));
- *vid->last_init
- = build_tree_list (NULL_TREE,
- fold_build1_loc (input_location, NOP_EXPR,
- vtable_entry_type,
- delta));
- vid->last_init = &TREE_CHAIN (*vid->last_init);
+ CONSTRUCTOR_APPEND_ELT (vid->inits, NULL_TREE,
+ fold_build1_loc (input_location, NOP_EXPR,
+ vtable_entry_type, delta));
}
}
@@ -8098,8 +8174,7 @@ add_vcall_offset (tree orig_fn, tree binfo, vtbl_init_data *vid)
vcall_offset);
}
/* Add the initializer to the vtable. */
- *vid->last_init = build_tree_list (NULL_TREE, vcall_offset);
- vid->last_init = &TREE_CHAIN (*vid->last_init);
+ CONSTRUCTOR_APPEND_ELT (vid->inits, NULL_TREE, vcall_offset);
}
}
@@ -8143,15 +8218,13 @@ build_rtti_vtbl_entries (tree binfo, vtbl_init_data* vid)
/* Convert the declaration to a type that can be stored in the
vtable. */
init = build_nop (vfunc_ptr_type_node, decl);
- *vid->last_init = build_tree_list (NULL_TREE, init);
- vid->last_init = &TREE_CHAIN (*vid->last_init);
+ CONSTRUCTOR_APPEND_ELT (vid->inits, NULL_TREE, init);
/* Add the offset-to-top entry. It comes earlier in the vtable than
the typeinfo entry. Convert the offset to look like a
function pointer, so that we can put it in the vtable. */
init = build_nop (vfunc_ptr_type_node, offset);
- *vid->last_init = build_tree_list (NULL_TREE, init);
- vid->last_init = &TREE_CHAIN (*vid->last_init);
+ CONSTRUCTOR_APPEND_ELT (vid->inits, NULL_TREE, init);
}
/* Fold a OBJ_TYPE_REF expression to the address of a function.
diff --git a/gcc/cp/config-lang.in b/gcc/cp/config-lang.in
index c6d7b38b31f..a15c7e24705 100644
--- a/gcc/cp/config-lang.in
+++ b/gcc/cp/config-lang.in
@@ -30,4 +30,4 @@ compilers="cc1plus\$(exeext)"
target_libs="target-libstdc++-v3"
-gtfiles="\$(srcdir)/cp/rtti.c \$(srcdir)/cp/mangle.c \$(srcdir)/cp/name-lookup.h \$(srcdir)/cp/name-lookup.c \$(srcdir)/cp/cp-tree.h \$(srcdir)/cp/decl.h \$(srcdir)/cp/call.c \$(srcdir)/cp/decl.c \$(srcdir)/cp/decl2.c \$(srcdir)/cp/pt.c \$(srcdir)/cp/repo.c \$(srcdir)/cp/semantics.c \$(srcdir)/cp/tree.c \$(srcdir)/cp/parser.c \$(srcdir)/cp/method.c \$(srcdir)/cp/typeck2.c \$(srcdir)/c-common.c \$(srcdir)/c-common.h \$(srcdir)/c-lex.c \$(srcdir)/c-pragma.h \$(srcdir)/c-pragma.c \$(srcdir)/cp/class.c \$(srcdir)/cp/cp-objcp-common.c \$(srcdir)/cp/cp-lang.c"
+gtfiles="\$(srcdir)/cp/rtti.c \$(srcdir)/cp/mangle.c \$(srcdir)/cp/name-lookup.h \$(srcdir)/cp/name-lookup.c \$(srcdir)/cp/cp-tree.h \$(srcdir)/cp/decl.h \$(srcdir)/cp/call.c \$(srcdir)/cp/decl.c \$(srcdir)/cp/decl2.c \$(srcdir)/cp/pt.c \$(srcdir)/cp/repo.c \$(srcdir)/cp/semantics.c \$(srcdir)/cp/tree.c \$(srcdir)/cp/parser.c \$(srcdir)/cp/method.c \$(srcdir)/cp/typeck2.c \$(srcdir)/c-family/c-common.c \$(srcdir)/c-family/c-common.h \$(srcdir)/c-family/c-lex.c \$(srcdir)/c-family/c-pragma.h \$(srcdir)/c-family/c-pragma.c \$(srcdir)/cp/class.c \$(srcdir)/cp/cp-objcp-common.c \$(srcdir)/cp/cp-lang.c"
diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c
index 2e3f11d0946..fa897bfa2b8 100644
--- a/gcc/cp/cp-gimplify.c
+++ b/gcc/cp/cp-gimplify.c
@@ -26,7 +26,7 @@ along with GCC; see the file COPYING3. If not see
#include "tm.h"
#include "tree.h"
#include "cp-tree.h"
-#include "c-common.h"
+#include "c-family/c-common.h"
#include "toplev.h"
#include "tree-iterator.h"
#include "gimple.h"
@@ -575,7 +575,7 @@ cp_gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
TREE_OPERAND (*expr_p, 1) = build1 (VIEW_CONVERT_EXPR,
TREE_TYPE (op0), op1);
- else if ((rhs_predicate_for (op0)) (op1)
+ else if ((is_gimple_lvalue (op1) || INDIRECT_REF_P (op1))
&& !(TREE_CODE (op1) == CALL_EXPR
&& CALL_EXPR_RETURN_SLOT_OPT (op1))
&& is_really_empty_class (TREE_TYPE (op0)))
@@ -981,7 +981,7 @@ cxx_omp_clause_apply_fn (tree fn, tree arg1, tree arg2)
return NULL;
nargs = list_length (DECL_ARGUMENTS (fn));
- argarray = (tree *) alloca (nargs * sizeof (tree));
+ argarray = XALLOCAVEC (tree, nargs);
defparm = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (fn)));
if (arg2)
diff --git a/gcc/cp/cp-lang.c b/gcc/cp/cp-lang.c
index a08f0dd71d0..fb687b81685 100644
--- a/gcc/cp/cp-lang.c
+++ b/gcc/cp/cp-lang.c
@@ -25,14 +25,13 @@ along with GCC; see the file COPYING3. If not see
#include "tm.h"
#include "tree.h"
#include "cp-tree.h"
-#include "c-common.h"
+#include "c-family/c-common.h"
#include "toplev.h"
#include "langhooks.h"
#include "langhooks-def.h"
#include "debug.h"
#include "cp-objcp-common.h"
#include "hashtab.h"
-#include "except.h"
enum c_language_kind c_language = clk_cxx;
static void cp_init_ts (void);
diff --git a/gcc/cp/cp-objcp-common.c b/gcc/cp/cp-objcp-common.c
index 35654c5f07a..9cfe7702aca 100644
--- a/gcc/cp/cp-objcp-common.c
+++ b/gcc/cp/cp-objcp-common.c
@@ -24,7 +24,7 @@ along with GCC; see the file COPYING3. If not see
#include "tm.h"
#include "tree.h"
#include "cp-tree.h"
-#include "c-common.h"
+#include "c-family/c-common.h"
#include "toplev.h"
#include "langhooks.h"
#include "langhooks-def.h"
@@ -203,7 +203,7 @@ decl_shadowed_for_var_insert (tree from, tree to)
struct tree_decl_map *h;
void **loc;
- h = GGC_NEW (struct tree_decl_map);
+ h = ggc_alloc_tree_decl_map ();
h->base.from = from;
h->to = to;
loc = htab_find_slot_with_hash (shadowed_var_for_decl, h, DECL_UID (from),
diff --git a/gcc/cp/cp-objcp-common.h b/gcc/cp/cp-objcp-common.h
index 1a97ad2b119..f2d4aa1cceb 100644
--- a/gcc/cp/cp-objcp-common.h
+++ b/gcc/cp/cp-objcp-common.h
@@ -143,4 +143,7 @@ extern bool cp_function_decl_explicit_p (tree decl);
#undef LANG_HOOKS_EH_USE_CXA_END_CLEANUP
#define LANG_HOOKS_EH_USE_CXA_END_CLEANUP true
+#undef LANG_HOOKS_EH_PROTECT_CLEANUP_ACTIONS
+#define LANG_HOOKS_EH_PROTECT_CLEANUP_ACTIONS cp_protect_cleanup_actions
+
#endif /* GCC_CP_OBJCP_COMMON */
diff --git a/gcc/cp/cp-tree.def b/gcc/cp/cp-tree.def
index c71f94caa61..b77350fffa8 100644
--- a/gcc/cp/cp-tree.def
+++ b/gcc/cp/cp-tree.def
@@ -247,6 +247,7 @@ DEFTREECODE (STATIC_CAST_EXPR, "static_cast_expr", tcc_unary, 1)
DEFTREECODE (DYNAMIC_CAST_EXPR, "dynamic_cast_expr", tcc_unary, 1)
DEFTREECODE (DOTSTAR_EXPR, "dotstar_expr", tcc_expression, 2)
DEFTREECODE (TYPEID_EXPR, "typeid_expr", tcc_expression, 1)
+DEFTREECODE (NOEXCEPT_EXPR, "noexcept_expr", tcc_unary, 1)
/* A placeholder for an expression that is not type-dependent, but
does occur in a template. When an expression that is not
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index da8293f7b52..1d9077cdaf1 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -42,7 +42,7 @@ c-common.h, not after.
#endif
#include "toplev.h"
#include "diagnostic.h"
-#include "c-common.h"
+#include "c-family/c-common.h"
#include "name-lookup.h"
@@ -418,6 +418,23 @@ typedef enum readonly_error_kind
REK_DECREMENT
} readonly_error_kind;
+/* Possible cases of expression list used by build_x_compound_expr_from_list. */
+typedef enum expr_list_kind {
+ ELK_INIT, /* initializer */
+ ELK_MEM_INIT, /* member initializer */
+ ELK_FUNC_CAST /* functional cast */
+} expr_list_kind;
+
+/* Possible cases of implicit bad rhs conversions. */
+typedef enum impl_conv_rhs {
+ ICR_DEFAULT_ARGUMENT, /* default argument */
+ ICR_CONVERTING, /* converting */
+ ICR_INIT, /* initialization */
+ ICR_ARGPASS, /* argument passing */
+ ICR_RETURN, /* return */
+ ICR_ASSIGN /* assignment */
+} impl_conv_rhs;
+
/* Macros for access to language-specific slots in an identifier. */
#define IDENTIFIER_NAMESPACE_BINDINGS(NODE) \
@@ -758,6 +775,8 @@ enum cp_tree_index
CPTI_LANG_NAME_JAVA,
CPTI_EMPTY_EXCEPT_SPEC,
+ CPTI_NOEXCEPT_TRUE_SPEC,
+ CPTI_NOEXCEPT_FALSE_SPEC,
CPTI_JCLASS,
CPTI_TERMINATE,
CPTI_CALL_UNEXPECTED,
@@ -847,6 +866,8 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX];
/* Exception specifier used for throw(). */
#define empty_except_spec cp_global_trees[CPTI_EMPTY_EXCEPT_SPEC]
+#define noexcept_true_spec cp_global_trees[CPTI_NOEXCEPT_TRUE_SPEC]
+#define noexcept_false_spec cp_global_trees[CPTI_NOEXCEPT_FALSE_SPEC]
/* If non-NULL, a POINTER_TYPE equivalent to (java::lang::Class*). */
#define jclass_node cp_global_trees[CPTI_JCLASS]
@@ -892,7 +913,7 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX];
struct GTY(()) saved_scope {
VEC(cxx_saved_binding,gc) *old_bindings;
tree old_namespace;
- tree decl_ns_list;
+ VEC(tree,gc) *decl_ns_list;
tree class_name;
tree class_type;
tree access_specifier;
@@ -1218,11 +1239,11 @@ struct GTY(()) lang_type_header {
BOOL_BITFIELD is_lang_type_class : 1;
BOOL_BITFIELD has_type_conversion : 1;
- BOOL_BITFIELD has_init_ref : 1;
+ BOOL_BITFIELD has_copy_ctor : 1;
BOOL_BITFIELD has_default_ctor : 1;
BOOL_BITFIELD const_needs_init : 1;
BOOL_BITFIELD ref_needs_init : 1;
- BOOL_BITFIELD has_const_assign_ref : 1;
+ BOOL_BITFIELD has_const_copy_assign : 1;
BOOL_BITFIELD spare : 1;
};
@@ -1250,7 +1271,7 @@ struct GTY(()) lang_type_class {
unsigned non_pod_class : 1;
unsigned nearly_empty_p : 1;
unsigned user_align : 1;
- unsigned has_assign_ref : 1;
+ unsigned has_copy_assign : 1;
unsigned has_new : 1;
unsigned has_array_new : 1;
@@ -1276,19 +1297,23 @@ struct GTY(()) lang_type_class {
unsigned was_anonymous : 1;
unsigned lazy_default_ctor : 1;
unsigned lazy_copy_ctor : 1;
- unsigned lazy_assignment_op : 1;
+ unsigned lazy_copy_assign : 1;
unsigned lazy_destructor : 1;
- unsigned has_const_init_ref : 1;
- unsigned has_complex_init_ref : 1;
- unsigned has_complex_assign_ref : 1;
+ unsigned has_const_copy_ctor : 1;
+ unsigned has_complex_copy_ctor : 1;
+ unsigned has_complex_copy_assign : 1;
unsigned non_aggregate : 1;
unsigned has_complex_dflt : 1;
unsigned has_list_ctor : 1;
unsigned non_std_layout : 1;
- unsigned lazy_move_ctor : 1;
unsigned is_literal : 1;
+ unsigned lazy_move_ctor : 1;
+ unsigned lazy_move_assign : 1;
+ unsigned has_complex_move_ctor : 1;
+ unsigned has_complex_move_assign : 1;
+
/* When adding a flag here, consider whether or not it ought to
apply to a template instance if it applies to the template. If
so, make sure to copy it in instantiate_class_template! */
@@ -1296,7 +1321,7 @@ struct GTY(()) lang_type_class {
/* There are some bits left to fill out a 32-bit word. Keep track
of this by updating the size of this bitfield whenever you add or
remove a flag. */
- unsigned dummy : 7;
+ unsigned dummy : 4;
tree primary_base;
VEC(tree_pair_s,gc) *vcall_indices;
@@ -1329,7 +1354,7 @@ struct GTY(()) lang_type_ptrmem {
tree record;
};
-struct GTY(()) lang_type {
+struct GTY((variable_size)) lang_type {
union lang_type_u
{
struct lang_type_header GTY((skip (""))) h;
@@ -1391,8 +1416,13 @@ struct GTY(()) lang_type {
/* Nonzero means that NODE (a class type) has an assignment operator
-- but that it has not yet been declared. */
-#define CLASSTYPE_LAZY_ASSIGNMENT_OP(NODE) \
- (LANG_TYPE_CLASS_CHECK (NODE)->lazy_assignment_op)
+#define CLASSTYPE_LAZY_COPY_ASSIGN(NODE) \
+ (LANG_TYPE_CLASS_CHECK (NODE)->lazy_copy_assign)
+
+/* Nonzero means that NODE (a class type) has an assignment operator
+ -- but that it has not yet been declared. */
+#define CLASSTYPE_LAZY_MOVE_ASSIGN(NODE) \
+ (LANG_TYPE_CLASS_CHECK (NODE)->lazy_move_assign)
/* Nonzero means that NODE (a class type) has a destructor -- but that
it has not yet been declared. */
@@ -1400,17 +1430,17 @@ struct GTY(()) lang_type {
(LANG_TYPE_CLASS_CHECK (NODE)->lazy_destructor)
/* Nonzero means that this _CLASSTYPE node overloads operator=(X&). */
-#define TYPE_HAS_ASSIGN_REF(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->has_assign_ref)
+#define TYPE_HAS_COPY_ASSIGN(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->has_copy_assign)
/* True iff the class type NODE has an "operator =" whose parameter
has a parameter of type "const X&". */
-#define TYPE_HAS_CONST_ASSIGN_REF(NODE) \
- (LANG_TYPE_CLASS_CHECK (NODE)->h.has_const_assign_ref)
+#define TYPE_HAS_CONST_COPY_ASSIGN(NODE) \
+ (LANG_TYPE_CLASS_CHECK (NODE)->h.has_const_copy_assign)
/* Nonzero means that this _CLASSTYPE node has an X(X&) constructor. */
-#define TYPE_HAS_INIT_REF(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->h.has_init_ref)
-#define TYPE_HAS_CONST_INIT_REF(NODE) \
- (LANG_TYPE_CLASS_CHECK (NODE)->has_const_init_ref)
+#define TYPE_HAS_COPY_CTOR(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->h.has_copy_ctor)
+#define TYPE_HAS_CONST_COPY_CTOR(NODE) \
+ (LANG_TYPE_CLASS_CHECK (NODE)->has_const_copy_ctor)
/* Nonzero if this class has an X(initializer_list<T>) constructor. */
#define TYPE_HAS_LIST_CTOR(NODE) \
@@ -1429,6 +1459,11 @@ struct GTY(()) lang_type {
starting the definition of this type has been seen. */
#define TYPE_BEING_DEFINED(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->being_defined)
+/* Nonzero means that this type is either complete or being defined, so we
+ can do lookup in it. */
+#define COMPLETE_OR_OPEN_TYPE_P(NODE) \
+ (COMPLETE_TYPE_P (NODE) || (CLASS_TYPE_P (NODE) && TYPE_BEING_DEFINED (NODE)))
+
/* Mark bits for repeated base checks. */
#define TYPE_MARKED_P(NODE) TREE_LANG_FLAG_6 (TYPE_CHECK (NODE))
@@ -1726,19 +1761,18 @@ struct GTY(()) lang_type {
/* For FUNCTION_TYPE or METHOD_TYPE, a list of the exceptions that
this type can raise. Each TREE_VALUE is a _TYPE. The TREE_VALUE
will be NULL_TREE to indicate a throw specification of `()', or
- no exceptions allowed. */
+ no exceptions allowed. For a noexcept specification, TREE_VALUE
+ is NULL_TREE and TREE_PURPOSE is the constant-expression. */
#define TYPE_RAISES_EXCEPTIONS(NODE) TYPE_LANG_SLOT_1 (NODE)
-/* For FUNCTION_TYPE or METHOD_TYPE, return 1 iff it is declared `throw()'. */
-#define TYPE_NOTHROW_P(NODE) \
- (TYPE_RAISES_EXCEPTIONS (NODE) \
- && TREE_VALUE (TYPE_RAISES_EXCEPTIONS (NODE)) == NULL_TREE)
+/* For FUNCTION_TYPE or METHOD_TYPE, return 1 iff it is declared `throw()'
+ or noexcept(true). */
+#define TYPE_NOTHROW_P(NODE) nothrow_spec_p (TYPE_RAISES_EXCEPTIONS (NODE))
/* For FUNCTION_TYPE or METHOD_TYPE, true if NODE is noexcept. This is the
case for things declared noexcept(true) and, with -fnothrow-opt, for
throw() functions. */
-#define TYPE_NOEXCEPT_P(NODE) \
- (flag_nothrow_opt && TYPE_NOTHROW_P(NODE))
+#define TYPE_NOEXCEPT_P(NODE) type_noexcept_p (NODE)
/* The binding level associated with the namespace. */
#define NAMESPACE_LEVEL(NODE) \
@@ -1876,7 +1910,7 @@ struct GTY(()) lang_decl_parm {
union rather than a struct containing a union as its only field, but
tree.h declares it as a struct. */
-struct GTY(()) lang_decl {
+struct GTY((variable_size)) lang_decl {
union GTY((desc ("%h.base.selector"))) lang_decl_u {
struct lang_decl_base GTY ((default)) base;
struct lang_decl_min GTY((tag ("0"))) min;
@@ -3134,13 +3168,19 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter)
#define TYPE_NON_AGGREGATE_CLASS(NODE) \
(CLASS_TYPE_P (NODE) && CLASSTYPE_NON_AGGREGATE (NODE))
-/* Nonzero if there is a user-defined X::op=(x&) for this class. */
-#define TYPE_HAS_COMPLEX_ASSIGN_REF(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->has_complex_assign_ref)
+/* Nonzero if there is a non-trivial X::op=(cv X&) for this class. */
+#define TYPE_HAS_COMPLEX_COPY_ASSIGN(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->has_complex_copy_assign)
+
+/* Nonzero if there is a non-trivial X::X(cv X&) for this class. */
+#define TYPE_HAS_COMPLEX_COPY_CTOR(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->has_complex_copy_ctor)
-/* Nonzero if there is a user-defined X::X(x&) for this class. */
-#define TYPE_HAS_COMPLEX_INIT_REF(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->has_complex_init_ref)
+/* Nonzero if there is a non-trivial X::op=(X&&) for this class. */
+#define TYPE_HAS_COMPLEX_MOVE_ASSIGN(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->has_complex_move_assign)
-/* Nonzero if there is a user-defined default constructor for this class. */
+/* Nonzero if there is a non-trivial X::X(X&&) for this class. */
+#define TYPE_HAS_COMPLEX_MOVE_CTOR(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->has_complex_move_ctor)
+
+/* Nonzero if there is a non-trivial default constructor for this class. */
#define TYPE_HAS_COMPLEX_DFLT(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->has_complex_dflt)
/* Nonzero if TYPE has a trivial destructor. From [class.dtor]:
@@ -3170,13 +3210,13 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter)
/* Nonzero for class type means that copy initialization of this type can use
a bitwise copy. */
-#define TYPE_HAS_TRIVIAL_INIT_REF(NODE) \
- (TYPE_HAS_INIT_REF (NODE) && ! TYPE_HAS_COMPLEX_INIT_REF (NODE))
+#define TYPE_HAS_TRIVIAL_COPY_CTOR(NODE) \
+ (TYPE_HAS_COPY_CTOR (NODE) && ! TYPE_HAS_COMPLEX_COPY_CTOR (NODE))
/* Nonzero for class type means that assignment of this type can use
a bitwise copy. */
-#define TYPE_HAS_TRIVIAL_ASSIGN_REF(NODE) \
- (TYPE_HAS_ASSIGN_REF (NODE) && ! TYPE_HAS_COMPLEX_ASSIGN_REF (NODE))
+#define TYPE_HAS_TRIVIAL_COPY_ASSIGN(NODE) \
+ (TYPE_HAS_COPY_ASSIGN (NODE) && ! TYPE_HAS_COMPLEX_COPY_ASSIGN (NODE))
/* Returns true if NODE is a pointer-to-data-member. */
#define TYPE_PTRMEM_P(NODE) \
@@ -3263,8 +3303,8 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter)
do { \
if (TYPE_LANG_SPECIFIC (NODE) == NULL) \
{ \
- TYPE_LANG_SPECIFIC (NODE) = GGC_CNEWVAR \
- (struct lang_type, sizeof (struct lang_type_ptrmem)); \
+ TYPE_LANG_SPECIFIC (NODE) = ggc_alloc_cleared_lang_type \
+ (sizeof (struct lang_type_ptrmem)); \
TYPE_LANG_SPECIFIC (NODE)->u.ptrmem.h.is_lang_type_class = 0; \
} \
TYPE_LANG_SPECIFIC (NODE)->u.ptrmem.record = (VALUE); \
@@ -3842,7 +3882,8 @@ typedef enum special_function_kind {
sfk_constructor, /* A constructor. */
sfk_copy_constructor, /* A copy constructor. */
sfk_move_constructor, /* A move constructor. */
- sfk_assignment_operator, /* An assignment operator. */
+ sfk_copy_assignment, /* A copy assignment operator. */
+ sfk_move_assignment, /* A move assignment operator. */
sfk_destructor, /* A destructor. */
sfk_complete_destructor, /* A destructor for complete objects. */
sfk_base_destructor, /* A destructor for base subobjects. */
@@ -4137,12 +4178,21 @@ enum overload_flags { NO_SPECIAL = 0, DTOR_FLAG, TYPENAME_FLAG };
/* We're inside an init-list, so narrowing conversions are ill-formed. */
#define LOOKUP_NO_NARROWING (LOOKUP_PREFER_RVALUE << 1)
/* Avoid user-defined conversions for the first parameter of a copy
- constructor. */
+ constructor (or move constructor). */
#define LOOKUP_NO_COPY_CTOR_CONVERSION (LOOKUP_NO_NARROWING << 1)
/* This is the first parameter of a copy constructor. */
#define LOOKUP_COPY_PARM (LOOKUP_NO_COPY_CTOR_CONVERSION << 1)
/* We only want to consider list constructors. */
#define LOOKUP_LIST_ONLY (LOOKUP_COPY_PARM << 1)
+/* Return after determining which function to call and checking access.
+ Used by sythesized_method_walk to determine which functions will
+ be called to initialize subobjects, in order to determine exception
+ specification and possible implicit delete.
+ This is kind of a hack, but since access control doesn't respect SFINAE
+ we can't just use tf_none to avoid access control errors, we need
+ another mechanism. Exiting early also avoids problems with trying
+ to perform argument conversions when the class isn't complete yet. */
+#define LOOKUP_SPECULATIVE (LOOKUP_LIST_ONLY << 1)
#define LOOKUP_NAMESPACES_ONLY(F) \
(((F) & LOOKUP_PREFER_NAMESPACES) && !((F) & LOOKUP_PREFER_TYPES))
@@ -4629,6 +4679,9 @@ extern tree in_class_defaulted_default_constructor (tree);
extern bool user_provided_p (tree);
extern bool type_has_user_provided_constructor (tree);
extern bool type_has_user_provided_default_constructor (tree);
+extern bool type_has_virtual_destructor (tree);
+extern bool type_has_move_constructor (tree);
+extern bool type_has_move_assign (tree);
extern void defaulted_late_check (tree);
extern bool defaultable_fn_check (tree);
extern void fixup_type_variants (tree);
@@ -4743,7 +4796,7 @@ extern tree check_elaborated_type_specifier (enum tag_types, tree, bool);
extern void warn_extern_redeclared_static (tree, tree);
extern tree cxx_comdat_group (tree);
extern bool cp_missing_noreturn_ok_p (tree);
-extern void initialize_artificial_var (tree, tree);
+extern void initialize_artificial_var (tree, VEC(constructor_elt,gc) *);
extern tree check_var_type (tree, tree);
extern tree reshape_init (tree, tree);
extern tree next_initializable_field (tree);
@@ -4820,11 +4873,17 @@ extern tree build_exc_ptr (void);
extern tree build_throw (tree);
extern int nothrow_libfn_p (const_tree);
extern void check_handlers (tree);
+extern tree finish_noexcept_expr (tree, tsubst_flags_t);
+extern bool nothrow_spec_p (const_tree);
+extern bool type_noexcept_p (const_tree);
+extern bool type_throw_all_p (const_tree);
+extern tree build_noexcept_spec (tree, int);
extern void choose_personality_routine (enum languages);
extern tree eh_type_info (tree);
extern tree begin_eh_spec_block (void);
extern void finish_eh_spec_block (tree, tree);
extern tree build_eh_type_type (tree);
+extern tree cp_protect_cleanup_actions (void);
/* in expr.c */
extern tree cplus_expand_constant (tree);
@@ -4888,15 +4947,19 @@ extern void init_method (void);
extern tree make_thunk (tree, bool, tree, tree);
extern void finish_thunk (tree);
extern void use_thunk (tree, bool);
+extern bool trivial_fn_p (tree);
+extern bool maybe_explain_implicit_delete (tree);
extern void synthesize_method (tree);
extern tree lazily_declare_fn (special_function_kind,
tree);
extern tree skip_artificial_parms_for (const_tree, tree);
extern int num_artificial_parms_for (const_tree);
extern tree make_alias_for (tree, tree);
-extern tree locate_copy (tree, void *);
-extern tree locate_ctor (tree, void *);
-extern tree locate_dtor (tree, void *);
+extern tree get_copy_ctor (tree);
+extern tree get_copy_assign (tree);
+extern tree get_default_ctor (tree);
+extern tree get_dtor (tree);
+extern tree locate_ctor (tree);
/* In optimize.c */
extern bool maybe_clone_body (tree);
@@ -5037,6 +5100,7 @@ extern int accessible_p (tree, tree, bool);
extern tree lookup_field_1 (tree, tree, bool);
extern tree lookup_field (tree, tree, int, bool);
extern int lookup_fnfields_1 (tree, tree);
+extern tree lookup_fnfields_slot (tree, tree);
extern int class_method_index_for_fn (tree, tree);
extern tree lookup_fnfields (tree, tree, int);
extern tree lookup_member (tree, tree, int, bool);
@@ -5248,12 +5312,12 @@ extern bool pod_type_p (const_tree);
extern bool layout_pod_type_p (const_tree);
extern bool std_layout_type_p (const_tree);
extern bool trivial_type_p (const_tree);
+extern bool trivially_copyable_p (const_tree);
extern bool type_has_nontrivial_default_init (const_tree);
extern bool type_has_nontrivial_copy_init (const_tree);
extern bool class_tmpl_impl_spec_p (const_tree);
extern int zero_init_p (const_tree);
extern tree strip_typedefs (tree);
-extern bool typedef_variant_p (tree);
extern void cp_set_underlying_type (tree);
extern tree copy_binfo (tree, tree, tree,
tree *, int);
@@ -5347,7 +5411,8 @@ extern tree require_complete_type (tree);
extern tree complete_type (tree);
extern tree complete_type_or_else (tree, tree);
extern int type_unknown_p (const_tree);
-extern bool comp_except_specs (const_tree, const_tree, bool);
+enum { ce_derived, ce_normal, ce_exact };
+extern bool comp_except_specs (const_tree, const_tree, int);
extern bool comptypes (tree, tree, int);
extern bool compparms (const_tree, const_tree);
extern int comp_cv_qualification (const_tree, const_tree);
@@ -5387,7 +5452,7 @@ extern tree cp_build_unary_op (enum tree_code, tree, int,
extern tree unary_complex_lvalue (enum tree_code, tree);
extern tree build_x_conditional_expr (tree, tree, tree,
tsubst_flags_t);
-extern tree build_x_compound_expr_from_list (tree, const char *);
+extern tree build_x_compound_expr_from_list (tree, expr_list_kind);
extern tree build_x_compound_expr_from_vec (VEC(tree,gc) *, const char *);
extern tree build_x_compound_expr (tree, tree, tsubst_flags_t);
extern tree build_compound_expr (location_t, tree, tree);
@@ -5402,7 +5467,7 @@ extern tree build_x_modify_expr (tree, enum tree_code, tree,
extern tree cp_build_modify_expr (tree, enum tree_code, tree,
tsubst_flags_t);
extern tree convert_for_initialization (tree, tree, tree, int,
- const char *, tree, int,
+ impl_conv_rhs, tree, int,
tsubst_flags_t);
extern int comp_ptr_ttypes (tree, tree);
extern bool comp_ptr_ttypes_const (tree, tree);
diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 71315b1f4fd..40a635153bc 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -196,7 +196,7 @@ cp_convert_to_pointer (tree type, tree expr)
return error_mark_node;
}
- if (integer_zerop (expr))
+ if (null_ptr_cst_p (expr))
{
if (TYPE_PTRMEMFUNC_P (type))
return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), expr, 0,
@@ -481,7 +481,7 @@ convert_to_reference (tree reftype, tree expr, int convtype,
else
{
rval = convert_for_initialization (NULL_TREE, type, expr, flags,
- "converting", 0, 0,
+ ICR_CONVERTING, 0, 0,
tf_warning_or_error);
if (rval == NULL_TREE || rval == error_mark_node)
return rval;
@@ -834,7 +834,9 @@ convert_to_void (tree expr, const char *implicit, tsubst_flags_t complain)
while (TREE_CODE (exprv) == COMPOUND_EXPR)
exprv = TREE_OPERAND (exprv, 1);
- if (DECL_P (exprv) || handled_component_p (exprv))
+ if (DECL_P (exprv)
+ || handled_component_p (exprv)
+ || TREE_CODE (exprv) == INDIRECT_REF)
/* Expr is not being 'used' here, otherwise we whould have
called mark_{rl}value_use use here, which would have in turn
called mark_exp_read. Rather, we call mark_exp_read directly
diff --git a/gcc/cp/cxx-pretty-print.c b/gcc/cp/cxx-pretty-print.c
index 04a83140ad9..6f4ab6b0811 100644
--- a/gcc/cp/cxx-pretty-print.c
+++ b/gcc/cp/cxx-pretty-print.c
@@ -791,6 +791,14 @@ pp_cxx_unary_expression (cxx_pretty_printer *pp, tree t)
pp_unary_expression (pp, TREE_OPERAND (t, 0));
break;
+ case NOEXCEPT_EXPR:
+ pp_cxx_ws_string (pp, "noexcept");
+ pp_cxx_whitespace (pp);
+ pp_cxx_left_paren (pp);
+ pp_cxx_expression (pp, TREE_OPERAND (t, 0));
+ pp_cxx_right_paren (pp);
+ break;
+
case UNARY_PLUS_EXPR:
pp_plus (pp);
pp_cxx_cast_expression (pp, TREE_OPERAND (t, 0));
@@ -1061,6 +1069,7 @@ pp_cxx_expression (cxx_pretty_printer *pp, tree t)
case SIZEOF_EXPR:
case ALIGNOF_EXPR:
+ case NOEXCEPT_EXPR:
pp_cxx_unary_expression (pp, t);
break;
@@ -1418,8 +1427,17 @@ pp_cxx_exception_specification (cxx_pretty_printer *pp, tree t)
tree ex_spec = TYPE_RAISES_EXCEPTIONS (t);
bool need_comma = false;
- if (!TYPE_NOTHROW_P (t) && ex_spec == NULL)
+ if (ex_spec == NULL)
return;
+ if (TREE_PURPOSE (ex_spec))
+ {
+ pp_cxx_ws_string (pp, "noexcept");
+ pp_cxx_whitespace (pp);
+ pp_cxx_left_paren (pp);
+ pp_cxx_expression (pp, TREE_PURPOSE (ex_spec));
+ pp_cxx_right_paren (pp);
+ return;
+ }
pp_cxx_ws_string (pp, "throw");
pp_cxx_left_paren (pp);
for (; ex_spec && TREE_VALUE (ex_spec); ex_spec = TREE_CHAIN (ex_spec))
diff --git a/gcc/cp/cxx-pretty-print.h b/gcc/cp/cxx-pretty-print.h
index a88d4c5ccdb..5a51f44bdb8 100644
--- a/gcc/cp/cxx-pretty-print.h
+++ b/gcc/cp/cxx-pretty-print.h
@@ -21,7 +21,7 @@ along with GCC; see the file COPYING3. If not see
#ifndef GCC_CXX_PRETTY_PRINT_H
#define GCC_CXX_PRETTY_PRINT_H
-#include "c-pretty-print.h"
+#include "c-family/c-pretty-print.h"
#undef pp_c_base
#define pp_c_base(PP) (&(PP)->c_base)
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index b9f3ea84643..1d11fb8f785 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -40,22 +40,28 @@ along with GCC; see the file COPYING3. If not see
#include "decl.h"
#include "intl.h"
#include "output.h"
-#include "except.h"
#include "toplev.h"
#include "hashtab.h"
#include "tm_p.h"
#include "target.h"
-#include "c-common.h"
-#include "c-pragma.h"
+#include "c-family/c-common.h"
+#include "c-family/c-pragma.h"
#include "diagnostic.h"
#include "intl.h"
#include "debug.h"
#include "timevar.h"
-#include "tree-flow.h"
#include "pointer-set.h"
#include "splay-tree.h"
#include "plugin.h"
+/* Possible cases of bad specifiers type used by bad_specifiers. */
+enum bad_spec_place {
+ BSP_VAR, /* variable */
+ BSP_PARM, /* parameter */
+ BSP_TYPE, /* type */
+ BSP_FIELD /* field */
+};
+
static tree grokparms (tree parmlist, tree *);
static const char *redeclaration_error_message (tree, tree);
@@ -71,7 +77,7 @@ static void record_unknown_type (tree, const char *);
static tree builtin_function_1 (tree, tree, bool);
static tree build_library_fn_1 (tree, enum tree_code, tree);
static int member_function_or_else (tree, tree, enum overload_flags);
-static void bad_specifiers (tree, const char *, int, int, int, int,
+static void bad_specifiers (tree, enum bad_spec_place, int, int, int, int,
int);
static void check_for_uninitialized_const_var (tree);
static hashval_t typename_hash (const void *);
@@ -90,6 +96,7 @@ static void check_function_type (tree, tree);
static void finish_constructor_body (void);
static void begin_destructor_body (void);
static void finish_destructor_body (void);
+static void record_key_method_defined (tree);
static tree create_array_type_for_decl (tree, tree, tree);
static tree get_atexit_node (void);
static tree get_dso_handle_node (void);
@@ -203,9 +210,9 @@ struct GTY(()) named_label_entry {
defined, or the inner scope popped. These are the decls that will
be skipped when jumping to the label. */
tree names_in_scope;
- /* A tree list of all decls from all binding levels that would be
+ /* A vector of all decls from all binding levels that would be
crossed by a backward branch to the label. */
- tree bad_decls;
+ VEC(tree,gc) *bad_decls;
/* A list of uses of the label, before the label is defined. */
struct named_label_use_entry *uses;
@@ -237,11 +244,18 @@ VEC(tree, gc) *deferred_mark_used_calls;
enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
-/* A TREE_LIST of VAR_DECLs. The TREE_PURPOSE is a RECORD_TYPE or
- UNION_TYPE; the TREE_VALUE is a VAR_DECL with that type. At the
- time the VAR_DECL was declared, the type was incomplete. */
+/* A list of VAR_DECLs whose type was incomplete at the time the
+ variable was declared. */
+
+typedef struct GTY(()) incomplete_var_d {
+ tree decl;
+ tree incomplete_type;
+} incomplete_var;
+
+DEF_VEC_O(incomplete_var);
+DEF_VEC_ALLOC_O(incomplete_var,gc);
-static GTY(()) tree incomplete_vars;
+static GTY(()) VEC(incomplete_var,gc) *incomplete_vars;
/* Returns the kind of template specialization we are currently
processing, given that it's declaration contained N_CLASS_SCOPES
@@ -462,7 +476,7 @@ poplevel_named_label_1 (void **slot, void *data)
for (decl = ent->names_in_scope; decl; decl = TREE_CHAIN (decl))
if (decl_jump_unsafe (decl))
- ent->bad_decls = tree_cons (NULL, decl, ent->bad_decls);
+ VEC_safe_push (tree, gc, ent->bad_decls, decl);
ent->binding_level = obl;
ent->names_in_scope = obl->names;
@@ -1104,10 +1118,10 @@ check_redeclaration_exception_specification (tree new_decl,
if ((pedantic || ! DECL_IN_SYSTEM_HEADER (old_decl))
&& ! DECL_IS_BUILTIN (old_decl)
&& flag_exceptions
- && !comp_except_specs (new_exceptions, old_exceptions,
- /*exact=*/true))
+ && !comp_except_specs (new_exceptions, old_exceptions, ce_normal))
{
- error ("declaration of %qF throws different exceptions", new_decl);
+ error ("declaration of %qF has a different exception specifier",
+ new_decl);
error ("from previous declaration %q+F", old_decl);
}
}
@@ -1286,7 +1300,7 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend)
/* Even if the types match, prefer the new declarations type for
built-ins which have not been explicitly declared, for
exception lists, etc... */
- else if (DECL_ANTICIPATED (olddecl))
+ else if (DECL_IS_BUILTIN (olddecl))
{
tree type = TREE_TYPE (newdecl);
tree attribs = (*targetm.merge_type_attributes)
@@ -2449,7 +2463,7 @@ make_label_decl (tree id, int local_p)
/* Record this label on the list of labels used in this function.
We do this before calling make_label_decl so that we get the
IDENTIFIER_LABEL_VALUE before the new label is declared. */
- ent = GGC_CNEW (struct named_label_entry);
+ ent = ggc_alloc_cleared_named_label_entry ();
ent->label_decl = decl;
slot = htab_find_slot (named_labels, ent, INSERT);
@@ -2643,6 +2657,7 @@ check_goto (tree decl)
struct named_label_entry *ent, dummy;
bool saw_catch = false, identified = false;
tree bad;
+ unsigned ix;
/* We can't know where a computed goto is jumping.
So we assume that it's OK. */
@@ -2669,7 +2684,7 @@ check_goto (tree decl)
&& ent->uses->names_in_scope == current_binding_level->names)
return;
- new_use = GGC_NEW (struct named_label_use_entry);
+ new_use = ggc_alloc_named_label_use_entry ();
new_use->binding_level = current_binding_level;
new_use->names_in_scope = current_binding_level->names;
new_use->o_goto_locus = input_location;
@@ -2681,29 +2696,28 @@ check_goto (tree decl)
}
if (ent->in_try_scope || ent->in_catch_scope
- || ent->in_omp_scope || ent->bad_decls)
+ || ent->in_omp_scope || !VEC_empty (tree, ent->bad_decls))
{
permerror (input_location, "jump to label %q+D", decl);
permerror (input_location, " from here");
identified = true;
}
- for (bad = ent->bad_decls; bad; bad = TREE_CHAIN (bad))
+ for (ix = 0; VEC_iterate (tree, ent->bad_decls, ix, bad); ix++)
{
- tree b = TREE_VALUE (bad);
- int u = decl_jump_unsafe (b);
+ int u = decl_jump_unsafe (bad);
- if (u > 1 && DECL_ARTIFICIAL (b))
+ if (u > 1 && DECL_ARTIFICIAL (bad))
{
/* Can't skip init of __exception_info. */
- error_at (DECL_SOURCE_LOCATION (b), " enters catch block");
+ error_at (DECL_SOURCE_LOCATION (bad), " enters catch block");
saw_catch = true;
}
else if (u > 1)
- error (" skips initialization of %q+#D", b);
+ error (" skips initialization of %q+#D", bad);
else
permerror (input_location, " enters scope of %q+#D which has "
- "non-trivial destructor", b);
+ "non-trivial destructor", bad);
}
if (ent->in_try_scope)
@@ -3433,6 +3447,8 @@ cxx_init_decl_processing (void)
truthvalue_true_node = boolean_true_node;
empty_except_spec = build_tree_list (NULL_TREE, NULL_TREE);
+ noexcept_true_spec = build_tree_list (boolean_true_node, NULL_TREE);
+ noexcept_false_spec = build_tree_list (boolean_false_node, NULL_TREE);
#if 0
record_builtin_type (RID_MAX, NULL, string_type_node);
@@ -3442,11 +3458,9 @@ cxx_init_decl_processing (void)
vtable_index_type = ptrdiff_type_node;
vtt_parm_type = build_pointer_type (const_ptr_type_node);
- void_ftype = build_function_type (void_type_node, void_list_node);
- void_ftype_ptr = build_function_type (void_type_node,
- tree_cons (NULL_TREE,
- ptr_type_node,
- void_list_node));
+ void_ftype = build_function_type_list (void_type_node, NULL_TREE);
+ void_ftype_ptr = build_function_type_list (void_type_node,
+ ptr_type_node, NULL_TREE);
void_ftype_ptr
= build_exception_variant (void_ftype_ptr, empty_except_spec);
@@ -3498,29 +3512,34 @@ cxx_init_decl_processing (void)
current_lang_name = lang_name_cplusplus;
{
- tree bad_alloc_id;
- tree bad_alloc_type_node;
- tree bad_alloc_decl;
tree newtype, deltype;
tree ptr_ftype_sizetype;
-
- push_namespace (std_identifier);
- bad_alloc_id = get_identifier ("bad_alloc");
- bad_alloc_type_node = make_class_type (RECORD_TYPE);
- TYPE_CONTEXT (bad_alloc_type_node) = current_namespace;
- bad_alloc_decl
- = create_implicit_typedef (bad_alloc_id, bad_alloc_type_node);
- DECL_CONTEXT (bad_alloc_decl) = current_namespace;
- pop_namespace ();
+ tree new_eh_spec;
ptr_ftype_sizetype
- = build_function_type (ptr_type_node,
- tree_cons (NULL_TREE,
- size_type_node,
- void_list_node));
- newtype = build_exception_variant
- (ptr_ftype_sizetype, add_exception_specifier
- (NULL_TREE, bad_alloc_type_node, -1));
+ = build_function_type_list (ptr_type_node, size_type_node, NULL_TREE);
+ if (cxx_dialect == cxx98)
+ {
+ tree bad_alloc_id;
+ tree bad_alloc_type_node;
+ tree bad_alloc_decl;
+
+ push_namespace (std_identifier);
+ bad_alloc_id = get_identifier ("bad_alloc");
+ bad_alloc_type_node = make_class_type (RECORD_TYPE);
+ TYPE_CONTEXT (bad_alloc_type_node) = current_namespace;
+ bad_alloc_decl
+ = create_implicit_typedef (bad_alloc_id, bad_alloc_type_node);
+ DECL_CONTEXT (bad_alloc_decl) = current_namespace;
+ pop_namespace ();
+
+ new_eh_spec
+ = add_exception_specifier (NULL_TREE, bad_alloc_type_node, -1);
+ }
+ else
+ new_eh_spec = noexcept_false_spec;
+
+ newtype = build_exception_variant (ptr_ftype_sizetype, new_eh_spec);
deltype = build_exception_variant (void_ftype_ptr, empty_except_spec);
push_cp_library_fn (NEW_EXPR, newtype);
push_cp_library_fn (VEC_NEW_EXPR, newtype);
@@ -3853,10 +3872,10 @@ fixup_anonymous_aggr (tree t)
/* Wipe out memory of synthesized methods. */
TYPE_HAS_USER_CONSTRUCTOR (t) = 0;
TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
- TYPE_HAS_INIT_REF (t) = 0;
- TYPE_HAS_CONST_INIT_REF (t) = 0;
- TYPE_HAS_ASSIGN_REF (t) = 0;
- TYPE_HAS_CONST_ASSIGN_REF (t) = 0;
+ TYPE_HAS_COPY_CTOR (t) = 0;
+ TYPE_HAS_CONST_COPY_CTOR (t) = 0;
+ TYPE_HAS_COPY_ASSIGN (t) = 0;
+ TYPE_HAS_CONST_COPY_ASSIGN (t) = 0;
/* Splice the implicitly generated functions out of the TYPE_METHODS
list. */
@@ -3902,7 +3921,7 @@ fixup_anonymous_aggr (tree t)
if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
error ("member %q+#D with destructor not allowed "
"in anonymous aggregate", field);
- if (TYPE_HAS_COMPLEX_ASSIGN_REF (type))
+ if (TYPE_HAS_COMPLEX_COPY_ASSIGN (type))
error ("member %q+#D with copy assignment operator "
"not allowed in anonymous aggregate", field);
}
@@ -4119,6 +4138,7 @@ start_decl (const cp_declarator *declarator,
tree context;
bool was_public;
int flags;
+ bool alias;
*pushed_scope_p = NULL_TREE;
@@ -4180,6 +4200,10 @@ start_decl (const cp_declarator *declarator,
if (toplevel_bindings_p ())
TREE_STATIC (decl) = 1;
}
+ alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl)) != 0;
+
+ if (alias && TREE_CODE (decl) == FUNCTION_DECL)
+ record_key_method_defined (decl);
/* If this is a typedef that names the class for linkage purposes
(7.1.3p8), apply any attributes directly to the type. */
@@ -4282,7 +4306,9 @@ start_decl (const cp_declarator *declarator,
DECL_EXTERNAL (decl) = 1;
}
- if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl))
+ if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl)
+ /* Aliases are definitions. */
+ && !alias)
permerror (input_location, "declaration of %q#D outside of class is not definition",
decl);
@@ -4437,7 +4463,7 @@ grok_reference_init (tree decl, tree type, tree init, tree *cleanup)
}
if (TREE_CODE (init) == TREE_LIST)
- init = build_x_compound_expr_from_list (init, "initializer");
+ init = build_x_compound_expr_from_list (init, ELK_INIT);
if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE
&& TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
@@ -5498,6 +5524,8 @@ initialize_local_var (tree decl, tree init)
/* Compute and store the initial value. */
already_used = TREE_USED (decl) || TREE_USED (type);
+ if (TREE_USED (type))
+ DECL_READ_P (decl) = 1;
/* Generate a cleanup, if necessary. */
cleanup = cxx_maybe_build_cleanup (decl);
@@ -5542,16 +5570,15 @@ initialize_local_var (tree decl, tree init)
/* DECL is a VAR_DECL for a compiler-generated variable with static
storage duration (like a virtual table) whose initializer is a
- compile-time constant. INIT must be either a TREE_LIST of values,
- or a CONSTRUCTOR. Initialize the variable and provide it to the
+ compile-time constant. Initialize the variable and provide it to the
back end. */
void
-initialize_artificial_var (tree decl, tree init)
+initialize_artificial_var (tree decl, VEC(constructor_elt,gc) *v)
{
+ tree init;
gcc_assert (DECL_ARTIFICIAL (decl));
- if (TREE_CODE (init) == TREE_LIST)
- init = build_constructor_from_list (TREE_TYPE (decl), init);
+ init = build_constructor (TREE_TYPE (decl), v);
gcc_assert (TREE_CODE (init) == CONSTRUCTOR);
DECL_INITIAL (decl) = init;
DECL_INITIALIZED_P (decl) = 1;
@@ -5657,7 +5684,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
return;
}
if (TREE_CODE (init) == TREE_LIST)
- init = build_x_compound_expr_from_list (init, "initializer");
+ init = build_x_compound_expr_from_list (init, ELK_INIT);
if (describable_type (init))
{
type = TREE_TYPE (decl) = do_auto_deduction (type, init, auto_node);
@@ -6058,20 +6085,21 @@ declare_global_var (tree name, tree type)
static tree
get_atexit_fn_ptr_type (void)
{
- tree arg_types;
tree fn_type;
if (!atexit_fn_ptr_type_node)
{
+ tree arg_type;
if (flag_use_cxa_atexit
&& !targetm.cxx.use_atexit_for_cxa_atexit ())
/* The parameter to "__cxa_atexit" is "void (*)(void *)". */
- arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
+ arg_type = ptr_type_node;
else
/* The parameter to "atexit" is "void (*)(void)". */
- arg_types = void_list_node;
+ arg_type = NULL_TREE;
- fn_type = build_function_type (void_type_node, arg_types);
+ fn_type = build_function_type_list (void_type_node,
+ arg_type, NULL_TREE);
atexit_fn_ptr_type_node = build_pointer_type (fn_type);
}
@@ -6086,7 +6114,6 @@ static tree
get_atexit_node (void)
{
tree atexit_fndecl;
- tree arg_types;
tree fn_type;
tree fn_ptr_type;
const char *name;
@@ -6103,25 +6130,28 @@ get_atexit_node (void)
We build up the argument types and then then function type
itself. */
+ tree argtype0, argtype1, argtype2;
use_aeabi_atexit = targetm.cxx.use_aeabi_atexit ();
/* First, build the pointer-to-function type for the first
argument. */
fn_ptr_type = get_atexit_fn_ptr_type ();
/* Then, build the rest of the argument types. */
- arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
+ argtype2 = ptr_type_node;
if (use_aeabi_atexit)
{
- arg_types = tree_cons (NULL_TREE, fn_ptr_type, arg_types);
- arg_types = tree_cons (NULL_TREE, ptr_type_node, arg_types);
+ argtype1 = fn_ptr_type;
+ argtype0 = ptr_type_node;
}
else
{
- arg_types = tree_cons (NULL_TREE, ptr_type_node, arg_types);
- arg_types = tree_cons (NULL_TREE, fn_ptr_type, arg_types);
+ argtype1 = ptr_type_node;
+ argtype0 = fn_ptr_type;
}
/* And the final __cxa_atexit type. */
- fn_type = build_function_type (integer_type_node, arg_types);
+ fn_type = build_function_type_list (integer_type_node,
+ argtype0, argtype1, argtype2,
+ NULL_TREE);
fn_ptr_type = build_pointer_type (fn_type);
if (use_aeabi_atexit)
name = "__aeabi_atexit";
@@ -6137,9 +6167,9 @@ get_atexit_node (void)
We build up the argument types and then then function type
itself. */
fn_ptr_type = get_atexit_fn_ptr_type ();
- arg_types = tree_cons (NULL_TREE, fn_ptr_type, void_list_node);
/* Build the final atexit type. */
- fn_type = build_function_type (integer_type_node, arg_types);
+ fn_type = build_function_type_list (integer_type_node,
+ fn_ptr_type, NULL_TREE);
name = "atexit";
}
@@ -6419,11 +6449,13 @@ expand_static_init (tree decl, tree init)
abort_fn = get_identifier ("__cxa_guard_abort");
if (!get_global_value_if_present (acquire_fn, &acquire_fn))
{
- tree argtypes = tree_cons (NULL_TREE, TREE_TYPE (guard_addr),
- void_list_node);
- tree vfntype = build_function_type (void_type_node, argtypes);
+ tree vfntype = build_function_type_list (void_type_node,
+ TREE_TYPE (guard_addr),
+ NULL_TREE);
acquire_fn = push_library_fn
- (acquire_fn, build_function_type (integer_type_node, argtypes),
+ (acquire_fn, build_function_type_list (integer_type_node,
+ TREE_TYPE (guard_addr),
+ NULL_TREE),
NULL_TREE);
release_fn = push_library_fn (release_fn, vfntype, NULL_TREE);
abort_fn = push_library_fn (abort_fn, vfntype, NULL_TREE);
@@ -6573,21 +6605,54 @@ member_function_or_else (tree ctype, tree cur_type, enum overload_flags flags)
static void
bad_specifiers (tree object,
- const char* type,
+ enum bad_spec_place type,
int virtualp,
int quals,
int inlinep,
int friendp,
int raises)
{
- if (virtualp)
- error ("%qD declared as a %<virtual%> %s", object, type);
- if (inlinep)
- error ("%qD declared as an %<inline%> %s", object, type);
- if (quals)
- error ("%<const%> and %<volatile%> function specifiers on "
- "%qD invalid in %s declaration",
- object, type);
+ switch (type)
+ {
+ case BSP_VAR:
+ if (virtualp)
+ error ("%qD declared as a %<virtual%> variable", object);
+ if (inlinep)
+ error ("%qD declared as an %<inline%> variable", object);
+ if (quals)
+ error ("%<const%> and %<volatile%> function specifiers on "
+ "%qD invalid in variable declaration", object);
+ break;
+ case BSP_PARM:
+ if (virtualp)
+ error ("%qD declared as a %<virtual%> parameter", object);
+ if (inlinep)
+ error ("%qD declared as an %<inline%> parameter", object);
+ if (quals)
+ error ("%<const%> and %<volatile%> function specifiers on "
+ "%qD invalid in parameter declaration", object);
+ break;
+ case BSP_TYPE:
+ if (virtualp)
+ error ("%qD declared as a %<virtual%> type", object);
+ if (inlinep)
+ error ("%qD declared as an %<inline%> type", object);
+ if (quals)
+ error ("%<const%> and %<volatile%> function specifiers on "
+ "%qD invalid in type declaration", object);
+ break;
+ case BSP_FIELD:
+ if (virtualp)
+ error ("%qD declared as a %<virtual%> field", object);
+ if (inlinep)
+ error ("%qD declared as an %<inline%> field", object);
+ if (quals)
+ error ("%<const%> and %<volatile%> function specifiers on "
+ "%qD invalid in field declaration", object);
+ break;
+ default:
+ gcc_unreachable();
+ }
if (friendp)
error ("%q+D declared as a friend", object);
if (raises
@@ -9079,10 +9144,12 @@ grokdeclarator (const cp_declarator *declarator,
for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
{
if (ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))
- {
- debug_hooks->set_name (t, decl);
- TYPE_NAME (t) = decl;
- }
+ /* We do not rename the debug info representing the
+ anonymous tagged type because the standard says in
+ [dcl.typedef] that the naming applies only for
+ linkage purposes. */
+ /*debug_hooks->set_name (t, decl);*/
+ TYPE_NAME (t) = decl;
}
if (TYPE_LANG_SPECIFIC (type))
@@ -9107,7 +9174,7 @@ grokdeclarator (const cp_declarator *declarator,
|| (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
- bad_specifiers (decl, "type", virtualp,
+ bad_specifiers (decl, BSP_TYPE, virtualp,
memfn_quals != TYPE_UNQUALIFIED,
inlinep, friendp, raises != NULL_TREE);
@@ -9293,7 +9360,7 @@ grokdeclarator (const cp_declarator *declarator,
{
decl = cp_build_parm_decl (unqualified_id, type);
- bad_specifiers (decl, "parameter", virtualp,
+ bad_specifiers (decl, BSP_PARM, virtualp,
memfn_quals != TYPE_UNQUALIFIED,
inlinep, friendp, raises != NULL_TREE);
}
@@ -9571,7 +9638,7 @@ grokdeclarator (const cp_declarator *declarator,
}
}
- bad_specifiers (decl, "field", virtualp,
+ bad_specifiers (decl, BSP_FIELD, virtualp,
memfn_quals != TYPE_UNQUALIFIED,
inlinep, friendp, raises != NULL_TREE);
}
@@ -9694,7 +9761,7 @@ grokdeclarator (const cp_declarator *declarator,
initialized,
(type_quals & TYPE_QUAL_CONST) != 0,
ctype ? ctype : in_namespace);
- bad_specifiers (decl, "variable", virtualp,
+ bad_specifiers (decl, BSP_VAR, virtualp,
memfn_quals != TYPE_UNQUALIFIED,
inlinep, friendp, raises != NULL_TREE);
@@ -10200,11 +10267,11 @@ grok_special_member_properties (tree decl)
X&, volatile X& or const volatile X&, and either there
are no other parameters or else all other parameters have
default arguments. */
- TYPE_HAS_INIT_REF (class_type) = 1;
+ TYPE_HAS_COPY_CTOR (class_type) = 1;
if (user_provided_p (decl))
- TYPE_HAS_COMPLEX_INIT_REF (class_type) = 1;
+ TYPE_HAS_COMPLEX_COPY_CTOR (class_type) = 1;
if (ctor > 1)
- TYPE_HAS_CONST_INIT_REF (class_type) = 1;
+ TYPE_HAS_CONST_COPY_CTOR (class_type) = 1;
}
else if (sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (decl)))
{
@@ -10212,6 +10279,8 @@ grok_special_member_properties (tree decl)
if (user_provided_p (decl))
TYPE_HAS_COMPLEX_DFLT (class_type) = 1;
}
+ else if (move_fn_p (decl) && user_provided_p (decl))
+ TYPE_HAS_COMPLEX_MOVE_CTOR (class_type) = 1;
else if (is_list_ctor (decl))
TYPE_HAS_LIST_CTOR (class_type) = 1;
}
@@ -10227,13 +10296,16 @@ grok_special_member_properties (tree decl)
if (assop)
{
- TYPE_HAS_ASSIGN_REF (class_type) = 1;
+ TYPE_HAS_COPY_ASSIGN (class_type) = 1;
if (user_provided_p (decl))
- TYPE_HAS_COMPLEX_ASSIGN_REF (class_type) = 1;
+ TYPE_HAS_COMPLEX_COPY_ASSIGN (class_type) = 1;
if (assop != 1)
- TYPE_HAS_CONST_ASSIGN_REF (class_type) = 1;
+ TYPE_HAS_CONST_COPY_ASSIGN (class_type) = 1;
}
+ else if (move_fn_p (decl) && user_provided_p (decl))
+ TYPE_HAS_COMPLEX_MOVE_ASSIGN (class_type) = 1;
}
+ /* Destructors are handled in check_methods. */
}
/* Check a constructor DECL has the correct form. Complains
@@ -12003,7 +12075,7 @@ start_preparsed_function (tree decl1, tree attrs, int flags)
/* Initialize the language data structures. Whenever we start
a new function, we destroy temporaries in the usual way. */
- cfun->language = GGC_CNEW (struct language_function);
+ cfun->language = ggc_alloc_cleared_language_function ();
current_stmt_tree ()->stmts_are_full_exprs_p = 1;
current_binding_level = bl;
@@ -12199,7 +12271,7 @@ use_eh_spec_block (tree fn)
{
return (flag_exceptions && flag_enforce_eh_specs
&& !processing_template_decl
- && TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn))
+ && !type_throw_all_p (TREE_TYPE (fn))
/* We insert the EH_SPEC_BLOCK only in the original
function; then, it is copied automatically to the
clones. */
@@ -12304,7 +12376,7 @@ save_function_data (tree decl)
gcc_assert (!DECL_PENDING_INLINE_P (decl));
/* Make a copy. */
- f = GGC_NEW (struct language_function);
+ f = ggc_alloc_language_function ();
memcpy (f, cp_function_chain, sizeof (struct language_function));
DECL_SAVED_FUNCTION_DATA (decl) = f;
@@ -12489,6 +12561,22 @@ outer_curly_brace_block (tree fndecl)
return block;
}
+/* If FNDECL is a class's key method, add the class to the list of
+ keyed classes that should be emitted. */
+
+static void
+record_key_method_defined (tree fndecl)
+{
+ if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fndecl)
+ && DECL_VIRTUAL_P (fndecl)
+ && !processing_template_decl)
+ {
+ tree fnclass = DECL_CONTEXT (fndecl);
+ if (fndecl == CLASSTYPE_KEY_METHOD (fnclass))
+ keyed_classes = tree_cons (NULL_TREE, fnclass, keyed_classes);
+ }
+}
+
/* Finish up a function declaration and compile that function
all the way to assembler language output. The free the storage
for the function definition.
@@ -12515,14 +12603,7 @@ finish_function (int flags)
gcc_assert (!defer_mark_used_calls);
defer_mark_used_calls = true;
- if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fndecl)
- && DECL_VIRTUAL_P (fndecl)
- && !processing_template_decl)
- {
- tree fnclass = DECL_CONTEXT (fndecl);
- if (fndecl == CLASSTYPE_KEY_METHOD (fnclass))
- keyed_classes = tree_cons (NULL_TREE, fnclass, keyed_classes);
- }
+ record_key_method_defined (fndecl);
nested = function_depth > 1;
fntype = TREE_TYPE (fndecl);
@@ -12859,7 +12940,12 @@ maybe_register_incomplete_var (tree var)
/* RTTI TD entries are created while defining the type_info. */
|| (TYPE_LANG_SPECIFIC (inner_type)
&& TYPE_BEING_DEFINED (inner_type)))
- incomplete_vars = tree_cons (inner_type, var, incomplete_vars);
+ {
+ incomplete_var *iv
+ = VEC_safe_push (incomplete_var, gc, incomplete_vars, NULL);
+ iv->decl = var;
+ iv->incomplete_type = inner_type;
+ }
}
}
@@ -12870,24 +12956,24 @@ maybe_register_incomplete_var (tree var)
void
complete_vars (tree type)
{
- tree *list = &incomplete_vars;
+ unsigned ix;
+ incomplete_var *iv;
- gcc_assert (CLASS_TYPE_P (type));
- while (*list)
+ for (ix = 0; VEC_iterate (incomplete_var, incomplete_vars, ix, iv); )
{
- if (same_type_p (type, TREE_PURPOSE (*list)))
+ if (same_type_p (type, iv->incomplete_type))
{
- tree var = TREE_VALUE (*list);
+ tree var = iv->decl;
tree type = TREE_TYPE (var);
/* Complete the type of the variable. The VAR_DECL itself
will be laid out in expand_expr. */
complete_type (type);
cp_apply_type_quals_to_decl (cp_type_quals (type), var);
/* Remove this entry from the list. */
- *list = TREE_CHAIN (*list);
+ VEC_unordered_remove (incomplete_var, incomplete_vars, ix);
}
else
- list = &TREE_CHAIN (*list);
+ ix++;
}
/* Check for pending declarations which may have abstract type. */
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index 33e0e265819..ce54c79f20e 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -37,23 +37,22 @@ along with GCC; see the file COPYING3. If not see
#include "cp-tree.h"
#include "decl.h"
#include "output.h"
-#include "except.h"
#include "toplev.h"
#include "timevar.h"
#include "cpplib.h"
#include "target.h"
-#include "c-common.h"
+#include "c-family/c-common.h"
#include "tree-mudflap.h"
#include "cgraph.h"
#include "tree-inline.h"
-#include "c-pragma.h"
+#include "c-family/c-pragma.h"
#include "tree-dump.h"
#include "intl.h"
#include "gimple.h"
#include "pointer-set.h"
#include "splay-tree.h"
#include "langhooks.h"
-#include "c-ada-spec.h"
+#include "c-family/c-ada-spec.h"
extern cpp_reader *parse_in;
@@ -2725,8 +2724,8 @@ start_objects (int method_type, int initp)
fndecl = build_lang_decl (FUNCTION_DECL,
get_file_function_name (type),
- build_function_type (void_type_node,
- void_list_node));
+ build_function_type_list (void_type_node,
+ NULL_TREE));
start_preparsed_function (fndecl, /*attrs=*/NULL_TREE, SF_PRE_PARSED);
TREE_PUBLIC (current_function_decl) = 0;
@@ -2818,7 +2817,6 @@ static splay_tree priority_info_map;
static tree
start_static_storage_duration_function (unsigned count)
{
- tree parm_types;
tree type;
tree body;
char id[sizeof (SSDF_IDENTIFIER) + 1 /* '\0' */ + 32];
@@ -2827,11 +2825,9 @@ start_static_storage_duration_function (unsigned count)
SSDF_IDENTIFIER_<number>. */
sprintf (id, "%s_%u", SSDF_IDENTIFIER, count);
- /* Create the parameters. */
- parm_types = void_list_node;
- parm_types = tree_cons (NULL_TREE, integer_type_node, parm_types);
- parm_types = tree_cons (NULL_TREE, integer_type_node, parm_types);
- type = build_function_type (void_type_node, parm_types);
+ type = build_function_type_list (void_type_node,
+ integer_type_node, integer_type_node,
+ NULL_TREE);
/* Create the FUNCTION_DECL itself. */
ssdf_decl = build_lang_decl (FUNCTION_DECL,
@@ -3589,7 +3585,8 @@ cp_write_global_declarations (void)
at_eof = 1;
/* Bad parse errors. Just forget about it. */
- if (! global_bindings_p () || current_class_type || decl_namespace_list)
+ if (! global_bindings_p () || current_class_type
+ || !VEC_empty (tree,decl_namespace_list))
return;
if (pch_file)
@@ -4113,8 +4110,9 @@ mark_used (tree decl)
return;
}
}
- error ("deleted function %q+D", decl);
- error ("used here");
+ error ("use of deleted function %qD", decl);
+ if (!maybe_explain_implicit_delete (decl))
+ error_at (DECL_SOURCE_LOCATION (decl), "declared here");
return;
}
/* If we don't need a value, then we don't need to synthesize DECL. */
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 381163b2daf..1902a135b89 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -115,7 +115,7 @@ init_error (void)
static void
dump_scope (tree scope, int flags)
{
- int f = ~TFF_RETURN_TYPE & (flags & (TFF_SCOPE | TFF_CHASE_TYPEDEF));
+ int f = flags & (TFF_SCOPE | TFF_CHASE_TYPEDEF);
if (scope == NULL_TREE)
return;
@@ -865,6 +865,7 @@ dump_simple_decl (tree t, tree type, int flags)
pp_maybe_space (cxx_pp);
}
if (! (flags & TFF_UNQUALIFIED_NAME)
+ && TREE_CODE (t) != PARM_DECL
&& (!DECL_INITIAL (t)
|| TREE_CODE (DECL_INITIAL (t)) != TEMPLATE_PARM_INDEX))
dump_scope (CP_DECL_CONTEXT (t), flags);
@@ -945,7 +946,7 @@ dump_decl (tree t, int flags)
dump_scope (CP_DECL_CONTEXT (t), flags);
flags &= ~TFF_UNQUALIFIED_NAME;
if (DECL_NAME (t) == NULL_TREE)
- pp_string (cxx_pp, M_("<unnamed>"));
+ pp_cxx_ws_string (cxx_pp, M_("{anonymous}"));
else
pp_cxx_tree_identifier (cxx_pp, DECL_NAME (t));
}
@@ -1355,6 +1356,7 @@ static void
dump_parameters (tree parmtypes, int flags)
{
int first = 1;
+ flags &= ~TFF_SCOPE;
pp_cxx_left_paren (cxx_pp);
for (first = 1; parmtypes != void_list_node;
@@ -1388,7 +1390,15 @@ dump_parameters (tree parmtypes, int flags)
static void
dump_exception_spec (tree t, int flags)
{
- if (t)
+ if (t && TREE_PURPOSE (t))
+ {
+ pp_cxx_ws_string (cxx_pp, "noexcept");
+ pp_cxx_whitespace (cxx_pp);
+ pp_cxx_left_paren (cxx_pp);
+ dump_expr (TREE_PURPOSE (t), flags);
+ pp_cxx_right_paren (cxx_pp);
+ }
+ else if (t)
{
pp_cxx_ws_string (cxx_pp, "throw");
pp_cxx_whitespace (cxx_pp);
@@ -1749,7 +1759,9 @@ dump_expr (tree t, int flags)
if (TREE_CODE (fn) == OBJ_TYPE_REF)
fn = resolve_virtual_fun_from_obj_type_ref (fn);
- if (TREE_TYPE (fn) != NULL_TREE && NEXT_CODE (fn) == METHOD_TYPE)
+ if (TREE_TYPE (fn) != NULL_TREE
+ && NEXT_CODE (fn) == METHOD_TYPE
+ && call_expr_nargs (t))
{
tree ob = CALL_EXPR_ARG (t, 0);
if (TREE_CODE (ob) == ADDR_EXPR)
@@ -2116,6 +2128,14 @@ dump_expr (tree t, int flags)
pp_cxx_right_paren (cxx_pp);
break;
+ case NOEXCEPT_EXPR:
+ pp_cxx_ws_string (cxx_pp, "noexcept");
+ pp_cxx_whitespace (cxx_pp);
+ pp_cxx_left_paren (cxx_pp);
+ dump_expr (TREE_OPERAND (t, 0), flags);
+ pp_cxx_right_paren (cxx_pp);
+ break;
+
case REALPART_EXPR:
case IMAGPART_EXPR:
pp_cxx_ws_string (cxx_pp, operator_name_info[TREE_CODE (t)].name);
diff --git a/gcc/cp/except.c b/gcc/cp/except.c
index 6f7f70ad804..79bab76cc5a 100644
--- a/gcc/cp/except.c
+++ b/gcc/cp/except.c
@@ -31,7 +31,6 @@ along with GCC; see the file COPYING3. If not see
#include "cp-tree.h"
#include "flags.h"
#include "output.h"
-#include "except.h"
#include "toplev.h"
#include "tree-inline.h"
#include "tree-iterator.h"
@@ -50,7 +49,6 @@ static tree wrap_cleanups_r (tree *, int *, void *);
static int complete_ptr_ref_or_void_ptr_p (tree, tree);
static bool is_admissible_throw_operand (tree);
static int can_convert_eh (tree, tree);
-static tree cp_protect_cleanup_actions (void);
/* Sets up all the global eh stuff that needs to be initialized at the
start of compilation. */
@@ -62,25 +60,22 @@ init_exception_processing (void)
/* void std::terminate (); */
push_namespace (std_identifier);
- tmp = build_function_type (void_type_node, void_list_node);
+ tmp = build_function_type_list (void_type_node, NULL_TREE);
terminate_node = build_cp_library_fn_ptr ("terminate", tmp);
TREE_THIS_VOLATILE (terminate_node) = 1;
TREE_NOTHROW (terminate_node) = 1;
pop_namespace ();
/* void __cxa_call_unexpected(void *); */
- tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
- tmp = build_function_type (void_type_node, tmp);
+ tmp = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
call_unexpected_node
= push_throw_library_fn (get_identifier ("__cxa_call_unexpected"), tmp);
-
- lang_protect_cleanup_actions = &cp_protect_cleanup_actions;
}
/* Returns an expression to be executed if an unhandled exception is
propagated out of a cleanup region. */
-static tree
+tree
cp_protect_cleanup_actions (void)
{
/* [except.terminate]
@@ -160,8 +155,9 @@ build_exc_ptr (void)
static tree
declare_nothrow_library_fn (tree name, tree return_type, tree parm_type)
{
- tree tmp = tree_cons (NULL_TREE, parm_type, void_list_node);
- return push_library_fn (name, build_function_type (return_type, tmp),
+ return push_library_fn (name, build_function_type_list (return_type,
+ parm_type,
+ NULL_TREE),
empty_except_spec);
}
@@ -407,6 +403,30 @@ initialize_handler_parm (tree decl, tree exp)
LOOKUP_ONLYCONVERTING|DIRECT_BIND);
}
+
+/* Routine to see if exception handling is turned on.
+ DO_WARN is nonzero if we want to inform the user that exception
+ handling is turned off.
+
+ This is used to ensure that -fexceptions has been specified if the
+ compiler tries to use any exception-specific functions. */
+
+static inline int
+doing_eh (void)
+{
+ if (! flag_exceptions)
+ {
+ static int warned = 0;
+ if (! warned)
+ {
+ error ("exception handling disabled, use -fexceptions to enable");
+ warned = 1;
+ }
+ return 0;
+ }
+ return 1;
+}
+
/* Call this to start a catch block. DECL is the catch parameter. */
tree
@@ -415,7 +435,7 @@ expand_start_catch_block (tree decl)
tree exp;
tree type, init;
- if (! doing_eh (1))
+ if (! doing_eh ())
return NULL_TREE;
/* Make sure this declaration is reasonable. */
@@ -494,7 +514,7 @@ expand_start_catch_block (tree decl)
void
expand_end_catch_block (void)
{
- if (! doing_eh (1))
+ if (! doing_eh ())
return;
/* The exception being handled is rethrown if control reaches the end of
@@ -641,7 +661,7 @@ build_throw (tree exp)
return error_mark_node;
}
- if (! doing_eh (1))
+ if (! doing_eh ())
return error_mark_node;
if (exp && decl_is_java_type (TREE_TYPE (exp), 1))
@@ -650,8 +670,9 @@ build_throw (tree exp)
if (!get_global_value_if_present (fn, &fn))
{
/* Declare void _Jv_Throw (void *). */
- tree tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
- tmp = build_function_type (ptr_type_node, tmp);
+ tree tmp;
+ tmp = build_function_type_list (ptr_type_node,
+ ptr_type_node, NULL_TREE);
fn = push_throw_library_fn (fn, tmp);
}
else if (really_overloaded_fn (fn))
@@ -675,9 +696,8 @@ build_throw (tree exp)
/* The CLEANUP_TYPE is the internal type of a destructor. */
if (!cleanup_type)
{
- tmp = void_list_node;
- tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
- tmp = build_function_type (void_type_node, tmp);
+ tmp = build_function_type_list (void_type_node,
+ ptr_type_node, NULL_TREE);
cleanup_type = build_pointer_type (tmp);
}
@@ -686,11 +706,9 @@ build_throw (tree exp)
{
/* Declare void __cxa_throw (void*, void*, void (*)(void*)). */
/* ??? Second argument is supposed to be "std::type_info*". */
- tmp = void_list_node;
- tmp = tree_cons (NULL_TREE, cleanup_type, tmp);
- tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
- tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
- tmp = build_function_type (void_type_node, tmp);
+ tmp = build_function_type_list (void_type_node,
+ ptr_type_node, ptr_type_node,
+ cleanup_type, NULL_TREE);
fn = push_throw_library_fn (fn, tmp);
}
@@ -808,7 +826,7 @@ build_throw (tree exp)
{
/* Declare void __cxa_rethrow (void). */
fn = push_throw_library_fn
- (fn, build_function_type (void_type_node, void_list_node));
+ (fn, build_function_type_list (void_type_node, NULL_TREE));
}
/* ??? Indicate that this function call allows exceptions of the type
@@ -998,3 +1016,143 @@ check_handlers (tree handlers)
check_handlers_1 (handler, i);
}
}
+
+/* walk_tree helper for finish_noexcept_expr. Returns non-null if the
+ expression *TP causes the noexcept operator to evaluate to false.
+
+ 5.3.7 [expr.noexcept]: The result of the noexcept operator is false if
+ in a potentially-evaluated context the expression would contain
+ * a potentially evaluated call to a function, member function,
+ function pointer, or member function pointer that does not have a
+ non-throwing exception-specification (15.4),
+ * a potentially evaluated throw-expression (15.1),
+ * a potentially evaluated dynamic_cast expression dynamic_cast<T>(v),
+ where T is a reference type, that requires a run-time check (5.2.7), or
+ * a potentially evaluated typeid expression (5.2.8) applied to a glvalue
+ expression whose type is a polymorphic class type (10.3). */
+
+static tree
+check_noexcept_r (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
+ void *data ATTRIBUTE_UNUSED)
+{
+ tree t = *tp;
+ enum tree_code code = TREE_CODE (t);
+ if (code == CALL_EXPR
+ || code == AGGR_INIT_EXPR)
+ {
+ /* We can only use the exception specification of the called function
+ for determining the value of a noexcept expression; we can't use
+ TREE_NOTHROW, as it might have a different value in another
+ translation unit, creating ODR problems.
+
+ We could use TREE_NOTHROW (t) for !TREE_PUBLIC fns, though... */
+ tree fn = (code == AGGR_INIT_EXPR
+ ? AGGR_INIT_EXPR_FN (t) : CALL_EXPR_FN (t));
+ tree type = TREE_TYPE (TREE_TYPE (fn));
+
+ STRIP_NOPS (fn);
+ if (TREE_CODE (fn) == ADDR_EXPR)
+ {
+ /* We do use TREE_NOTHROW for ABI internals like __dynamic_cast,
+ and for C library functions known not to throw. */
+ fn = TREE_OPERAND (fn, 0);
+ if (TREE_CODE (fn) == FUNCTION_DECL
+ && DECL_EXTERN_C_P (fn)
+ && (DECL_ARTIFICIAL (fn)
+ || nothrow_libfn_p (fn)))
+ return TREE_NOTHROW (fn) ? NULL_TREE : fn;
+ }
+ if (!TYPE_NOTHROW_P (type))
+ return fn;
+ }
+
+ return NULL_TREE;
+}
+
+/* Evaluate noexcept ( EXPR ). */
+
+tree
+finish_noexcept_expr (tree expr, tsubst_flags_t complain)
+{
+ tree fn;
+
+ if (processing_template_decl)
+ return build_min (NOEXCEPT_EXPR, boolean_type_node, expr);
+
+ fn = cp_walk_tree_without_duplicates (&expr, check_noexcept_r, 0);
+ if (fn)
+ {
+ if ((complain & tf_warning) && TREE_CODE (fn) == FUNCTION_DECL
+ && TREE_NOTHROW (fn) && !DECL_ARTIFICIAL (fn))
+ {
+ warning (OPT_Wnoexcept, "noexcept-expression evaluates to %<false%> "
+ "because of a call to %qD", fn);
+ warning (OPT_Wnoexcept, "but %q+D does not throw; perhaps "
+ "it should be declared %<noexcept%>", fn);
+ }
+ return boolean_false_node;
+ }
+ else
+ return boolean_true_node;
+}
+
+/* Return true iff SPEC is throw() or noexcept(true). */
+
+bool
+nothrow_spec_p (const_tree spec)
+{
+ if (spec == NULL_TREE
+ || TREE_VALUE (spec) != NULL_TREE
+ || spec == noexcept_false_spec)
+ return false;
+ if (TREE_PURPOSE (spec) == NULL_TREE
+ || spec == noexcept_true_spec)
+ return true;
+ gcc_assert (processing_template_decl
+ || TREE_PURPOSE (spec) == error_mark_node);
+ return false;
+}
+
+/* For FUNCTION_TYPE or METHOD_TYPE, true if NODE is noexcept. This is the
+ case for things declared noexcept(true) and, with -fnothrow-opt, for
+ throw() functions. */
+
+bool
+type_noexcept_p (const_tree type)
+{
+ tree spec = TYPE_RAISES_EXCEPTIONS (type);
+ if (flag_nothrow_opt)
+ return nothrow_spec_p (spec);
+ else
+ return spec == noexcept_true_spec;
+}
+
+/* For FUNCTION_TYPE or METHOD_TYPE, true if NODE can throw any type,
+ i.e. no exception-specification or noexcept(false). */
+
+bool
+type_throw_all_p (const_tree type)
+{
+ tree spec = TYPE_RAISES_EXCEPTIONS (type);
+ return spec == NULL_TREE || spec == noexcept_false_spec;
+}
+
+/* Create a representation of the noexcept-specification with
+ constant-expression of EXPR. COMPLAIN is as for tsubst. */
+
+tree
+build_noexcept_spec (tree expr, int complain)
+{
+ expr = perform_implicit_conversion_flags (boolean_type_node, expr,
+ complain,
+ LOOKUP_NORMAL);
+ if (expr == boolean_true_node)
+ return noexcept_true_spec;
+ else if (expr == boolean_false_node)
+ return noexcept_false_spec;
+ else
+ {
+ gcc_assert (processing_template_decl || expr == error_mark_node);
+ return build_tree_list (expr, NULL_TREE);
+ }
+}
diff --git a/gcc/cp/expr.c b/gcc/cp/expr.c
index ef5d6be3c5b..681834d9a37 100644
--- a/gcc/cp/expr.c
+++ b/gcc/cp/expr.c
@@ -1,7 +1,7 @@
/* Convert language-specific tree expression to rtl instructions,
for GNU compiler.
Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
- 2000, 2001, 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
+ 2000, 2001, 2002, 2003, 2004, 2007, 2010 Free Software Foundation, Inc.
This file is part of GCC.
@@ -28,7 +28,6 @@ along with GCC; see the file COPYING3. If not see
#include "flags.h"
#include "cp-tree.h"
#include "toplev.h"
-#include "except.h"
#include "tm_p.h"
/* Expand C++-specific constants. Currently, this means PTRMEM_CST. */
@@ -132,6 +131,7 @@ mark_exp_read (tree exp)
case IMAGPART_EXPR:
CASE_CONVERT:
case ADDR_EXPR:
+ case INDIRECT_REF:
mark_exp_read (TREE_OPERAND (exp, 0));
break;
case COMPOUND_EXPR:
diff --git a/gcc/cp/g++spec.c b/gcc/cp/g++spec.c
index f33affc5e85..2b8081d9141 100644
--- a/gcc/cp/g++spec.c
+++ b/gcc/cp/g++spec.c
@@ -258,7 +258,7 @@ lang_specific_driver (int *in_argc, const char *const **in_argv,
}
if (quote)
- fatal_error ("argument to '%s' missing\n", quote);
+ fatal_error ("argument to %qs missing", quote);
/* There's no point adding -shared-libgcc if we don't have a shared
libgcc. */
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 1f3e8035382..85ad582f2d1 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -30,7 +30,6 @@ along with GCC; see the file COPYING3. If not see
#include "cp-tree.h"
#include "flags.h"
#include "output.h"
-#include "except.h"
#include "toplev.h"
#include "target.h"
@@ -526,7 +525,7 @@ perform_member_init (tree member, tree init)
else if (TREE_CODE (init) == TREE_LIST)
/* There was an explicit member initialization. Do some work
in that case. */
- init = build_x_compound_expr_from_list (init, "member initializer");
+ init = build_x_compound_expr_from_list (init, ELK_MEM_INIT);
if (init)
finish_expr_stmt (cp_build_modify_expr (decl, INIT_EXPR, init,
@@ -1509,8 +1508,17 @@ build_offset_ref (tree type, tree member, bool address_p)
return member;
if (dependent_type_p (type) || type_dependent_expression_p (member))
- return build_qualified_name (NULL_TREE, type, member,
- /*template_p=*/false);
+ {
+ tree ref, mem_type = NULL_TREE;
+ if (!dependent_scope_p (type))
+ mem_type = TREE_TYPE (member);
+ ref = build_qualified_name (mem_type, type, member,
+ /*template_p=*/false);
+ /* Undo convert_from_reference. */
+ if (TREE_CODE (ref) == INDIRECT_REF)
+ ref = TREE_OPERAND (ref, 0);
+ return ref;
+ }
gcc_assert (TYPE_P (type));
if (! is_class_type (type, 1))
@@ -1520,8 +1528,7 @@ build_offset_ref (tree type, tree member, bool address_p)
/* Callers should call mark_used before this point. */
gcc_assert (!DECL_P (member) || TREE_USED (member));
- if (!COMPLETE_TYPE_P (complete_type (type))
- && !TYPE_BEING_DEFINED (type))
+ if (!COMPLETE_OR_OPEN_TYPE_P (complete_type (type)))
{
error ("incomplete type %qT does not have member %qD", type, member);
return error_mark_node;
@@ -2827,7 +2834,7 @@ build_vec_init (tree base, tree maxindex, tree init,
&& TREE_CODE (atype) == ARRAY_TYPE
&& (from_array == 2
? (!CLASS_TYPE_P (inner_elt_type)
- || !TYPE_HAS_COMPLEX_ASSIGN_REF (inner_elt_type))
+ || !TYPE_HAS_COMPLEX_COPY_ASSIGN (inner_elt_type))
: !TYPE_NEEDS_CONSTRUCTING (type))
&& ((TREE_CODE (init) == CONSTRUCTOR
/* Don't do this if the CONSTRUCTOR might contain something
diff --git a/gcc/cp/lang-specs.h b/gcc/cp/lang-specs.h
index 8aa3adf61a7..24213587f76 100644
--- a/gcc/cp/lang-specs.h
+++ b/gcc/cp/lang-specs.h
@@ -1,6 +1,6 @@
/* Definitions for specs for C++.
Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000,
- 2001, 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
+ 2001, 2002, 2003, 2004, 2007, 2010 Free Software Foundation, Inc.
This file is part of GCC.
@@ -47,7 +47,7 @@ along with GCC; see the file COPYING3. If not see
%(cpp_options) %2 -o %{save-temps:%b.ii} %{!save-temps:%g.ii} \n}\
cc1plus %{save-temps|no-integrated-cpp:-fpreprocessed %{save-temps:%b.ii} %{!save-temps:%g.ii}}\
%{!save-temps:%{!no-integrated-cpp:%(cpp_unique_options)}}\
- %(cc1_options) %2 %{+e1*}\
+ %(cc1_options) %2\
%{!fsyntax-only:%{!fdump-ada-spec*:-o %g.s %{!o*:--output-pch=%i.gch}\
%W{o*:--output-pch=%*}}%V}}}}",
CPLUSPLUS_CPP_SPEC, 0, 0},
@@ -58,11 +58,11 @@ along with GCC; see the file COPYING3. If not see
%(cpp_options) %2 -o %{save-temps:%b.ii} %{!save-temps:%g.ii} \n}\
cc1plus %{save-temps|no-integrated-cpp:-fpreprocessed %{save-temps:%b.ii} %{!save-temps:%g.ii}}\
%{!save-temps:%{!no-integrated-cpp:%(cpp_unique_options)}}\
- %(cc1_options) %2 %{+e1*}\
+ %(cc1_options) %2\
%{!fsyntax-only:%(invoke_as)}}}}",
CPLUSPLUS_CPP_SPEC, 0, 0},
{".ii", "@c++-cpp-output", 0, 0, 0},
{"@c++-cpp-output",
"%{!M:%{!MM:%{!E:\
- cc1plus -fpreprocessed %i %(cc1_options) %2 %{+e*}\
+ cc1plus -fpreprocessed %i %(cc1_options) %2\
%{!fsyntax-only:%(invoke_as)}}}}", 0, 0, 0},
diff --git a/gcc/cp/lex.c b/gcc/cp/lex.c
index 041e391f543..9e3b57b75ef 100644
--- a/gcc/cp/lex.c
+++ b/gcc/cp/lex.c
@@ -32,7 +32,7 @@ along with GCC; see the file COPYING3. If not see
#include "cp-tree.h"
#include "cpplib.h"
#include "flags.h"
-#include "c-pragma.h"
+#include "c-family/c-pragma.h"
#include "toplev.h"
#include "output.h"
#include "tm_p.h"
@@ -184,7 +184,7 @@ init_reswords (void)
/* The Objective-C keywords are all context-dependent. */
mask |= D_OBJC;
- ridpointers = GGC_CNEWVEC (tree, (int) RID_MAX);
+ ridpointers = ggc_alloc_cleared_vec_tree ((int) RID_MAX);
for (i = 0; i < num_c_common_reswords; i++)
{
if (c_common_reswords[i].disable & D_CONLY)
@@ -540,7 +540,7 @@ retrofit_lang_decl (tree t)
else
gcc_unreachable ();
- ld = GGC_CNEWVAR (struct lang_decl, size);
+ ld = ggc_alloc_cleared_lang_decl (size);
ld->u.base.selector = sel;
@@ -581,7 +581,7 @@ cxx_dup_lang_specific_decl (tree node)
else
gcc_unreachable ();
- ld = GGC_NEWVAR (struct lang_decl, size);
+ ld = ggc_alloc_lang_decl (size);
memcpy (ld, DECL_LANG_SPECIFIC (node), size);
DECL_LANG_SPECIFIC (node) = ld;
@@ -618,7 +618,7 @@ copy_lang_type (tree node)
size = sizeof (struct lang_type);
else
size = sizeof (struct lang_type_ptrmem);
- lt = GGC_NEWVAR (struct lang_type, size);
+ lt = ggc_alloc_lang_type (size);
memcpy (lt, TYPE_LANG_SPECIFIC (node), size);
TYPE_LANG_SPECIFIC (node) = lt;
@@ -649,7 +649,8 @@ cxx_make_type (enum tree_code code)
if (RECORD_OR_UNION_CODE_P (code)
|| code == BOUND_TEMPLATE_TEMPLATE_PARM)
{
- struct lang_type *pi = GGC_CNEW (struct lang_type);
+ struct lang_type *pi
+ = ggc_alloc_cleared_lang_type (sizeof (struct lang_type));
TYPE_LANG_SPECIFIC (t) = pi;
pi->u.c.h.is_lang_type_class = 1;
diff --git a/gcc/cp/method.c b/gcc/cp/method.c
index 124a83ced3d..ad41e9acc57 100644
--- a/gcc/cp/method.c
+++ b/gcc/cp/method.c
@@ -57,9 +57,8 @@ enum mangling_flags
typedef enum mangling_flags mangling_flags;
-static void do_build_assign_ref (tree);
+static void do_build_copy_assign (tree);
static void do_build_copy_constructor (tree);
-static tree synthesize_exception_spec (tree, tree (*) (tree, void *), void *);
static tree make_alias_for_thunk (tree);
/* Called once to initialize method.c. */
@@ -400,6 +399,74 @@ use_thunk (tree thunk_fndecl, bool emit_p)
/* Code for synthesizing methods which have default semantics defined. */
+/* True iff CTYPE has a trivial SFK. */
+
+static bool
+type_has_trivial_fn (tree ctype, special_function_kind sfk)
+{
+ switch (sfk)
+ {
+ case sfk_constructor:
+ return !TYPE_HAS_COMPLEX_DFLT (ctype);
+ case sfk_copy_constructor:
+ return !TYPE_HAS_COMPLEX_COPY_CTOR (ctype);
+ case sfk_move_constructor:
+ return !TYPE_HAS_COMPLEX_MOVE_CTOR (ctype);
+ case sfk_copy_assignment:
+ return !TYPE_HAS_COMPLEX_COPY_ASSIGN (ctype);
+ case sfk_move_assignment:
+ return !TYPE_HAS_COMPLEX_MOVE_ASSIGN (ctype);
+ case sfk_destructor:
+ return !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype);
+ default:
+ gcc_unreachable ();
+ }
+}
+
+/* Note that CTYPE has a non-trivial SFK even though we previously thought
+ it was trivial. */
+
+static void
+type_set_nontrivial_flag (tree ctype, special_function_kind sfk)
+{
+ switch (sfk)
+ {
+ case sfk_constructor:
+ TYPE_HAS_COMPLEX_DFLT (ctype) = true;
+ return;
+ case sfk_copy_constructor:
+ TYPE_HAS_COMPLEX_COPY_CTOR (ctype) = true;
+ return;
+ case sfk_move_constructor:
+ TYPE_HAS_COMPLEX_MOVE_CTOR (ctype) = true;
+ return;
+ case sfk_copy_assignment:
+ TYPE_HAS_COMPLEX_COPY_ASSIGN (ctype) = true;
+ return;
+ case sfk_move_assignment:
+ TYPE_HAS_COMPLEX_MOVE_ASSIGN (ctype) = true;
+ return;
+ case sfk_destructor:
+ TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype) = true;
+ return;
+ default:
+ gcc_unreachable ();
+ }
+}
+
+/* True iff FN is a trivial defaulted member function ([cd]tor, op=). */
+
+bool
+trivial_fn_p (tree fn)
+{
+ if (!DECL_DEFAULTED_FN (fn))
+ return false;
+
+ /* If fn is a clone, get the primary variant. */
+ fn = DECL_ORIGIN (fn);
+ return type_has_trivial_fn (DECL_CONTEXT (fn), special_function_p (fn));
+}
+
/* Generate code for default X(X&) or X(X&&) constructor. */
static void
@@ -407,14 +474,15 @@ do_build_copy_constructor (tree fndecl)
{
tree parm = FUNCTION_FIRST_USER_PARM (fndecl);
bool move_p = DECL_MOVE_CONSTRUCTOR_P (fndecl);
+ bool trivial = trivial_fn_p (fndecl);
parm = convert_from_reference (parm);
- if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type)
+ if (trivial
&& is_empty_class (current_class_type))
/* Don't copy the padding byte; it might not have been allocated
if *this is a base subobject. */;
- else if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type))
+ else if (trivial)
{
tree t = build2 (INIT_EXPR, void_type_node, current_class_ref, parm);
finish_expr_stmt (t);
@@ -508,19 +576,21 @@ do_build_copy_constructor (tree fndecl)
}
static void
-do_build_assign_ref (tree fndecl)
+do_build_copy_assign (tree fndecl)
{
tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
tree compound_stmt;
+ bool move_p = move_fn_p (fndecl);
+ bool trivial = trivial_fn_p (fndecl);
compound_stmt = begin_compound_stmt (0);
parm = convert_from_reference (parm);
- if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type)
+ if (trivial
&& is_empty_class (current_class_type))
/* Don't copy the padding byte; it might not have been allocated
if *this is a base subobject. */;
- else if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type))
+ else if (trivial)
{
tree t = build2 (MODIFY_EXPR, void_type_node, current_class_ref, parm);
finish_expr_stmt (t);
@@ -542,6 +612,8 @@ do_build_assign_ref (tree fndecl)
/* We must convert PARM directly to the base class
explicitly since the base class may be ambiguous. */
converted_parm = build_base_path (PLUS_EXPR, parm, base_binfo, 1);
+ if (move_p)
+ converted_parm = move (converted_parm);
/* Call the base class assignment operator. */
parmvec = make_tree_vector_single (converted_parm);
finish_expr_stmt
@@ -604,6 +676,8 @@ do_build_assign_ref (tree fndecl)
expr_type = cp_build_qualified_type (expr_type, quals);
init = build3 (COMPONENT_REF, expr_type, init, field, NULL_TREE);
+ if (move_p && TREE_CODE (expr_type) != REFERENCE_TYPE)
+ init = move (init);
if (DECL_NAME (field))
init = cp_build_modify_expr (comp, NOP_EXPR, init,
@@ -657,7 +731,7 @@ synthesize_method (tree fndecl)
if (DECL_OVERLOADED_OPERATOR_P (fndecl) == NOP_EXPR)
{
- do_build_assign_ref (fndecl);
+ do_build_copy_assign (fndecl);
need_body = false;
}
else if (DECL_CONSTRUCTOR_P (fndecl))
@@ -695,163 +769,505 @@ synthesize_method (tree fndecl)
fndecl);
}
-/* Use EXTRACTOR to locate the relevant function called for each base &
- class field of TYPE. CLIENT allows additional information to be passed
- to EXTRACTOR. Generates the union of all exceptions generated by those
- functions. Note that we haven't updated TYPE_FIELDS and such of any
- variants yet, so we need to look at the main one. */
+/* Build a reference to type TYPE with cv-quals QUALS, which is an
+ rvalue if RVALUE is true. */
static tree
-synthesize_exception_spec (tree type, tree (*extractor) (tree, void*),
- void *client)
+build_stub_type (tree type, int quals, bool rvalue)
{
- tree raises = empty_except_spec;
- tree fields = TYPE_FIELDS (type);
- tree binfo, base_binfo;
- int i;
+ tree argtype = cp_build_qualified_type (type, quals);
+ return cp_build_reference_type (argtype, rvalue);
+}
- for (binfo = TYPE_BINFO (type), i = 0;
- BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
- {
- tree fn = (*extractor) (BINFO_TYPE (base_binfo), client);
- if (fn)
- {
- tree fn_raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn));
+/* Build a dummy glvalue from dereferencing a dummy reference of type
+ REFTYPE. */
- raises = merge_exception_specifiers (raises, fn_raises);
- }
- }
- for (; fields; fields = TREE_CHAIN (fields))
- {
- tree type = TREE_TYPE (fields);
- tree fn;
+static tree
+build_stub_object (tree reftype)
+{
+ tree stub = build1 (NOP_EXPR, reftype, integer_one_node);
+ return convert_from_reference (stub);
+}
- if (TREE_CODE (fields) != FIELD_DECL || DECL_ARTIFICIAL (fields))
- continue;
- while (TREE_CODE (type) == ARRAY_TYPE)
- type = TREE_TYPE (type);
- if (!CLASS_TYPE_P (type))
- continue;
+/* Determine which function will be called when looking up NAME in TYPE,
+ called with a single ARGTYPE argument, or no argument if ARGTYPE is
+ null. FLAGS and COMPLAIN are as for build_new_method_call.
- fn = (*extractor) (type, client);
- if (fn)
- {
- tree fn_raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn));
+ Returns a FUNCTION_DECL if all is well.
+ Returns NULL_TREE if overload resolution failed.
+ Returns error_mark_node if the chosen function cannot be called. */
- raises = merge_exception_specifiers (raises, fn_raises);
- }
+static tree
+locate_fn_flags (tree type, tree name, tree argtype, int flags,
+ tsubst_flags_t complain)
+{
+ tree ob, fn, fns, binfo, rval;
+ VEC(tree,gc) *args;
+
+ if (TYPE_P (type))
+ binfo = TYPE_BINFO (type);
+ else
+ {
+ binfo = type;
+ type = BINFO_TYPE (binfo);
+ }
+
+ ob = build_stub_object (cp_build_reference_type (type, false));
+ args = make_tree_vector ();
+ if (argtype)
+ {
+ tree arg = build_stub_object (argtype);
+ VEC_quick_push (tree, args, arg);
}
- return raises;
+
+ fns = lookup_fnfields (binfo, name, 0);
+ rval = build_new_method_call (ob, fns, &args, binfo, flags, &fn, complain);
+
+ release_tree_vector (args);
+ if (fn && rval == error_mark_node)
+ return rval;
+ else
+ return fn;
}
/* Locate the dtor of TYPE. */
tree
-locate_dtor (tree type, void *client ATTRIBUTE_UNUSED)
+get_dtor (tree type)
{
- return CLASSTYPE_DESTRUCTORS (type);
+ tree fn = locate_fn_flags (type, complete_dtor_identifier, NULL_TREE,
+ LOOKUP_NORMAL, tf_warning_or_error);
+ if (fn == error_mark_node)
+ return NULL_TREE;
+ return fn;
}
/* Locate the default ctor of TYPE. */
tree
-locate_ctor (tree type, void *client ATTRIBUTE_UNUSED)
+locate_ctor (tree type)
{
- tree fns;
+ tree fn = locate_fn_flags (type, complete_ctor_identifier, NULL_TREE,
+ LOOKUP_SPECULATIVE, tf_none);
+ if (fn == error_mark_node)
+ return NULL_TREE;
+ return fn;
+}
- if (!TYPE_HAS_DEFAULT_CONSTRUCTOR (type))
+/* Likewise, but give any appropriate errors. */
+
+tree
+get_default_ctor (tree type)
+{
+ tree fn = locate_fn_flags (type, complete_ctor_identifier, NULL_TREE,
+ LOOKUP_NORMAL, tf_warning_or_error);
+ if (fn == error_mark_node)
return NULL_TREE;
+ return fn;
+}
+
+/* Locate the copy ctor of TYPE. */
+
+tree
+get_copy_ctor (tree type)
+{
+ int quals = (TYPE_HAS_CONST_COPY_CTOR (type)
+ ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
+ tree argtype = build_stub_type (type, quals, false);
+ tree fn = locate_fn_flags (type, complete_ctor_identifier, argtype,
+ LOOKUP_NORMAL, tf_warning_or_error);
+ if (fn == error_mark_node)
+ return NULL_TREE;
+ return fn;
+}
- /* Call lookup_fnfields_1 to create the constructor declarations, if
- necessary. */
- if (CLASSTYPE_LAZY_DEFAULT_CTOR (type))
- return lazily_declare_fn (sfk_constructor, type);
+/* Locate the copy assignment operator of TYPE. */
- for (fns = CLASSTYPE_CONSTRUCTORS (type); fns; fns = OVL_NEXT (fns))
+tree
+get_copy_assign (tree type)
+{
+ int quals = (TYPE_HAS_CONST_COPY_ASSIGN (type)
+ ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
+ tree argtype = build_stub_type (type, quals, false);
+ tree fn = locate_fn_flags (type, ansi_assopname (NOP_EXPR), argtype,
+ LOOKUP_NORMAL, tf_warning_or_error);
+ if (fn == error_mark_node)
+ return NULL_TREE;
+ return fn;
+}
+
+/* Subroutine of synthesized_method_walk. Update SPEC_P, TRIVIAL_P and
+ DELETED_P or give an error message MSG with argument ARG. */
+
+static void
+process_subob_fn (tree fn, bool move_p, tree *spec_p, bool *trivial_p,
+ bool *deleted_p, const char *msg, tree arg)
+{
+ if (!fn || fn == error_mark_node)
+ goto bad;
+
+ if (spec_p)
{
- tree fn = OVL_CURRENT (fns);
- tree parms = TYPE_ARG_TYPES (TREE_TYPE (fn));
+ tree raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn));
+ *spec_p = merge_exception_specifiers (*spec_p, raises);
+ }
- parms = skip_artificial_parms_for (fn, parms);
+ if (trivial_p && !trivial_fn_p (fn))
+ *trivial_p = false;
- if (sufficient_parms_p (parms))
- return fn;
+ if (move_p && !move_fn_p (fn) && !trivial_fn_p (fn))
+ {
+ if (msg)
+ error (msg, arg);
+ goto bad;
}
- gcc_unreachable ();
+
+ return;
+
+ bad:
+ if (deleted_p)
+ *deleted_p = true;
}
-struct copy_data
+/* The caller wants to generate an implicit declaration of SFK for CTYPE
+ which is const if relevant and CONST_P is set. If spec_p, trivial_p and
+ deleted_p are non-null, set their referent appropriately. If diag is
+ true, we're being called from maybe_explain_implicit_delete to give
+ errors. */
+
+static void
+synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p,
+ tree *spec_p, bool *trivial_p, bool *deleted_p,
+ bool diag)
{
- tree name;
- int quals;
-};
+ tree binfo, base_binfo, field, scope, fnname, rval, argtype;
+ bool move_p, copy_arg_p, assign_p, expected_trivial, check_vdtor;
+ VEC(tree,gc) *vbases;
+ int i, quals, flags;
+ tsubst_flags_t complain;
+ const char *msg;
+
+ if (spec_p)
+ *spec_p = (cxx_dialect >= cxx0x
+ ? noexcept_true_spec : empty_except_spec);
+
+ if (deleted_p)
+ {
+ /* "The closure type associated with a lambda-expression has a deleted
+ default constructor and a deleted copy assignment operator."
+ This is diagnosed in maybe_explain_implicit_delete. */
+ if (LAMBDA_TYPE_P (ctype)
+ && (sfk == sfk_constructor
+ || sfk == sfk_copy_assignment))
+ {
+ *deleted_p = true;
+ return;
+ }
-/* Locate the copy ctor or copy assignment of TYPE. CLIENT_
- points to a COPY_DATA holding the name (NULL for the ctor)
- and desired qualifiers of the source operand. */
+ *deleted_p = false;
+ }
-tree
-locate_copy (tree type, void *client_)
-{
- struct copy_data *client = (struct copy_data *)client_;
- tree fns;
- tree best = NULL_TREE;
- bool excess_p = false;
+ move_p = false;
+ switch (sfk)
+ {
+ case sfk_constructor:
+ case sfk_destructor:
+ copy_arg_p = false;
+ break;
- if (client->name)
+ case sfk_move_constructor:
+ case sfk_move_assignment:
+ move_p = true;
+ case sfk_copy_constructor:
+ case sfk_copy_assignment:
+ copy_arg_p = true;
+ break;
+
+ default:
+ gcc_unreachable ();
+ }
+
+ expected_trivial = type_has_trivial_fn (ctype, sfk);
+ if (trivial_p)
+ *trivial_p = expected_trivial;
+
+#ifndef ENABLE_CHECKING
+ /* The TYPE_HAS_COMPLEX_* flags tell us about constraints from base
+ class versions and other properties of the type. But a subobject
+ class can be trivially copyable and yet have overload resolution
+ choose a template constructor for initialization, depending on
+ rvalueness and cv-quals. So we can't exit early for copy/move
+ methods in C++0x. */
+ if (expected_trivial
+ && (!copy_arg_p || cxx_dialect < cxx0x))
+ return;
+#endif
+
+ assign_p = false;
+ switch (sfk)
{
- int ix;
- ix = lookup_fnfields_1 (type, client->name);
- if (ix < 0)
- return NULL_TREE;
- fns = VEC_index (tree, CLASSTYPE_METHOD_VEC (type), ix);
+ case sfk_move_assignment:
+ case sfk_copy_assignment:
+ assign_p = true;
+ fnname = ansi_assopname (NOP_EXPR);
+ break;
+
+ case sfk_destructor:
+ check_vdtor = true;
+ /* The synthesized method will call base dtors, but check complete
+ here to avoid having to deal with VTT. */
+ fnname = complete_dtor_identifier;
+ break;
+
+ case sfk_constructor:
+ case sfk_move_constructor:
+ case sfk_copy_constructor:
+ fnname = complete_ctor_identifier;
+ break;
+
+ default:
+ gcc_unreachable ();
}
- else if (TYPE_HAS_INIT_REF (type))
+
+ ++cp_unevaluated_operand;
+ ++c_inhibit_evaluation_warnings;
+
+ scope = push_scope (ctype);
+
+ if (diag)
{
- /* If construction of the copy constructor was postponed, create
- it now. */
- if (CLASSTYPE_LAZY_COPY_CTOR (type))
- lazily_declare_fn (sfk_copy_constructor, type);
- if (CLASSTYPE_LAZY_MOVE_CTOR (type))
- lazily_declare_fn (sfk_move_constructor, type);
- fns = CLASSTYPE_CONSTRUCTORS (type);
+ flags = LOOKUP_NORMAL|LOOKUP_SPECULATIVE;
+ complain = tf_warning_or_error;
}
else
- return NULL_TREE;
- for (; fns; fns = OVL_NEXT (fns))
{
- tree fn = OVL_CURRENT (fns);
- tree parms = TYPE_ARG_TYPES (TREE_TYPE (fn));
- tree src_type;
- int excess;
- int quals;
-
- parms = skip_artificial_parms_for (fn, parms);
- if (!parms)
- continue;
- src_type = non_reference (TREE_VALUE (parms));
+ flags = LOOKUP_PROTECT|LOOKUP_SPECULATIVE;
+ complain = tf_none;
+ }
- if (src_type == error_mark_node)
- return NULL_TREE;
+ if (const_p)
+ quals = TYPE_QUAL_CONST;
+ else
+ quals = TYPE_UNQUALIFIED;
+ argtype = NULL_TREE;
- if (!same_type_ignoring_top_level_qualifiers_p (src_type, type))
- continue;
- if (!sufficient_parms_p (TREE_CHAIN (parms)))
+ for (binfo = TYPE_BINFO (ctype), i = 0;
+ BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
+ {
+ tree basetype = BINFO_TYPE (base_binfo);
+ if (copy_arg_p)
+ argtype = build_stub_type (basetype, quals, move_p);
+ rval = locate_fn_flags (base_binfo, fnname, argtype, flags, complain);
+
+ if (!diag)
+ msg = NULL;
+ else if (assign_p)
+ msg = ("base %qT does not have a move assignment operator or trivial "
+ "copy assignment operator");
+ else
+ msg = ("base %qT does not have a move constructor or trivial "
+ "copy constructor");
+
+ process_subob_fn (rval, move_p, spec_p, trivial_p, deleted_p,
+ msg, BINFO_TYPE (base_binfo));
+
+ if (check_vdtor && type_has_virtual_destructor (basetype))
+ {
+ rval = locate_fn_flags (ctype, ansi_opname (DELETE_EXPR),
+ ptr_type_node, flags, complain);
+ /* Unlike for base ctor/op=/dtor, for operator delete it's fine
+ to have a null rval (no class-specific op delete). */
+ if (rval && rval == error_mark_node && deleted_p)
+ *deleted_p = true;
+ }
+ }
+
+ vbases = CLASSTYPE_VBASECLASSES (ctype);
+ if (vbases && assign_p && move_p)
+ {
+ /* Should the spec be changed to allow vbases that only occur once? */
+ if (diag)
+ error ("%qT has virtual bases, default move assignment operator "
+ "cannot be generated", ctype);
+ else if (deleted_p)
+ *deleted_p = true;
+ }
+ else if (!assign_p)
+ for (i = 0; VEC_iterate (tree, vbases, i, base_binfo); ++i)
+ {
+ if (copy_arg_p)
+ argtype = build_stub_type (BINFO_TYPE (base_binfo), quals, move_p);
+ rval = locate_fn_flags (base_binfo, fnname, argtype, flags, complain);
+
+ if (!diag)
+ msg = NULL;
+ else if (assign_p)
+ msg = ("virtual base %qT does not have a move assignment "
+ "operator or trivial copy assignment operator");
+ else
+ msg = ("virtual base %qT does not have a move constructor "
+ "or trivial copy constructor");
+
+ process_subob_fn (rval, move_p, spec_p, trivial_p, deleted_p,
+ msg, BINFO_TYPE (base_binfo));
+ }
+
+ for (field = TYPE_FIELDS (ctype); field; field = TREE_CHAIN (field))
+ {
+ tree mem_type;
+
+ if (TREE_CODE (field) != FIELD_DECL
+ || DECL_ARTIFICIAL (field))
continue;
- quals = cp_type_quals (src_type);
- if (client->quals & ~quals)
+
+ mem_type = strip_array_types (TREE_TYPE (field));
+ if (assign_p)
+ {
+ bool bad = true;
+ if (CP_TYPE_CONST_P (mem_type) && !CLASS_TYPE_P (mem_type))
+ {
+ if (diag)
+ error ("non-static const member %q#D, can't use default "
+ "assignment operator", field);
+ }
+ else if (TREE_CODE (mem_type) == REFERENCE_TYPE)
+ {
+ if (diag)
+ error ("non-static reference member %q#D, can't use "
+ "default assignment operator", field);
+ }
+ else
+ bad = false;
+
+ if (bad && deleted_p)
+ *deleted_p = true;
+ }
+ else if (sfk == sfk_constructor)
+ {
+ bool bad = true;
+ if (CP_TYPE_CONST_P (mem_type)
+ && (!CLASS_TYPE_P (mem_type)
+ || !type_has_user_provided_default_constructor (mem_type)))
+ {
+ if (diag)
+ error ("uninitialized non-static const member %q#D",
+ field);
+ }
+ else if (TREE_CODE (mem_type) == REFERENCE_TYPE)
+ {
+ if (diag)
+ error ("uninitialized non-static reference member %q#D",
+ field);
+ }
+ else
+ bad = false;
+
+ if (bad && deleted_p)
+ *deleted_p = true;
+ }
+
+ if (!CLASS_TYPE_P (mem_type)
+ || ANON_AGGR_TYPE_P (mem_type))
continue;
- excess = quals & ~client->quals;
- if (!best || (excess_p && !excess))
+
+ if (copy_arg_p)
{
- best = fn;
- excess_p = excess;
+ int mem_quals = cp_type_quals (mem_type) | quals;
+ if (DECL_MUTABLE_P (field))
+ mem_quals &= ~TYPE_QUAL_CONST;
+ argtype = build_stub_type (mem_type, mem_quals, move_p);
}
+
+ rval = locate_fn_flags (mem_type, fnname, argtype, flags, complain);
+
+ if (!diag)
+ msg = NULL;
+ else if (assign_p)
+ msg = ("non-static data member %qD does not have a move "
+ "assignment operator or trivial copy assignment operator");
else
- /* Ambiguous */
- return NULL_TREE;
+ msg = ("non-static data member %qD does not have a move "
+ "constructor or trivial copy constructor");
+
+ process_subob_fn (rval, move_p, spec_p, trivial_p, deleted_p,
+ msg, field);
}
- return best;
+
+ pop_scope (scope);
+
+ --cp_unevaluated_operand;
+ --c_inhibit_evaluation_warnings;
+
+#ifdef ENABLE_CHECKING
+ /* If we expected this to be trivial but it isn't, then either we're in
+ C++0x mode and this is a copy/move ctor/op= or there's an error. */
+ gcc_assert (!(trivial_p && expected_trivial && !*trivial_p)
+ || (copy_arg_p && cxx_dialect >= cxx0x)
+ || errorcount);
+#endif
+}
+
+/* DECL is a deleted function. If it's implicitly deleted, explain why and
+ return true; else return false. */
+
+bool
+maybe_explain_implicit_delete (tree decl)
+{
+ /* If decl is a clone, get the primary variant. */
+ decl = DECL_ORIGIN (decl);
+ gcc_assert (DECL_DELETED_FN (decl));
+ if (DECL_DEFAULTED_FN (decl)
+ && DECL_INITIAL (decl) == NULL_TREE)
+ {
+ /* Not marked GTY; it doesn't need to be GC'd or written to PCH. */
+ static htab_t explained_htab;
+ void **slot;
+
+ special_function_kind sfk;
+ location_t loc;
+ bool informed;
+ tree ctype;
+
+ if (!explained_htab)
+ explained_htab = htab_create (37, htab_hash_pointer,
+ htab_eq_pointer, NULL);
+ slot = htab_find_slot (explained_htab, decl, INSERT);
+ if (*slot)
+ return true;
+ *slot = decl;
+
+ sfk = special_function_p (decl);
+ ctype = DECL_CONTEXT (decl);
+ loc = input_location;
+ input_location = DECL_SOURCE_LOCATION (decl);
+
+ informed = false;
+ if (LAMBDA_TYPE_P (ctype))
+ {
+ informed = true;
+ if (sfk == sfk_constructor)
+ error ("a lambda closure type has a deleted default constructor");
+ else if (sfk == sfk_copy_assignment)
+ error ("a lambda closure type has a deleted copy assignment operator");
+ else
+ informed = false;
+ }
+ if (!informed)
+ {
+ tree parm_type = TREE_VALUE (FUNCTION_FIRST_USER_PARMTYPE (decl));
+ bool const_p = CP_TYPE_CONST_P (non_reference (parm_type));
+ tree scope = push_scope (ctype);
+ error ("%qD is implicitly deleted because the default "
+ "definition would be ill-formed:", decl);
+ pop_scope (scope);
+ synthesized_method_walk (ctype, sfk, const_p,
+ NULL, NULL, NULL, true);
+ }
+
+ input_location = loc;
+ return true;
+ }
+ return false;
}
/* Implicitly declare the special function indicated by KIND, as a
@@ -872,6 +1288,8 @@ implicitly_declare_fn (special_function_kind kind, tree type, bool const_p)
tree this_parm;
tree name;
HOST_WIDE_INT saved_processing_template_decl;
+ bool deleted_p;
+ bool trivial_p;
/* Because we create declarations for implicitly declared functions
lazily, we may be creating the declaration for a member of TYPE
@@ -903,50 +1321,49 @@ implicitly_declare_fn (special_function_kind kind, tree type, bool const_p)
case sfk_destructor:
/* Destructor. */
name = constructor_name (type);
- raises = synthesize_exception_spec (type, &locate_dtor, 0);
break;
case sfk_constructor:
/* Default constructor. */
name = constructor_name (type);
- raises = synthesize_exception_spec (type, &locate_ctor, 0);
break;
case sfk_copy_constructor:
- case sfk_assignment_operator:
+ case sfk_copy_assignment:
case sfk_move_constructor:
+ case sfk_move_assignment:
{
- struct copy_data data;
-
- data.name = NULL;
- data.quals = 0;
- if (kind == sfk_assignment_operator)
+ bool move_p;
+ if (kind == sfk_copy_assignment
+ || kind == sfk_move_assignment)
{
return_type = build_reference_type (type);
name = ansi_assopname (NOP_EXPR);
- data.name = name;
}
else
name = constructor_name (type);
if (const_p)
- {
- data.quals = TYPE_QUAL_CONST;
- rhs_parm_type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
- }
+ rhs_parm_type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
else
rhs_parm_type = type;
- rhs_parm_type
- = cp_build_reference_type (rhs_parm_type,
- kind == sfk_move_constructor);
+ move_p = (kind == sfk_move_assignment
+ || kind == sfk_move_constructor);
+ rhs_parm_type = cp_build_reference_type (rhs_parm_type, move_p);
+
parameter_types = tree_cons (NULL_TREE, rhs_parm_type, parameter_types);
- raises = synthesize_exception_spec (type, &locate_copy, &data);
break;
}
default:
gcc_unreachable ();
}
+ synthesized_method_walk (type, kind, const_p, &raises, &trivial_p,
+ &deleted_p, false);
+
+ if (!trivial_p && type_has_trivial_fn (type, kind))
+ type_set_nontrivial_flag (type, kind);
+
/* Create the function. */
fn_type = build_method_type_directly (type, return_type, parameter_types);
if (raises)
@@ -991,6 +1408,8 @@ implicitly_declare_fn (special_function_kind kind, tree type, bool const_p)
DECL_IN_AGGR_P (fn) = 1;
DECL_ARTIFICIAL (fn) = 1;
DECL_DEFAULTED_FN (fn) = 1;
+ if (cxx_dialect >= cxx0x)
+ DECL_DELETED_FN (fn) = deleted_p;
DECL_NOT_REALLY_EXTERN (fn) = 1;
DECL_DECLARED_INLINE_P (fn) = 1;
gcc_assert (!TREE_USED (fn));
@@ -1022,6 +1441,18 @@ defaulted_late_check (tree fn)
error_at (DECL_SOURCE_LOCATION (fn),
"does not match expected signature %qD", implicit_fn);
}
+
+ /* 8.4.2/2: If it is explicitly defaulted on its first declaration, it is
+ implicitly considered to have the same exception-specification as if
+ it had been implicitly declared. */
+ if (DECL_DEFAULTED_IN_CLASS_P (fn))
+ {
+ tree eh_spec = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (implicit_fn));
+ TREE_TYPE (fn) = build_exception_variant (TREE_TYPE (fn), eh_spec);
+ }
+
+ if (DECL_DELETED_FN (implicit_fn))
+ DECL_DELETED_FN (fn) = 1;
}
/* Returns true iff FN can be explicitly defaulted, and gives any
@@ -1046,9 +1477,13 @@ defaultable_fn_check (tree fn)
else if (DECL_DESTRUCTOR_P (fn))
kind = sfk_destructor;
else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
- && DECL_OVERLOADED_OPERATOR_P (fn) == NOP_EXPR
- && copy_fn_p (fn))
- kind = sfk_assignment_operator;
+ && DECL_OVERLOADED_OPERATOR_P (fn) == NOP_EXPR)
+ {
+ if (copy_fn_p (fn))
+ kind = sfk_copy_assignment;
+ else if (move_fn_p (fn))
+ kind = sfk_move_assignment;
+ }
if (kind == sfk_none)
{
@@ -1094,21 +1529,49 @@ tree
lazily_declare_fn (special_function_kind sfk, tree type)
{
tree fn;
- bool const_p;
-
- /* Figure out whether or not the argument has a const reference
- type. */
- if (sfk == sfk_copy_constructor)
- const_p = TYPE_HAS_CONST_INIT_REF (type);
- else if (sfk == sfk_assignment_operator)
- const_p = TYPE_HAS_CONST_ASSIGN_REF (type);
- else
- /* In this case, CONST_P will be ignored. */
- const_p = false;
+ /* Whether or not the argument has a const reference type. */
+ bool const_p = false;
+
+ switch (sfk)
+ {
+ case sfk_constructor:
+ CLASSTYPE_LAZY_DEFAULT_CTOR (type) = 0;
+ break;
+ case sfk_copy_constructor:
+ const_p = TYPE_HAS_CONST_COPY_CTOR (type);
+ CLASSTYPE_LAZY_COPY_CTOR (type) = 0;
+ break;
+ case sfk_move_constructor:
+ CLASSTYPE_LAZY_MOVE_CTOR (type) = 0;
+ break;
+ case sfk_copy_assignment:
+ const_p = TYPE_HAS_CONST_COPY_ASSIGN (type);
+ CLASSTYPE_LAZY_COPY_ASSIGN (type) = 0;
+ break;
+ case sfk_move_assignment:
+ CLASSTYPE_LAZY_MOVE_ASSIGN (type) = 0;
+ break;
+ case sfk_destructor:
+ CLASSTYPE_LAZY_DESTRUCTOR (type) = 0;
+ break;
+ default:
+ gcc_unreachable ();
+ }
+
/* Declare the function. */
fn = implicitly_declare_fn (sfk, type, const_p);
+
+ /* For move variants, rather than declare them as deleted we just
+ don't declare them at all. */
+ if (DECL_DELETED_FN (fn)
+ && (sfk == sfk_move_constructor
+ || sfk == sfk_move_assignment))
+ return NULL_TREE;
+
/* A destructor may be virtual. */
- if (sfk == sfk_destructor)
+ if (sfk == sfk_destructor
+ || sfk == sfk_move_assignment
+ || sfk == sfk_copy_assignment)
check_for_override (fn, type);
/* Add it to CLASSTYPE_METHOD_VEC. */
add_method (type, fn, NULL_TREE);
@@ -1133,22 +1596,10 @@ lazily_declare_fn (special_function_kind sfk, tree type)
TYPE_METHODS (type) = fn;
}
maybe_add_class_template_decl_list (type, fn, /*friend_p=*/0);
- if (sfk == sfk_assignment_operator)
- CLASSTYPE_LAZY_ASSIGNMENT_OP (type) = 0;
- else
- {
- /* Remember that the function has been created. */
- if (sfk == sfk_constructor)
- CLASSTYPE_LAZY_DEFAULT_CTOR (type) = 0;
- else if (sfk == sfk_copy_constructor)
- CLASSTYPE_LAZY_COPY_CTOR (type) = 0;
- else if (sfk == sfk_move_constructor)
- CLASSTYPE_LAZY_MOVE_CTOR (type) = 0;
- else if (sfk == sfk_destructor)
- CLASSTYPE_LAZY_DESTRUCTOR (type) = 0;
- /* Create appropriate clones. */
- clone_function_decl (fn, /*update_method_vec=*/true);
- }
+ if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn)
+ || DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fn))
+ /* Create appropriate clones. */
+ clone_function_decl (fn, /*update_method_vec=*/true);
return fn;
}
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index 936c25638e0..67131190305 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -31,7 +31,7 @@ along with GCC; see the file COPYING3. If not see
#include "toplev.h"
#include "diagnostic-core.h"
#include "debug.h"
-#include "c-pragma.h"
+#include "c-family/c-pragma.h"
/* The bindings for a particular name in a particular scope. */
@@ -102,7 +102,7 @@ binding_entry_make (tree name, tree type)
free_binding_entry = entry->chain;
}
else
- entry = GGC_NEW (struct binding_entry_s);
+ entry = ggc_alloc_binding_entry_s ();
entry->name = name;
entry->type = type;
@@ -144,7 +144,7 @@ binding_table_construct (binding_table table, size_t chain_count)
{
table->chain_count = chain_count;
table->entry_count = 0;
- table->chain = GGC_CNEWVEC (binding_entry, table->chain_count);
+ table->chain = ggc_alloc_cleared_vec_binding_entry (table->chain_count);
}
/* Make TABLE's entries ready for reuse. */
@@ -178,7 +178,7 @@ binding_table_free (binding_table table)
static inline binding_table
binding_table_new (size_t chain_count)
{
- binding_table table = GGC_NEW (struct binding_table_s);
+ binding_table table = ggc_alloc_binding_table_s ();
table->chain = NULL;
binding_table_construct (table, chain_count);
return table;
@@ -292,7 +292,7 @@ cxx_binding_make (tree value, tree type)
free_bindings = binding->previous;
}
else
- binding = GGC_NEW (cxx_binding);
+ binding = ggc_alloc_cxx_binding ();
cxx_binding_init (binding, value, type);
@@ -707,7 +707,7 @@ pushdecl_maybe_friend (tree x, bool is_friend)
= htab_create_ggc (20, cxx_int_tree_map_hash,
cxx_int_tree_map_eq, NULL);
- h = GGC_NEW (struct cxx_int_tree_map);
+ h = ggc_alloc_cxx_int_tree_map ();
h->uid = DECL_UID (x);
h->to = t;
loc = htab_find_slot_with_hash
@@ -805,7 +805,7 @@ pushdecl_maybe_friend (tree x, bool is_friend)
TYPE_RAISES_EXCEPTIONS (TREE_TYPE (previous));
if (!comp_except_specs (previous_exception_spec,
x_exception_spec,
- true))
+ ce_normal))
{
pedwarn (input_location, 0, "declaration of %q#D with C language linkage",
x);
@@ -1384,7 +1384,7 @@ begin_scope (scope_kind kind, tree entity)
free_binding_level = scope->level_chain;
}
else
- scope = GGC_CNEW (cxx_scope);
+ scope = ggc_alloc_cleared_cxx_scope ();
scope->this_entity = entity;
scope->more_cleanups_ok = true;
@@ -2480,6 +2480,8 @@ push_scope (tree t)
void
pop_scope (tree t)
{
+ if (t == NULL_TREE)
+ return;
if (TREE_CODE (t) == NAMESPACE_DECL)
pop_decl_namespace ();
else if CLASS_TYPE_P (t)
@@ -3195,8 +3197,8 @@ current_decl_namespace (void)
{
tree result;
/* If we have been pushed into a different namespace, use it. */
- if (decl_namespace_list)
- return TREE_PURPOSE (decl_namespace_list);
+ if (!VEC_empty (tree, decl_namespace_list))
+ return VEC_last (tree, decl_namespace_list);
if (current_class_type)
result = decl_namespace_context (current_class_type);
@@ -3380,8 +3382,7 @@ push_decl_namespace (tree decl)
{
if (TREE_CODE (decl) != NAMESPACE_DECL)
decl = decl_namespace_context (decl);
- decl_namespace_list = tree_cons (ORIGINAL_NAMESPACE (decl),
- NULL_TREE, decl_namespace_list);
+ VEC_safe_push (tree, gc, decl_namespace_list, ORIGINAL_NAMESPACE (decl));
}
/* [namespace.memdef]/2 */
@@ -3389,7 +3390,7 @@ push_decl_namespace (tree decl)
void
pop_decl_namespace (void)
{
- decl_namespace_list = TREE_CHAIN (decl_namespace_list);
+ VEC_pop (tree, decl_namespace_list);
}
/* Return the namespace that is the common ancestor
@@ -4589,8 +4590,8 @@ struct arg_lookup
{
tree name;
VEC(tree,gc) *args;
- tree namespaces;
- tree classes;
+ VEC(tree,gc) *namespaces;
+ VEC(tree,gc) *classes;
tree functions;
};
@@ -4667,9 +4668,9 @@ arg_assoc_namespace (struct arg_lookup *k, tree scope)
{
tree value;
- if (purpose_member (scope, k->namespaces))
- return 0;
- k->namespaces = tree_cons (scope, NULL_TREE, k->namespaces);
+ if (vec_member (scope, k->namespaces))
+ return false;
+ VEC_safe_push (tree, gc, k->namespaces, scope);
/* Check out our super-users. */
for (value = DECL_NAMESPACE_ASSOCIATIONS (scope); value;
@@ -4850,9 +4851,9 @@ arg_assoc_class (struct arg_lookup *k, tree type)
if (!CLASS_TYPE_P (type))
return false;
- if (purpose_member (type, k->classes))
+ if (vec_member (type, k->classes))
return false;
- k->classes = tree_cons (type, NULL_TREE, k->classes);
+ VEC_safe_push (tree, gc, k->classes, type);
if (TYPE_CLASS_SCOPE_P (type)
&& arg_assoc_class_only (k, TYPE_CONTEXT (type)))
@@ -5049,14 +5050,14 @@ lookup_arg_dependent (tree name, tree fns, VEC(tree,gc) *args)
k.name = name;
k.args = args;
k.functions = fns;
- k.classes = NULL_TREE;
+ k.classes = make_tree_vector ();
/* We previously performed an optimization here by setting
NAMESPACES to the current namespace when it was safe. However, DR
164 says that namespaces that were already searched in the first
stage of template processing are searched again (potentially
picking up later definitions) in the second stage. */
- k.namespaces = NULL_TREE;
+ k.namespaces = make_tree_vector ();
arg_assoc_args_vec (&k, args);
@@ -5070,6 +5071,9 @@ lookup_arg_dependent (tree name, tree fns, VEC(tree,gc) *args)
error (" in call to %qD", name);
fns = error_mark_node;
}
+
+ release_tree_vector (k.classes);
+ release_tree_vector (k.namespaces);
POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, fns);
}
@@ -5406,7 +5410,7 @@ push_to_top_level (void)
bool need_pop;
timevar_push (TV_NAME_LOOKUP);
- s = GGC_CNEW (struct saved_scope);
+ s = ggc_alloc_cleared_saved_scope ();
b = scope_chain ? current_binding_level : 0;
diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h
index 08514810ab0..e5190eba93f 100644
--- a/gcc/cp/name-lookup.h
+++ b/gcc/cp/name-lookup.h
@@ -22,7 +22,7 @@ along with GCC; see the file COPYING3. If not see
#ifndef GCC_CP_NAME_LOOKUP_H
#define GCC_CP_NAME_LOOKUP_H
-#include "c-common.h"
+#include "c-family/c-common.h"
/* The type of dictionary used to map names to types declared at
a given scope. */
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 4a50b556f46..e8f10a4d000 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -27,7 +27,7 @@ along with GCC; see the file COPYING3. If not see
#include "tree.h"
#include "cp-tree.h"
#include "intl.h"
-#include "c-pragma.h"
+#include "c-family/c-pragma.h"
#include "decl.h"
#include "flags.h"
#include "diagnostic-core.h"
@@ -35,7 +35,7 @@ along with GCC; see the file COPYING3. If not see
#include "output.h"
#include "target.h"
#include "cgraph.h"
-#include "c-common.h"
+#include "c-family/c-common.h"
#include "plugin.h"
@@ -393,7 +393,7 @@ cp_lexer_new_main (void)
c_common_no_more_pch ();
/* Allocate the memory. */
- lexer = GGC_CNEW (cp_lexer);
+ lexer = ggc_alloc_cleared_cp_lexer ();
#ifdef ENABLE_CHECKING
/* Initially we are not debugging. */
@@ -404,7 +404,7 @@ cp_lexer_new_main (void)
/* Create the buffer. */
alloc = CP_LEXER_BUFFER_SIZE;
- buffer = GGC_NEWVEC (cp_token, alloc);
+ buffer = ggc_alloc_vec_cp_token (alloc);
/* Put the first token in the buffer. */
space = alloc;
@@ -445,7 +445,7 @@ cp_lexer_new_from_tokens (cp_token_cache *cache)
{
cp_token *first = cache->first;
cp_token *last = cache->last;
- cp_lexer *lexer = GGC_CNEW (cp_lexer);
+ cp_lexer *lexer = ggc_alloc_cleared_cp_lexer ();
/* We do not own the buffer. */
lexer->buffer = NULL;
@@ -946,7 +946,7 @@ cp_lexer_stop_debugging (cp_lexer* lexer)
static cp_token_cache *
cp_token_cache_new (cp_token *first, cp_token *last)
{
- cp_token_cache *cache = GGC_NEW (cp_token_cache);
+ cp_token_cache *cache = ggc_alloc_cp_token_cache ();
cache->first = first;
cache->last = last;
return cache;
@@ -1496,7 +1496,7 @@ cp_parser_context_new (cp_parser_context* next)
memset (context, 0, sizeof (*context));
}
else
- context = GGC_CNEW (cp_parser_context);
+ context = ggc_alloc_cleared_cp_parser_context ();
/* No errors have occurred yet in this context. */
context->status = CP_PARSER_STATUS_KIND_NO_ERROR;
@@ -3093,7 +3093,7 @@ cp_parser_new (void)
cp_lexer *lexer;
unsigned i;
- /* cp_lexer_new_main is called before calling ggc_alloc because
+ /* cp_lexer_new_main is called before doing GC allocation because
cp_lexer_new_main might load a PCH file. */
lexer = cp_lexer_new_main ();
@@ -3102,7 +3102,7 @@ cp_parser_new (void)
for (i = 0; i < sizeof (binops) / sizeof (binops[0]); i++)
binops_by_token[binops[i].token_type] = binops[i];
- parser = GGC_CNEW (cp_parser);
+ parser = ggc_alloc_cleared_cp_parser ();
parser->lexer = lexer;
parser->context = cp_parser_context_new (NULL);
@@ -4605,7 +4605,7 @@ cp_parser_nested_name_specifier_opt (cp_parser *parser,
token->type = CPP_NESTED_NAME_SPECIFIER;
/* Retrieve any deferred checks. Do not pop this access checks yet
so the memory will not be reclaimed during token replacing below. */
- token->u.tree_check_value = GGC_CNEW (struct tree_check);
+ token->u.tree_check_value = ggc_alloc_cleared_tree_check ();
token->u.tree_check_value->value = parser->scope;
token->u.tree_check_value->checks = get_deferred_access_checks ();
token->u.tree_check_value->qualifying_scope =
@@ -5841,6 +5841,51 @@ cp_parser_unary_expression (cp_parser *parser, bool address_p, bool cast_p,
}
break;
+ case RID_NOEXCEPT:
+ {
+ tree expr;
+ const char *saved_message;
+ bool saved_integral_constant_expression_p;
+ bool saved_non_integral_constant_expression_p;
+ bool saved_greater_than_is_operator_p;
+
+ cp_lexer_consume_token (parser->lexer);
+ cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
+
+ saved_message = parser->type_definition_forbidden_message;
+ parser->type_definition_forbidden_message
+ = G_("types may not be defined in %<noexcept%> expressions");
+
+ saved_integral_constant_expression_p
+ = parser->integral_constant_expression_p;
+ saved_non_integral_constant_expression_p
+ = parser->non_integral_constant_expression_p;
+ parser->integral_constant_expression_p = false;
+
+ saved_greater_than_is_operator_p
+ = parser->greater_than_is_operator_p;
+ parser->greater_than_is_operator_p = true;
+
+ ++cp_unevaluated_operand;
+ ++c_inhibit_evaluation_warnings;
+ expr = cp_parser_expression (parser, false, NULL);
+ --c_inhibit_evaluation_warnings;
+ --cp_unevaluated_operand;
+
+ parser->greater_than_is_operator_p
+ = saved_greater_than_is_operator_p;
+
+ parser->integral_constant_expression_p
+ = saved_integral_constant_expression_p;
+ parser->non_integral_constant_expression_p
+ = saved_non_integral_constant_expression_p;
+
+ parser->type_definition_forbidden_message = saved_message;
+
+ cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ return finish_noexcept_expr (expr, tf_warning_or_error);
+ }
+
default:
break;
}
@@ -6770,15 +6815,20 @@ cp_parser_question_colon_clause (cp_parser* parser, tree logical_or_expr)
{
tree expr;
tree assignment_expr;
+ struct cp_token *token;
/* Consume the `?' token. */
cp_lexer_consume_token (parser->lexer);
+ token = cp_lexer_peek_token (parser->lexer);
if (cp_parser_allow_gnu_extensions_p (parser)
- && cp_lexer_next_token_is (parser->lexer, CPP_COLON))
+ && token->type == CPP_COLON)
{
+ pedwarn (token->location, OPT_pedantic,
+ "ISO C++ does not allow ?: with omitted middle operand");
/* Implicit true clause. */
expr = NULL_TREE;
c_inhibit_evaluation_warnings += logical_or_expr == truthvalue_true_node;
+ warn_for_omitted_condop (token->location, logical_or_expr);
}
else
{
@@ -10136,7 +10186,7 @@ cp_parser_mem_initializer_list (cp_parser* parser)
mem-initializer-list. */
if (!DECL_CONSTRUCTOR_P (current_function_decl))
error_at (token->location,
- "only constructors take base initializers");
+ "only constructors take member initializers");
/* Loop through the list. */
while (true)
@@ -11230,7 +11280,7 @@ cp_parser_template_id (cp_parser *parser,
token->type = CPP_TEMPLATE_ID;
/* Retrieve any deferred checks. Do not pop this access checks yet
so the memory will not be reclaimed during token replacing below. */
- token->u.tree_check_value = GGC_CNEW (struct tree_check);
+ token->u.tree_check_value = ggc_alloc_cleared_tree_check ();
token->u.tree_check_value->value = template_id;
token->u.tree_check_value->checks = get_deferred_access_checks ();
token->keyword = RID_MAX;
@@ -17489,13 +17539,50 @@ cp_parser_exception_specification_opt (cp_parser* parser)
{
cp_token *token;
tree type_id_list;
+ const char *saved_message;
/* Peek at the next token. */
token = cp_lexer_peek_token (parser->lexer);
+
+ /* Is it a noexcept-specification? */
+ if (cp_parser_is_keyword (token, RID_NOEXCEPT))
+ {
+ tree expr;
+ cp_lexer_consume_token (parser->lexer);
+
+ if (cp_lexer_peek_token (parser->lexer)->type == CPP_OPEN_PAREN)
+ {
+ cp_lexer_consume_token (parser->lexer);
+
+ /* Types may not be defined in an exception-specification. */
+ saved_message = parser->type_definition_forbidden_message;
+ parser->type_definition_forbidden_message
+ = G_("types may not be defined in an exception-specification");
+
+ expr = cp_parser_constant_expression (parser, false, NULL);
+
+ /* Restore the saved message. */
+ parser->type_definition_forbidden_message = saved_message;
+
+ cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ }
+ else
+ expr = boolean_true_node;
+
+ return build_noexcept_spec (expr, tf_warning_or_error);
+ }
+
/* If it's not `throw', then there's no exception-specification. */
if (!cp_parser_is_keyword (token, RID_THROW))
return NULL_TREE;
+#if 0
+ /* Enable this once a lot of code has transitioned to noexcept? */
+ if (cxx_dialect == cxx0x && !in_system_header)
+ warning (OPT_Wdeprecated, "dynamic exception specifications are "
+ "deprecated in C++0x; use %<noexcept%> instead.");
+#endif
+
/* Consume the `throw'. */
cp_lexer_consume_token (parser->lexer);
@@ -17507,8 +17594,6 @@ cp_parser_exception_specification_opt (cp_parser* parser)
/* If it's not a `)', then there is a type-id-list. */
if (token->type != CPP_CLOSE_PAREN)
{
- const char *saved_message;
-
/* Types may not be defined in an exception-specification. */
saved_message = parser->type_definition_forbidden_message;
parser->type_definition_forbidden_message
@@ -18285,6 +18370,14 @@ cp_parser_lookup_name (cp_parser *parser, tree name,
if (dependent_p)
pushed_scope = push_scope (parser->scope);
+ /* If the PARSER->SCOPE is a template specialization, it
+ may be instantiated during name lookup. In that case,
+ errors may be issued. Even if we rollback the current
+ tentative parse, those errors are valid. */
+ decl = lookup_qualified_name (parser->scope, name,
+ tag_type != none_type,
+ /*complain=*/true);
+
/* 3.4.3.1: In a lookup in which the constructor is an acceptable
lookup result and the nested-name-specifier nominates a class C:
* if the name specified after the nested-name-specifier, when
@@ -18300,17 +18393,11 @@ cp_parser_lookup_name (cp_parser *parser, tree name,
shall be used only in the declarator-id of a declaration that
names a constructor or in a using-declaration. */
if (tag_type == none_type
- && CLASS_TYPE_P (parser->scope)
- && constructor_name_p (name, parser->scope))
- name = ctor_identifier;
-
- /* If the PARSER->SCOPE is a template specialization, it
- may be instantiated during name lookup. In that case,
- errors may be issued. Even if we rollback the current
- tentative parse, those errors are valid. */
- decl = lookup_qualified_name (parser->scope, name,
- tag_type != none_type,
- /*complain=*/true);
+ && DECL_SELF_REFERENCE_P (decl)
+ && same_type_p (DECL_CONTEXT (decl), parser->scope))
+ decl = lookup_qualified_name (parser->scope, ctor_identifier,
+ tag_type != none_type,
+ /*complain=*/true);
/* If we have a single function from a using decl, pull it out. */
if (TREE_CODE (decl) == OVERLOAD
@@ -22618,11 +22705,12 @@ static tree
cp_parser_omp_for_loop (cp_parser *parser, tree clauses, tree *par_clauses)
{
tree init, cond, incr, body, decl, pre_body = NULL_TREE, ret;
- tree for_block = NULL_TREE, real_decl, initv, condv, incrv, declv;
+ tree real_decl, initv, condv, incrv, declv;
tree this_pre_body, cl;
location_t loc_first;
bool collapse_err = false;
int i, collapse = 1, nbraces = 0;
+ VEC(tree,gc) *for_block = make_tree_vector ();
for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
@@ -22741,8 +22829,7 @@ cp_parser_omp_for_loop (cp_parser *parser, tree clauses, tree *par_clauses)
LOOKUP_ONLYCONVERTING);
if (CLASS_TYPE_P (TREE_TYPE (decl)))
{
- for_block
- = tree_cons (NULL, this_pre_body, for_block);
+ VEC_safe_push (tree, gc, for_block, this_pre_body);
init = NULL_TREE;
}
else
@@ -22996,11 +23083,9 @@ cp_parser_omp_for_loop (cp_parser *parser, tree clauses, tree *par_clauses)
}
}
- while (for_block)
- {
- add_stmt (pop_stmt_list (TREE_VALUE (for_block)));
- for_block = TREE_CHAIN (for_block);
- }
+ while (!VEC_empty (tree, for_block))
+ add_stmt (pop_stmt_list (VEC_pop (tree, for_block)));
+ release_tree_vector (for_block);
return ret;
}
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index dcb455b66aa..09d077ade06 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -35,12 +35,11 @@ along with GCC; see the file COPYING3. If not see
#include "pointer-set.h"
#include "flags.h"
#include "cp-tree.h"
-#include "c-common.h"
+#include "c-family/c-common.h"
#include "cp-objcp-common.h"
#include "tree-inline.h"
#include "decl.h"
#include "output.h"
-#include "except.h"
#include "toplev.h"
#include "timevar.h"
#include "tree-iterator.h"
@@ -888,10 +887,10 @@ maybe_process_partial_specialization (tree type)
slot = (spec_entry **)
htab_find_slot (type_specializations, &elt, INSERT);
- *slot = GGC_NEW (spec_entry);
+ *slot = ggc_alloc_spec_entry ();
**slot = elt;
}
- else if (COMPLETE_TYPE_P (inst) || TYPE_BEING_DEFINED (inst))
+ else if (COMPLETE_OR_OPEN_TYPE_P (inst))
/* But if we've had an implicit instantiation, that's a
problem ([temp.expl.spec]/6). */
error ("specialization %qT after instantiation %qT",
@@ -1401,7 +1400,7 @@ register_specialization (tree spec, tree tmpl, tree args, bool is_friend,
if (!optimize_specialization_lookup_p (tmpl))
{
gcc_assert (tmpl && args && spec);
- *slot = GGC_NEW (spec_entry);
+ *slot = ggc_alloc_spec_entry ();
**slot = elt;
if (TREE_CODE (spec) == FUNCTION_DECL && DECL_NAMESPACE_SCOPE_P (spec)
&& PRIMARY_TEMPLATE_P (tmpl)
@@ -3875,10 +3874,10 @@ process_partial_specialization (tree decl)
or some such would have been OK. */
tpd.level = TMPL_PARMS_DEPTH (current_template_parms);
- tpd.parms = (int *) alloca (sizeof (int) * ntparms);
+ tpd.parms = XALLOCAVEC (int, ntparms);
memset (tpd.parms, 0, sizeof (int) * ntparms);
- tpd.arg_uses_template_parms = (int *) alloca (sizeof (int) * nargs);
+ tpd.arg_uses_template_parms = XALLOCAVEC (int, nargs);
memset (tpd.arg_uses_template_parms, 0, sizeof (int) * nargs);
for (i = 0; i < nargs; ++i)
{
@@ -3993,12 +3992,11 @@ process_partial_specialization (tree decl)
if (!tpd2.parms)
{
/* We haven't yet initialized TPD2. Do so now. */
- tpd2.arg_uses_template_parms
- = (int *) alloca (sizeof (int) * nargs);
+ tpd2.arg_uses_template_parms = XALLOCAVEC (int, nargs);
/* The number of parameters here is the number in the
main template, which, as checked in the assertion
above, is NARGS. */
- tpd2.parms = (int *) alloca (sizeof (int) * nargs);
+ tpd2.parms = XALLOCAVEC (int, nargs);
tpd2.level =
TMPL_PARMS_DEPTH (DECL_TEMPLATE_PARMS (maintmpl));
}
@@ -4882,6 +4880,36 @@ check_valid_ptrmem_cst_expr (tree type, tree expr)
return false;
}
+/* Returns TRUE iff the address of OP is value-dependent.
+
+ 14.6.2.4 [temp.dep.temp]:
+ A non-integral non-type template-argument is dependent if its type is
+ dependent or it has either of the following forms
+ qualified-id
+ & qualified-id
+ and contains a nested-name-specifier which specifies a class-name that
+ names a dependent type.
+
+ We generalize this to just say that the address of a member of a
+ dependent class is value-dependent; the above doesn't cover the
+ address of a static data member named with an unqualified-id. */
+
+static bool
+has_value_dependent_address (tree op)
+{
+ /* We could use get_inner_reference here, but there's no need;
+ this is only relevant for template non-type arguments, which
+ can only be expressed as &id-expression. */
+ if (DECL_P (op))
+ {
+ tree ctx = CP_DECL_CONTEXT (op);
+ if (TYPE_P (ctx) && dependent_type_p (ctx))
+ return true;
+ }
+
+ return false;
+}
+
/* Attempt to convert the non-type template parameter EXPR to the
indicated TYPE. If the conversion is successful, return the
converted value. If the conversion is unsuccessful, return
@@ -4920,6 +4948,11 @@ convert_nontype_argument (tree type, tree expr)
return NULL_TREE;
}
+ /* Add the ADDR_EXPR now for the benefit of
+ value_dependent_expression_p. */
+ if (TYPE_PTROBV_P (type))
+ expr = decay_conversion (expr);
+
/* If we are in a template, EXPR may be non-dependent, but still
have a syntactic, rather than semantic, form. For example, EXPR
might be a SCOPE_REF, rather than the VAR_DECL to which the
@@ -4927,11 +4960,18 @@ convert_nontype_argument (tree type, tree expr)
so that access checking can be performed when the template is
instantiated -- but here we need the resolved form so that we can
convert the argument. */
- expr = fold_non_dependent_expr (expr);
+ if (TYPE_REF_OBJ_P (type)
+ && has_value_dependent_address (expr))
+ /* If we want the address and it's value-dependent, don't fold. */;
+ else
+ expr = fold_non_dependent_expr (expr);
if (error_operand_p (expr))
return error_mark_node;
expr_type = TREE_TYPE (expr);
- expr = mark_rvalue_use (expr);
+ if (TREE_CODE (type) == REFERENCE_TYPE)
+ expr = mark_lvalue_use (expr);
+ else
+ expr = mark_rvalue_use (expr);
/* HACK: Due to double coercion, we can get a
NOP_EXPR<REFERENCE_TYPE>(ADDR_EXPR<POINTER_TYPE> (arg)) here,
@@ -5922,15 +5962,15 @@ coerce_template_parms (tree parms,
{
if (complain & tf_error)
{
- const char *or_more = "";
if (variadic_p)
{
- or_more = " or more";
--nparms;
+ error ("wrong number of template arguments "
+ "(%d, should be %d or more)", nargs, nparms);
}
-
- error ("wrong number of template arguments (%d, should be %d%s)",
- nargs, nparms, or_more);
+ else
+ error ("wrong number of template arguments "
+ "(%d, should be %d)", nargs, nparms);
if (in_decl)
error ("provided for %q+D", in_decl);
@@ -6155,7 +6195,7 @@ add_pending_template (tree d)
if (level)
push_tinst_level (d);
- pt = GGC_NEW (struct pending_template);
+ pt = ggc_alloc_pending_template ();
pt->next = NULL;
pt->tinst = current_tinst_level;
if (last_pending_template)
@@ -6718,7 +6758,7 @@ lookup_template_class (tree d1,
elt.spec = t;
slot = (spec_entry **) htab_find_slot_with_hash (type_specializations,
&elt, hash, INSERT);
- *slot = GGC_NEW (spec_entry);
+ *slot = ggc_alloc_spec_entry ();
**slot = elt;
/* Note this use of the partial instantiation so we can check it
@@ -7076,7 +7116,7 @@ push_tinst_level (tree d)
return 0;
}
- new_level = GGC_NEW (struct tinst_level);
+ new_level = ggc_alloc_tinst_level ();
new_level->decl = d;
new_level->locus = input_location;
new_level->in_system_header_p = in_system_header;
@@ -7699,8 +7739,7 @@ instantiate_class_template (tree type)
if (type == error_mark_node)
return error_mark_node;
- if (TYPE_BEING_DEFINED (type)
- || COMPLETE_TYPE_P (type)
+ if (COMPLETE_OR_OPEN_TYPE_P (type)
|| uses_template_parms (type))
return type;
@@ -7770,10 +7809,10 @@ instantiate_class_template (tree type)
TYPE_HAS_NEW_OPERATOR (type) = TYPE_HAS_NEW_OPERATOR (pattern);
TYPE_HAS_ARRAY_NEW_OPERATOR (type) = TYPE_HAS_ARRAY_NEW_OPERATOR (pattern);
TYPE_GETS_DELETE (type) = TYPE_GETS_DELETE (pattern);
- TYPE_HAS_ASSIGN_REF (type) = TYPE_HAS_ASSIGN_REF (pattern);
- TYPE_HAS_CONST_ASSIGN_REF (type) = TYPE_HAS_CONST_ASSIGN_REF (pattern);
- TYPE_HAS_INIT_REF (type) = TYPE_HAS_INIT_REF (pattern);
- TYPE_HAS_CONST_INIT_REF (type) = TYPE_HAS_CONST_INIT_REF (pattern);
+ TYPE_HAS_COPY_ASSIGN (type) = TYPE_HAS_COPY_ASSIGN (pattern);
+ TYPE_HAS_CONST_COPY_ASSIGN (type) = TYPE_HAS_CONST_COPY_ASSIGN (pattern);
+ TYPE_HAS_COPY_CTOR (type) = TYPE_HAS_COPY_CTOR (pattern);
+ TYPE_HAS_CONST_COPY_CTOR (type) = TYPE_HAS_CONST_COPY_CTOR (pattern);
TYPE_HAS_DEFAULT_CONSTRUCTOR (type) = TYPE_HAS_DEFAULT_CONSTRUCTOR (pattern);
TYPE_HAS_CONVERSION (type) = TYPE_HAS_CONVERSION (pattern);
TYPE_PACKED (type) = TYPE_PACKED (pattern);
@@ -7795,8 +7834,7 @@ instantiate_class_template (tree type)
instantiate it, and that lookup should instantiate the enclosing
class. */
gcc_assert (!DECL_CLASS_SCOPE_P (TYPE_MAIN_DECL (pattern))
- || COMPLETE_TYPE_P (TYPE_CONTEXT (type))
- || TYPE_BEING_DEFINED (TYPE_CONTEXT (type)));
+ || COMPLETE_OR_OPEN_TYPE_P (TYPE_CONTEXT (type)));
base_list = NULL_TREE;
if (BINFO_N_BASE_BINFOS (pbinfo))
@@ -8527,7 +8565,7 @@ tsubst_template_args (tree t, tree args, tsubst_flags_t complain, tree in_decl)
tree orig_t = t;
int len = TREE_VEC_LENGTH (t);
int need_new = 0, i, expanded_len_adjust = 0, out;
- tree *elts = (tree *) alloca (len * sizeof (tree));
+ tree *elts = XALLOCAVEC (tree, len);
for (i = 0; i < len; i++)
{
@@ -9838,7 +9876,15 @@ tsubst_exception_specification (tree fntype,
specs = TYPE_RAISES_EXCEPTIONS (fntype);
new_specs = NULL_TREE;
- if (specs)
+ if (specs && TREE_PURPOSE (specs))
+ {
+ /* A noexcept-specifier. */
+ new_specs = tsubst_copy_and_build
+ (TREE_PURPOSE (specs), args, complain, in_decl, /*function_p=*/false,
+ /*integral_constant_expression_p=*/true);
+ new_specs = build_noexcept_spec (new_specs, complain);
+ }
+ else if (specs)
{
if (! TREE_VALUE (specs))
new_specs = specs;
@@ -12245,6 +12291,17 @@ tsubst_copy_and_build (tree t,
return cxx_sizeof_or_alignof_expr (op1, TREE_CODE (t),
complain & tf_error);
+ case NOEXCEPT_EXPR:
+ op1 = TREE_OPERAND (t, 0);
+ ++cp_unevaluated_operand;
+ ++c_inhibit_evaluation_warnings;
+ op1 = tsubst_copy_and_build (op1, args, complain, in_decl,
+ /*function_p=*/false,
+ /*integral_constant_expression_p=*/false);
+ --cp_unevaluated_operand;
+ --c_inhibit_evaluation_warnings;
+ return finish_noexcept_expr (op1, complain);
+
case MODOP_EXPR:
{
tree r = build_x_modify_expr
@@ -17463,40 +17520,6 @@ dependent_scope_p (tree scope)
&& !currently_open_class (scope));
}
-/* Returns TRUE if EXPRESSION is dependent, according to CRITERION. */
-
-static bool
-dependent_scope_ref_p (tree expression, bool criterion (tree))
-{
- tree scope;
- tree name;
-
- gcc_assert (TREE_CODE (expression) == SCOPE_REF);
-
- if (!TYPE_P (TREE_OPERAND (expression, 0)))
- return true;
-
- scope = TREE_OPERAND (expression, 0);
- name = TREE_OPERAND (expression, 1);
-
- /* [temp.dep.expr]
-
- An id-expression is type-dependent if it contains a
- nested-name-specifier that contains a class-name that names a
- dependent type. */
- /* The suggested resolution to Core Issue 224 implies that if the
- qualifying type is the current class, then we must peek
- inside it. */
- if (DECL_P (name)
- && currently_open_class (scope)
- && !criterion (name))
- return false;
- if (dependent_type_p (scope))
- return true;
-
- return false;
-}
-
/* Returns TRUE if the EXPRESSION is value-dependent, in the sense of
[temp.dep.constexpr]. EXPRESSION is already known to be a constant
expression. */
@@ -17579,8 +17602,17 @@ value_dependent_expression_p (tree expression)
return dependent_type_p (expression);
return type_dependent_expression_p (expression);
+ case NOEXCEPT_EXPR:
+ expression = TREE_OPERAND (expression, 0);
+ /* FIXME why check value-dependency? */
+ return (type_dependent_expression_p (expression)
+ || value_dependent_expression_p (expression));
+
case SCOPE_REF:
- return dependent_scope_ref_p (expression, value_dependent_expression_p);
+ {
+ tree name = TREE_OPERAND (expression, 1);
+ return value_dependent_expression_p (name);
+ }
case COMPONENT_REF:
return (value_dependent_expression_p (TREE_OPERAND (expression, 0))
@@ -17617,6 +17649,13 @@ value_dependent_expression_p (tree expression)
return ((value_dependent_expression_p (TREE_OPERAND (expression, 0)))
|| (value_dependent_expression_p (TREE_OPERAND (expression, 2))));
+ case ADDR_EXPR:
+ {
+ tree op = TREE_OPERAND (expression, 0);
+ return (value_dependent_expression_p (op)
+ || has_value_dependent_address (op));
+ }
+
default:
/* A constant expression is value-dependent if any subexpression is
value-dependent. */
@@ -17680,6 +17719,7 @@ type_dependent_expression_p (tree expression)
if (TREE_CODE (expression) == PSEUDO_DTOR_EXPR
|| TREE_CODE (expression) == SIZEOF_EXPR
|| TREE_CODE (expression) == ALIGNOF_EXPR
+ || TREE_CODE (expression) == NOEXCEPT_EXPR
|| TREE_CODE (expression) == TRAIT_EXPR
|| TREE_CODE (expression) == TYPEID_EXPR
|| TREE_CODE (expression) == DELETE_EXPR
@@ -17715,10 +17755,19 @@ type_dependent_expression_p (tree expression)
return dependent_type_p (type);
}
- if (TREE_CODE (expression) == SCOPE_REF
- && dependent_scope_ref_p (expression,
- type_dependent_expression_p))
- return true;
+ if (TREE_CODE (expression) == SCOPE_REF)
+ {
+ tree scope = TREE_OPERAND (expression, 0);
+ tree name = TREE_OPERAND (expression, 1);
+
+ /* 14.6.2.2 [temp.dep.expr]: An id-expression is type-dependent if it
+ contains an identifier associated by name lookup with one or more
+ declarations declared with a dependent type, or...a
+ nested-name-specifier or qualified-id that names a member of an
+ unknown specialization. */
+ return (type_dependent_expression_p (name)
+ || dependent_scope_p (scope));
+ }
if (TREE_CODE (expression) == FUNCTION_DECL
&& DECL_LANG_SPECIFIC (expression)
diff --git a/gcc/cp/ptree.c b/gcc/cp/ptree.c
index a1fa71ffe22..c2493c7fcad 100644
--- a/gcc/cp/ptree.c
+++ b/gcc/cp/ptree.c
@@ -124,9 +124,9 @@ cxx_print_type (FILE *file, tree node, int indent)
fputs (" X()", file);
if (TYPE_HAS_CONVERSION (node))
fputs (" has-type-conversion", file);
- if (TYPE_HAS_INIT_REF (node))
+ if (TYPE_HAS_COPY_CTOR (node))
{
- if (TYPE_HAS_CONST_INIT_REF (node))
+ if (TYPE_HAS_CONST_COPY_CTOR (node))
fputs (" X(constX&)", file);
else
fputs (" X(X&)", file);
@@ -139,7 +139,7 @@ cxx_print_type (FILE *file, tree node, int indent)
fputs (" delete", file);
if (TYPE_GETS_DELETE (node) & 2)
fputs (" delete[]", file);
- if (TYPE_HAS_ASSIGN_REF (node))
+ if (TYPE_HAS_COPY_ASSIGN (node))
fputs (" this=(X&)", file);
if (CLASSTYPE_SORTED_FIELDS (node))
fprintf (file, " sorted-fields %p",
diff --git a/gcc/cp/repo.c b/gcc/cp/repo.c
index 08a4d623d40..2a08c8fa412 100644
--- a/gcc/cp/repo.c
+++ b/gcc/cp/repo.c
@@ -43,7 +43,7 @@ static FILE *open_repo_file (const char *);
static char *afgets (FILE *);
static FILE *reopen_repo_file_for_write (void);
-static GTY(()) tree pending_repo;
+static GTY(()) VEC(tree,gc) *pending_repo;
static char *repo_name;
static const char *old_args, *old_dir, *old_main;
@@ -236,9 +236,10 @@ reopen_repo_file_for_write (void)
void
finish_repo (void)
{
- tree t;
+ tree val;
char *dir, *args;
FILE *repo_file;
+ unsigned ix;
if (!flag_use_repository || flag_compare_debug)
return;
@@ -266,9 +267,10 @@ finish_repo (void)
fprintf (repo_file, "\n");
}
- for (t = pending_repo; t; t = TREE_CHAIN (t))
+ for (ix = VEC_length (tree, pending_repo) - 1;
+ VEC_iterate (tree, pending_repo, ix, val);
+ ix--)
{
- tree val = TREE_VALUE (t);
tree name = DECL_ASSEMBLER_NAME (val);
char type = IDENTIFIER_REPO_CHOSEN (name) ? 'C' : 'O';
fprintf (repo_file, "%c %s\n", type, IDENTIFIER_POINTER (name));
@@ -352,7 +354,7 @@ repo_emit_p (tree decl)
if (!DECL_REPO_AVAILABLE_P (decl))
{
DECL_REPO_AVAILABLE_P (decl) = 1;
- pending_repo = tree_cons (NULL_TREE, decl, pending_repo);
+ VEC_safe_push (tree, gc, pending_repo, decl);
}
return IDENTIFIER_REPO_CHOSEN (DECL_ASSEMBLER_NAME (decl)) ? 1 : ret;
diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c
index 62aa9212929..dde8e825dbe 100644
--- a/gcc/cp/rtti.c
+++ b/gcc/cp/rtti.c
@@ -33,7 +33,7 @@ along with GCC; see the file COPYING3. If not see
#include "toplev.h"
#include "convert.h"
#include "target.h"
-#include "c-pragma.h"
+#include "c-family/c-pragma.h"
/* C++ returns type information to the user in struct type_info
objects. We also use type information to implement dynamic_cast and
@@ -207,8 +207,8 @@ throw_bad_cast (void)
{
tree fn = get_identifier ("__cxa_bad_cast");
if (!get_global_value_if_present (fn, &fn))
- fn = push_throw_library_fn (fn, build_function_type (ptr_type_node,
- void_list_node));
+ fn = push_throw_library_fn (fn, build_function_type_list (ptr_type_node,
+ NULL_TREE));
return build_cxx_call (fn, 0, NULL);
}
@@ -225,7 +225,7 @@ throw_bad_typeid (void)
tree t;
t = build_reference_type (const_type_info_type_node);
- t = build_function_type (t, void_list_node);
+ t = build_function_type_list (t, NULL_TREE);
fn = push_throw_library_fn (fn, t);
}
@@ -729,12 +729,10 @@ build_dynamic_cast_1 (tree type, tree expr, tsubst_flags_t complain)
(cp_build_qualified_type
(tinfo_ptr, TYPE_QUAL_CONST));
name = "__dynamic_cast";
- tmp = tree_cons
- (NULL_TREE, const_ptr_type_node, tree_cons
- (NULL_TREE, tinfo_ptr, tree_cons
- (NULL_TREE, tinfo_ptr, tree_cons
- (NULL_TREE, ptrdiff_type_node, void_list_node))));
- tmp = build_function_type (ptr_type_node, tmp);
+ tmp = build_function_type_list (ptr_type_node,
+ const_ptr_type_node,
+ tinfo_ptr, tinfo_ptr,
+ ptrdiff_type_node, NULL_TREE);
dcast_fn = build_library_fn_ptr (name, tmp);
DECL_PURE_P (dcast_fn) = 1;
pop_abi_namespace ();
diff --git a/gcc/cp/search.c b/gcc/cp/search.c
index 4843855bf70..9dbefd3c5bc 100644
--- a/gcc/cp/search.c
+++ b/gcc/cp/search.c
@@ -216,8 +216,7 @@ lookup_base (tree t, tree base, base_access access, base_kind *kind_ptr)
/* If BASE is incomplete, it can't be a base of T--and instantiating it
might cause an error. */
- if (t_binfo && CLASS_TYPE_P (base)
- && (COMPLETE_TYPE_P (base) || TYPE_BEING_DEFINED (base)))
+ if (t_binfo && CLASS_TYPE_P (base) && COMPLETE_OR_OPEN_TYPE_P (base))
{
struct lookup_base_data_s data;
@@ -1336,7 +1335,7 @@ lookup_conversion_operator (tree class_type, tree type)
}
/* TYPE is a class type. Return the index of the fields within
- the method vector with name NAME, or -1 is no such field exists. */
+ the method vector with name NAME, or -1 if no such field exists. */
int
lookup_fnfields_1 (tree type, tree name)
@@ -1362,9 +1361,13 @@ lookup_fnfields_1 (tree type, tree name)
if (CLASSTYPE_LAZY_MOVE_CTOR (type))
lazily_declare_fn (sfk_move_constructor, type);
}
- else if (name == ansi_assopname(NOP_EXPR)
- && CLASSTYPE_LAZY_ASSIGNMENT_OP (type))
- lazily_declare_fn (sfk_assignment_operator, type);
+ else if (name == ansi_assopname (NOP_EXPR))
+ {
+ if (CLASSTYPE_LAZY_COPY_ASSIGN (type))
+ lazily_declare_fn (sfk_copy_assignment, type);
+ if (CLASSTYPE_LAZY_MOVE_ASSIGN (type))
+ lazily_declare_fn (sfk_move_assignment, type);
+ }
else if ((name == dtor_identifier
|| name == base_dtor_identifier
|| name == complete_dtor_identifier
@@ -1442,6 +1445,18 @@ lookup_fnfields_1 (tree type, tree name)
return -1;
}
+/* TYPE is a class type. Return the field within the method vector with
+ name NAME, or NULL_TREE if no such field exists. */
+
+tree
+lookup_fnfields_slot (tree type, tree name)
+{
+ int ix = lookup_fnfields_1 (type, name);
+ if (ix < 0)
+ return NULL_TREE;
+ return VEC_index (tree, CLASSTYPE_METHOD_VEC (type), ix);
+}
+
/* Like lookup_fnfields_1, except that the name is extracted from
FUNCTION, which is a FUNCTION_DECL or a TEMPLATE_DECL. */
@@ -1867,7 +1882,7 @@ check_final_overrider (tree overrider, tree basefn)
}
/* Check throw specifier is at least as strict. */
- if (!comp_except_specs (base_throw, over_throw, 0))
+ if (!comp_except_specs (base_throw, over_throw, ce_derived))
{
error ("looser throw specifier for %q+#F", overrider);
error (" overriding %q+#F", basefn);
@@ -1890,6 +1905,7 @@ check_final_overrider (tree overrider, tree basefn)
{
error ("deleted function %q+D", overrider);
error ("overriding non-deleted function %q+D", basefn);
+ maybe_explain_implicit_delete (overrider);
}
else
{
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 05d1cada906..156f278e171 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -30,10 +30,9 @@ along with GCC; see the file COPYING3. If not see
#include "tm.h"
#include "tree.h"
#include "cp-tree.h"
-#include "c-common.h"
+#include "c-family/c-common.h"
#include "tree-inline.h"
#include "tree-mudflap.h"
-#include "except.h"
#include "toplev.h"
#include "flags.h"
#include "output.h"
@@ -1219,7 +1218,7 @@ finish_asm_stmt (int volatile_p, tree string, tree output_operands,
tree operand;
int i;
- oconstraints = (const char **) alloca (noutputs * sizeof (char *));
+ oconstraints = XALLOCAVEC (const char *, noutputs);
string = resolve_asm_operand_names (string, output_operands,
input_operands, labels);
@@ -3098,7 +3097,13 @@ finish_id_expression (tree id_expression,
{
tree r = convert_from_reference (decl);
- if (processing_template_decl && TYPE_P (scope))
+ /* In a template, return a SCOPE_REF for most qualified-ids
+ so that we can check access at instantiation time. But if
+ we're looking at a member of the current instantiation, we
+ know we have access and building up the SCOPE_REF confuses
+ non-type template argument handling. */
+ if (processing_template_decl && TYPE_P (scope)
+ && !currently_open_class (scope))
r = build_qualified_name (TREE_TYPE (r),
scope, decl,
template_p);
@@ -3255,6 +3260,7 @@ simplify_aggr_init_expr (tree *tp)
fn,
aggr_init_expr_nargs (aggr_init_expr),
AGGR_INIT_EXPR_ARGP (aggr_init_expr));
+ TREE_NOTHROW (call_expr) = TREE_NOTHROW (aggr_init_expr);
if (style == ctor)
{
@@ -3521,31 +3527,6 @@ finalize_nrv (tree *tp, tree var, tree result)
htab_delete (data.visited);
}
-/* Return the declaration for the function called by CALL_EXPR T,
- TYPE is the class type of the clause decl. */
-
-static tree
-omp_clause_info_fndecl (tree t, tree type)
-{
- tree ret = get_callee_fndecl (t);
-
- if (ret)
- return ret;
-
- gcc_assert (TREE_CODE (t) == CALL_EXPR);
- t = CALL_EXPR_FN (t);
- STRIP_NOPS (t);
- if (TREE_CODE (t) == OBJ_TYPE_REF)
- {
- t = cp_fold_obj_type_ref (t, type);
- if (TREE_CODE (t) == ADDR_EXPR
- && TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL)
- return TREE_OPERAND (t, 0);
- }
-
- return NULL_TREE;
-}
-
/* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */
bool
@@ -3563,80 +3544,27 @@ cxx_omp_create_clause_info (tree c, tree type, bool need_default_ctor,
info = make_tree_vec (3);
CP_OMP_CLAUSE_INFO (c) = info;
- if (need_default_ctor
- || (need_copy_ctor && !TYPE_HAS_TRIVIAL_INIT_REF (type)))
+ if (need_default_ctor || need_copy_ctor)
{
- VEC(tree,gc) *vec;
-
if (need_default_ctor)
- vec = NULL;
+ t = get_default_ctor (type);
else
- {
- t = build_int_cst (build_pointer_type (type), 0);
- t = build1 (INDIRECT_REF, type, t);
- vec = make_tree_vector_single (t);
- }
- t = build_special_member_call (NULL_TREE, complete_ctor_identifier,
- &vec, type, LOOKUP_NORMAL,
- tf_warning_or_error);
+ t = get_copy_ctor (type);
- if (vec != NULL)
- release_tree_vector (vec);
-
- if (targetm.cxx.cdtor_returns_this () || errorcount)
- /* Because constructors and destructors return this,
- the call will have been cast to "void". Remove the
- cast here. We would like to use STRIP_NOPS, but it
- wouldn't work here because TYPE_MODE (t) and
- TYPE_MODE (TREE_OPERAND (t, 0)) are different.
- They are VOIDmode and Pmode, respectively. */
- if (TREE_CODE (t) == NOP_EXPR)
- t = TREE_OPERAND (t, 0);
-
- TREE_VEC_ELT (info, 0) = get_callee_fndecl (t);
+ if (t && !trivial_fn_p (t))
+ TREE_VEC_ELT (info, 0) = t;
}
if ((need_default_ctor || need_copy_ctor)
&& TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
- {
- t = build_int_cst (build_pointer_type (type), 0);
- t = build1 (INDIRECT_REF, type, t);
- t = build_special_member_call (t, complete_dtor_identifier,
- NULL, type, LOOKUP_NORMAL,
- tf_warning_or_error);
+ TREE_VEC_ELT (info, 1) = get_dtor (type);
- if (targetm.cxx.cdtor_returns_this () || errorcount)
- /* Because constructors and destructors return this,
- the call will have been cast to "void". Remove the
- cast here. We would like to use STRIP_NOPS, but it
- wouldn't work here because TYPE_MODE (t) and
- TYPE_MODE (TREE_OPERAND (t, 0)) are different.
- They are VOIDmode and Pmode, respectively. */
- if (TREE_CODE (t) == NOP_EXPR)
- t = TREE_OPERAND (t, 0);
-
- TREE_VEC_ELT (info, 1) = omp_clause_info_fndecl (t, type);
- }
-
- if (need_copy_assignment && !TYPE_HAS_TRIVIAL_ASSIGN_REF (type))
+ if (need_copy_assignment)
{
- VEC(tree,gc) *vec;
-
- t = build_int_cst (build_pointer_type (type), 0);
- t = build1 (INDIRECT_REF, type, t);
- vec = make_tree_vector_single (t);
- t = build_special_member_call (t, ansi_assopname (NOP_EXPR),
- &vec, type, LOOKUP_NORMAL,
- tf_warning_or_error);
- release_tree_vector (vec);
-
- /* We'll have called convert_from_reference on the call, which
- may well have added an indirect_ref. It's unneeded here,
- and in the way, so kill it. */
- if (TREE_CODE (t) == INDIRECT_REF)
- t = TREE_OPERAND (t, 0);
+ t = get_copy_assign (type);
- TREE_VEC_ELT (info, 2) = omp_clause_info_fndecl (t, type);
+ if (t && !trivial_fn_p (t))
+ TREE_VEC_ELT (info, 2) = t;
}
return errorcount != save_errorcount;
@@ -5005,7 +4933,7 @@ classtype_has_nothrow_assign_or_copy_p (tree type, bool assign_p)
return false;
fns = VEC_index (tree, CLASSTYPE_METHOD_VEC (type), ix);
}
- else if (TYPE_HAS_INIT_REF (type))
+ else if (TYPE_HAS_COPY_CTOR (type))
{
/* If construction of the copy constructor was postponed, create
it now. */
@@ -5064,13 +4992,13 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
&& (trivial_type_p (type1)
|| (CLASS_TYPE_P (type1)
- && TYPE_HAS_TRIVIAL_ASSIGN_REF (type1))));
+ && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1))));
case CPTK_HAS_NOTHROW_CONSTRUCTOR:
type1 = strip_array_types (type1);
return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2)
|| (CLASS_TYPE_P (type1)
- && (t = locate_ctor (type1, NULL))
+ && (t = locate_ctor (type1))
&& TYPE_NOTHROW_P (TREE_TYPE (t))));
case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
@@ -5089,7 +5017,7 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
type" wording for this trait. */
type1 = strip_array_types (type1);
return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
- || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_INIT_REF (type1)));
+ || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1)));
case CPTK_HAS_TRIVIAL_DESTRUCTOR:
type1 = strip_array_types (type1);
@@ -5098,8 +5026,7 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
&& TYPE_HAS_TRIVIAL_DESTRUCTOR (type1)));
case CPTK_HAS_VIRTUAL_DESTRUCTOR:
- return (CLASS_TYPE_P (type1)
- && (t = locate_dtor (type1, NULL)) && DECL_VIRTUAL_P (t));
+ return type_has_virtual_destructor (type1);
case CPTK_IS_ABSTRACT:
return (CLASS_TYPE_P (type1) && CLASSTYPE_PURE_VIRTUALS (type1));
@@ -5151,7 +5078,8 @@ check_trait_type (tree type)
if (COMPLETE_TYPE_P (type))
return true;
- if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
+ if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type)
+ && COMPLETE_TYPE_P (TREE_TYPE (type)))
return true;
if (VOID_TYPE_P (type))
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 9a5ee0fb2d8..d62f9d7acf6 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -31,9 +31,9 @@ along with GCC; see the file COPYING3. If not see
#include "tree-inline.h"
#include "debug.h"
#include "convert.h"
-#include "tree-flow.h"
#include "cgraph.h"
#include "splay-tree.h"
+#include "gimple.h" /* gimple_has_body_p */
static tree bot_manip (tree *, int *, void *);
static tree bot_replace (tree *, int *, void *);
@@ -418,6 +418,7 @@ build_aggr_init_expr (tree type, tree init)
AGGR_INIT_EXPR_ARGP (init));
TREE_SIDE_EFFECTS (rval) = 1;
AGGR_INIT_VIA_CTOR_P (rval) = is_ctor;
+ TREE_NOTHROW (rval) = TREE_NOTHROW (init);
}
else
rval = init;
@@ -478,7 +479,7 @@ build_target_expr_with_type (tree init, tree type)
if (TREE_CODE (init) == TARGET_EXPR)
return init;
- else if (CLASS_TYPE_P (type) && !TYPE_HAS_TRIVIAL_INIT_REF (type)
+ else if (CLASS_TYPE_P (type) && type_has_nontrivial_copy_init (type)
&& !VOID_TYPE_P (TREE_TYPE (init))
&& TREE_CODE (init) != COND_EXPR
&& TREE_CODE (init) != CONSTRUCTOR
@@ -496,7 +497,8 @@ build_target_expr_with_type (tree init, tree type)
/* Like the above function, but without the checking. This function should
only be used by code which is deliberately trying to subvert the type
- system, such as call_builtin_trap. */
+ system, such as call_builtin_trap. Or build_over_call, to avoid
+ infinite recursion. */
tree
force_target_expr (tree type, tree init)
@@ -1055,14 +1057,6 @@ strip_typedefs (tree t)
return cp_build_qualified_type (result, cp_type_quals (t));
}
-/* Returns true iff TYPE is a type variant created for a typedef. */
-
-bool
-typedef_variant_p (tree type)
-{
- return is_typedef_decl (TYPE_NAME (type));
-}
-
/* Setup a TYPE_DECL node as a typedef representation.
See comments of set_underlying_type in c-common.c. */
@@ -1466,12 +1460,16 @@ cxx_printable_name_translate (tree decl, int v)
tree
build_exception_variant (tree type, tree raises)
{
- tree v = TYPE_MAIN_VARIANT (type);
- int type_quals = TYPE_QUALS (type);
+ tree v;
+ int type_quals;
+
+ if (comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (type), ce_exact))
+ return type;
- for (; v; v = TYPE_NEXT_VARIANT (v))
+ type_quals = TYPE_QUALS (type);
+ for (v = TYPE_MAIN_VARIANT (type); v; v = TYPE_NEXT_VARIANT (v))
if (check_qualified_type (v, type, type_quals)
- && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (v), 1))
+ && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (v), ce_exact))
return v;
/* Need to build a new variant. */
@@ -2371,7 +2369,9 @@ type_has_nontrivial_default_init (const_tree t)
return 0;
}
-/* Returns true iff copying an object of type T is non-trivial. */
+/* Returns true iff copying an object of type T (including via move
+ constructor) is non-trivial. That is, T has no non-trivial copy
+ constructors and no non-trivial move constructors. */
bool
type_has_nontrivial_copy_init (const_tree t)
@@ -2379,12 +2379,38 @@ type_has_nontrivial_copy_init (const_tree t)
t = strip_array_types (CONST_CAST_TREE (t));
if (CLASS_TYPE_P (t))
- return TYPE_HAS_COMPLEX_INIT_REF (t);
+ {
+ gcc_assert (COMPLETE_TYPE_P (t));
+ return ((TYPE_HAS_COPY_CTOR (t)
+ && TYPE_HAS_COMPLEX_COPY_CTOR (t))
+ || TYPE_HAS_COMPLEX_MOVE_CTOR (t));
+ }
else
return 0;
}
-/* Returns 1 iff type T is a trivial type, as defined in [basic.types]. */
+/* Returns 1 iff type T is a trivially copyable type, as defined in
+ [basic.types] and [class]. */
+
+bool
+trivially_copyable_p (const_tree t)
+{
+ t = strip_array_types (CONST_CAST_TREE (t));
+
+ if (CLASS_TYPE_P (t))
+ return ((!TYPE_HAS_COPY_CTOR (t)
+ || !TYPE_HAS_COMPLEX_COPY_CTOR (t))
+ && !TYPE_HAS_COMPLEX_MOVE_CTOR (t)
+ && (!TYPE_HAS_COPY_ASSIGN (t)
+ || !TYPE_HAS_COMPLEX_COPY_ASSIGN (t))
+ && !TYPE_HAS_COMPLEX_MOVE_ASSIGN (t)
+ && TYPE_HAS_TRIVIAL_DESTRUCTOR (t));
+ else
+ return scalarish_type_p (t);
+}
+
+/* Returns 1 iff type T is a trivial type, as defined in [basic.types] and
+ [class]. */
bool
trivial_type_p (const_tree t)
@@ -2393,9 +2419,7 @@ trivial_type_p (const_tree t)
if (CLASS_TYPE_P (t))
return (TYPE_HAS_TRIVIAL_DFLT (t)
- && TYPE_HAS_TRIVIAL_INIT_REF (t)
- && TYPE_HAS_TRIVIAL_ASSIGN_REF (t)
- && TYPE_HAS_TRIVIAL_DESTRUCTOR (t));
+ && trivially_copyable_p (t));
else
return scalarish_type_p (t);
}
@@ -2644,10 +2668,8 @@ cp_build_type_attribute_variant (tree type, tree attributes)
tree new_type;
new_type = build_type_attribute_variant (type, attributes);
- if ((TREE_CODE (new_type) == FUNCTION_TYPE
- || TREE_CODE (new_type) == METHOD_TYPE)
- && (TYPE_RAISES_EXCEPTIONS (new_type)
- != TYPE_RAISES_EXCEPTIONS (type)))
+ if (TREE_CODE (new_type) == FUNCTION_TYPE
+ || TREE_CODE (new_type) == METHOD_TYPE)
new_type = build_exception_variant (new_type,
TYPE_RAISES_EXCEPTIONS (type));
@@ -2668,7 +2690,7 @@ cxx_type_hash_eq (const_tree typea, const_tree typeb)
gcc_assert (TREE_CODE (typea) == FUNCTION_TYPE);
return comp_except_specs (TYPE_RAISES_EXCEPTIONS (typea),
- TYPE_RAISES_EXCEPTIONS (typeb), 1);
+ TYPE_RAISES_EXCEPTIONS (typeb), ce_exact);
}
/* Apply FUNC to all language-specific sub-trees of TP in a pre-order
@@ -2837,7 +2859,12 @@ special_function_p (const_tree decl)
if (DECL_CONSTRUCTOR_P (decl))
return sfk_constructor;
if (DECL_OVERLOADED_OPERATOR_P (decl) == NOP_EXPR)
- return sfk_assignment_operator;
+ {
+ if (copy_fn_p (decl))
+ return sfk_copy_assignment;
+ if (move_fn_p (decl))
+ return sfk_move_assignment;
+ }
if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl))
return sfk_destructor;
if (DECL_COMPLETE_DESTRUCTOR_P (decl))
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index a7d04ddbc5b..20345b551ed 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -39,12 +39,12 @@ along with GCC; see the file COPYING3. If not see
#include "intl.h"
#include "target.h"
#include "convert.h"
-#include "c-common.h"
+#include "c-family/c-common.h"
#include "params.h"
static tree pfn_from_ptrmemfunc (tree);
static tree delta_from_ptrmemfunc (tree);
-static tree convert_for_assignment (tree, tree, const char *, tree, int,
+static tree convert_for_assignment (tree, tree, impl_conv_rhs, tree, int,
tsubst_flags_t, int);
static tree cp_pointer_int_sum (enum tree_code, tree, tree);
static tree rationalize_conditional_expr (enum tree_code, tree,
@@ -829,26 +829,17 @@ merge_types (tree t1, tree t2)
/* Simple way if one arg fails to specify argument types. */
if (p1 == NULL_TREE || TREE_VALUE (p1) == void_type_node)
- {
- parms = p2;
- raises = TYPE_RAISES_EXCEPTIONS (t2);
- }
+ parms = p2;
else if (p2 == NULL_TREE || TREE_VALUE (p2) == void_type_node)
- {
- parms = p1;
- raises = TYPE_RAISES_EXCEPTIONS (t1);
- }
+ parms = p1;
else
- {
- parms = commonparms (p1, p2);
- /* In cases where we're merging a real declaration with a
- built-in declaration, t1 is the real one. */
- raises = TYPE_RAISES_EXCEPTIONS (t1);
- }
+ parms = commonparms (p1, p2);
rval = build_function_type (valtype, parms);
gcc_assert (type_memfn_quals (t1) == type_memfn_quals (t2));
rval = apply_memfn_quals (rval, type_memfn_quals (t1));
+ raises = merge_exception_specifiers (TYPE_RAISES_EXCEPTIONS (t1),
+ TYPE_RAISES_EXCEPTIONS (t2));
t1 = build_exception_variant (rval, raises);
break;
}
@@ -858,7 +849,8 @@ merge_types (tree t1, tree t2)
/* Get this value the long way, since TYPE_METHOD_BASETYPE
is just the main variant of this. */
tree basetype = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t2)));
- tree raises = TYPE_RAISES_EXCEPTIONS (t1);
+ tree raises = merge_exception_specifiers (TYPE_RAISES_EXCEPTIONS (t1),
+ TYPE_RAISES_EXCEPTIONS (t2));
tree t3;
/* If this was a member function type, get back to the
@@ -989,13 +981,14 @@ comp_except_types (tree a, tree b, bool exact)
}
/* Return true if TYPE1 and TYPE2 are equivalent exception specifiers.
- If EXACT is false, T2 can be stricter than T1 (according to 15.4/7),
- otherwise it must be exact. Exception lists are unordered, but
- we've already filtered out duplicates. Most lists will be in order,
- we should try to make use of that. */
+ If EXACT is ce_derived, T2 can be stricter than T1 (according to 15.4/5).
+ If EXACT is ce_normal, the compatibility rules in 15.4/3 apply.
+ If EXACT is ce_exact, the specs must be exactly the same. Exception lists
+ are unordered, but we've already filtered out duplicates. Most lists will
+ be in order, we should try to make use of that. */
bool
-comp_except_specs (const_tree t1, const_tree t2, bool exact)
+comp_except_specs (const_tree t1, const_tree t2, int exact)
{
const_tree probe;
const_tree base;
@@ -1004,14 +997,42 @@ comp_except_specs (const_tree t1, const_tree t2, bool exact)
if (t1 == t2)
return true;
+ /* First handle noexcept. */
+ if (exact < ce_exact)
+ {
+ /* noexcept(false) is compatible with any throwing dynamic-exc-spec
+ and stricter than any spec. */
+ if (t1 == noexcept_false_spec)
+ return !nothrow_spec_p (t2) || exact == ce_derived;
+ /* Even a derived noexcept(false) is compatible with a throwing
+ dynamic spec. */
+ if (t2 == noexcept_false_spec)
+ return !nothrow_spec_p (t1);
+
+ /* Otherwise, if we aren't looking for an exact match, noexcept is
+ equivalent to throw(). */
+ if (t1 == noexcept_true_spec)
+ t1 = empty_except_spec;
+ if (t2 == noexcept_true_spec)
+ t2 = empty_except_spec;
+ }
+
+ /* If any noexcept is left, it is only comparable to itself;
+ either we're looking for an exact match or we're redeclaring a
+ template with dependent noexcept. */
+ if ((t1 && TREE_PURPOSE (t1))
+ || (t2 && TREE_PURPOSE (t2)))
+ return (t1 && t2
+ && cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)));
+
if (t1 == NULL_TREE) /* T1 is ... */
- return t2 == NULL_TREE || !exact;
+ return t2 == NULL_TREE || exact == ce_derived;
if (!TREE_VALUE (t1)) /* t1 is EMPTY */
return t2 != NULL_TREE && !TREE_VALUE (t2);
if (t2 == NULL_TREE) /* T2 is ... */
return false;
if (TREE_VALUE (t1) && !TREE_VALUE (t2)) /* T2 is EMPTY, T1 is not */
- return !exact;
+ return exact == ce_derived;
/* Neither set is ... or EMPTY, make sure each part of T2 is in T1.
Count how many we find, to determine exactness. For exact matching and
@@ -1026,7 +1047,7 @@ comp_except_specs (const_tree t1, const_tree t2, bool exact)
if (comp_except_types (a, b, exact))
{
- if (probe == base && exact)
+ if (probe == base && exact > ce_derived)
base = TREE_CHAIN (probe);
length++;
break;
@@ -1035,7 +1056,7 @@ comp_except_specs (const_tree t1, const_tree t2, bool exact)
if (probe == NULL_TREE)
return false;
}
- return !exact || base == NULL_TREE || length == list_length (t1);
+ return exact == ce_derived || base == NULL_TREE || length == list_length (t1);
}
/* Compare the array types T1 and T2. ALLOW_REDECLARATION is true if
@@ -2229,6 +2250,7 @@ build_class_member_access_expr (tree object, tree member,
{
/* A static data member. */
result = member;
+ mark_exp_read (object);
/* If OBJECT has side-effects, they are supposed to occur. */
if (TREE_SIDE_EFFECTS (object))
result = build2 (COMPOUND_EXPR, TREE_TYPE (result), object, result);
@@ -3473,7 +3495,7 @@ convert_arguments (tree typelist, VEC(tree,gc) **values, tree fndecl,
{
parmval = convert_for_initialization
(NULL_TREE, type, val, flags,
- "argument passing", fndecl, i, complain);
+ ICR_ARGPASS, fndecl, i, complain);
parmval = convert_for_arg_passing (type, parmval);
}
@@ -4759,7 +4781,7 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert,
tree val;
const char *invalid_op_diag;
- if (error_operand_p (arg))
+ if (!arg || error_operand_p (arg))
return error_mark_node;
if ((invalid_op_diag
@@ -5466,14 +5488,30 @@ build_x_conditional_expr (tree ifexp, tree op1, tree op2,
/* Given a list of expressions, return a compound expression
that performs them all and returns the value of the last of them. */
-tree build_x_compound_expr_from_list (tree list, const char *msg)
+tree
+build_x_compound_expr_from_list (tree list, expr_list_kind exp)
{
tree expr = TREE_VALUE (list);
if (TREE_CHAIN (list))
{
- if (msg)
- permerror (input_location, "%s expression list treated as compound expression", msg);
+ switch (exp)
+ {
+ case ELK_INIT:
+ permerror (input_location, "expression list treated as compound "
+ "expression in initializer");
+ break;
+ case ELK_MEM_INIT:
+ permerror (input_location, "expression list treated as compound "
+ "expression in mem-initializer");
+ break;
+ case ELK_FUNC_CAST:
+ permerror (input_location, "expression list treated as compound "
+ "expression in functional cast");
+ break;
+ default:
+ gcc_unreachable ();
+ }
for (list = TREE_CHAIN (list); list; list = TREE_CHAIN (list))
expr = build_x_compound_expr (expr, TREE_VALUE (list),
@@ -6747,10 +6785,10 @@ cp_build_modify_expr (tree lhs, enum tree_code modifycode, tree rhs,
/* Calls with INIT_EXPR are all direct-initialization, so don't set
LOOKUP_ONLYCONVERTING. */
newrhs = convert_for_initialization (lhs, olhstype, newrhs, LOOKUP_NORMAL,
- "initialization", NULL_TREE, 0,
+ ICR_INIT, NULL_TREE, 0,
complain);
else
- newrhs = convert_for_assignment (olhstype, newrhs, "assignment",
+ newrhs = convert_for_assignment (olhstype, newrhs, ICR_ASSIGN,
NULL_TREE, 0, complain, LOOKUP_IMPLICIT);
if (!same_type_p (lhstype, olhstype))
@@ -7019,7 +7057,7 @@ build_ptrmemfunc (tree type, tree pfn, int force, bool c_cast_p)
}
/* Handle null pointer to member function conversions. */
- if (integer_zerop (pfn))
+ if (null_ptr_cst_p (pfn))
{
pfn = build_c_cast (input_location, type, integer_zero_node);
return build_ptrmemfunc1 (to_type,
@@ -7150,14 +7188,15 @@ delta_from_ptrmemfunc (tree t)
}
/* Convert value RHS to type TYPE as preparation for an assignment to
- an lvalue of type TYPE. ERRTYPE is a string to use in error
- messages: "assignment", "return", etc. If FNDECL is non-NULL, we
- are doing the conversion in order to pass the PARMNUMth argument of
- FNDECL. */
+ an lvalue of type TYPE. ERRTYPE indicates what kind of error the
+ implicit conversion is. If FNDECL is non-NULL, we are doing the
+ conversion in order to pass the PARMNUMth argument of FNDECL.
+ If FNDECL is NULL, we are doing the conversion in function pointer
+ argument passing, conversion in initialization, etc. */
static tree
convert_for_assignment (tree type, tree rhs,
- const char *errtype, tree fndecl, int parmnum,
+ impl_conv_rhs errtype, tree fndecl, int parmnum,
tsubst_flags_t complain, int flags)
{
tree rhstype;
@@ -7194,23 +7233,25 @@ convert_for_assignment (tree type, tree rhs,
if (c_dialect_objc ())
{
int parmno;
+ tree selector;
tree rname = fndecl;
- if (!strcmp (errtype, "assignment"))
- parmno = -1;
- else if (!strcmp (errtype, "initialization"))
- parmno = -2;
- else
- {
- tree selector = objc_message_selector ();
-
- parmno = parmnum;
-
- if (selector && parmno > 1)
- {
- rname = selector;
- parmno -= 1;
- }
+ switch (errtype)
+ {
+ case ICR_ASSIGN:
+ parmno = -1;
+ break;
+ case ICR_INIT:
+ parmno = -2;
+ break;
+ default:
+ selector = objc_message_selector ();
+ parmno = parmnum;
+ if (selector && parmno > 1)
+ {
+ rname = selector;
+ parmno -= 1;
+ }
}
if (objc_compare_types (type, rhstype, parmno, rname))
@@ -7247,8 +7288,35 @@ convert_for_assignment (tree type, tree rhs,
error ("cannot convert %qT to %qT for argument %qP to %qD",
rhstype, type, parmnum, fndecl);
else
- error ("cannot convert %qT to %qT in %s", rhstype, type,
- errtype);
+ switch (errtype)
+ {
+ case ICR_DEFAULT_ARGUMENT:
+ error ("cannot convert %qT to %qT in default argument",
+ rhstype, type);
+ break;
+ case ICR_ARGPASS:
+ error ("cannot convert %qT to %qT in argument passing",
+ rhstype, type);
+ break;
+ case ICR_CONVERTING:
+ error ("cannot convert %qT to %qT",
+ rhstype, type);
+ break;
+ case ICR_INIT:
+ error ("cannot convert %qT to %qT in initialization",
+ rhstype, type);
+ break;
+ case ICR_RETURN:
+ error ("cannot convert %qT to %qT in return",
+ rhstype, type);
+ break;
+ case ICR_ASSIGN:
+ error ("cannot convert %qT to %qT in assignment",
+ rhstype, type);
+ break;
+ default:
+ gcc_unreachable();
+ }
}
return error_mark_node;
}
@@ -7260,9 +7328,42 @@ convert_for_assignment (tree type, tree rhs,
&& coder == codel
&& check_missing_format_attribute (type, rhstype)
&& (complain & tf_warning))
- warning (OPT_Wmissing_format_attribute,
- "%s might be a candidate for a format attribute",
- errtype);
+ switch (errtype)
+ {
+ case ICR_ARGPASS:
+ case ICR_DEFAULT_ARGUMENT:
+ if (fndecl)
+ warning (OPT_Wmissing_format_attribute,
+ "parameter %qP of %qD might be a candidate "
+ "for a format attribute", parmnum, fndecl);
+ else
+ warning (OPT_Wmissing_format_attribute,
+ "parameter might be a candidate "
+ "for a format attribute");
+ break;
+ case ICR_CONVERTING:
+ warning (OPT_Wmissing_format_attribute,
+ "target of conversion might be might be a candidate "
+ "for a format attribute");
+ break;
+ case ICR_INIT:
+ warning (OPT_Wmissing_format_attribute,
+ "target of initialization might be a candidate "
+ "for a format attribute");
+ break;
+ case ICR_RETURN:
+ warning (OPT_Wmissing_format_attribute,
+ "return type might be a candidate "
+ "for a format attribute");
+ break;
+ case ICR_ASSIGN:
+ warning (OPT_Wmissing_format_attribute,
+ "left-hand side of assignment might be a candidate "
+ "for a format attribute");
+ break;
+ default:
+ gcc_unreachable();
+ }
}
/* If -Wparentheses, warn about a = b = c when a has type bool and b
@@ -7288,7 +7389,7 @@ convert_for_assignment (tree type, tree rhs,
/* Convert RHS to be of type TYPE.
If EXP is nonzero, it is the target of the initialization.
- ERRTYPE is a string to use in error messages.
+ ERRTYPE indicates what kind of error the implicit conversion is.
Two major differences between the behavior of
`convert_for_assignment' and `convert_for_initialization'
@@ -7304,7 +7405,7 @@ convert_for_assignment (tree type, tree rhs,
tree
convert_for_initialization (tree exp, tree type, tree rhs, int flags,
- const char *errtype, tree fndecl, int parmnum,
+ impl_conv_rhs errtype, tree fndecl, int parmnum,
tsubst_flags_t complain)
{
enum tree_code codel = TREE_CODE (type);
@@ -7695,7 +7796,7 @@ check_return_expr (tree retval, bool *no_warning)
to the type of return value's location to handle the
case that functype is smaller than the valtype. */
retval = convert_for_initialization
- (NULL_TREE, functype, retval, flags, "return", NULL_TREE, 0,
+ (NULL_TREE, functype, retval, flags, ICR_RETURN, NULL_TREE, 0,
tf_warning_or_error);
retval = convert (valtype, retval);
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 7603ead5463..f62bbb5d950 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -352,7 +352,7 @@ abstract_virtuals_error (tree decl, tree type)
slot = htab_find_slot_with_hash (abstract_pending_vars, type,
(hashval_t)TYPE_UID (type), INSERT);
- pat = GGC_NEW (struct pending_abstract_type);
+ pat = ggc_alloc_pending_abstract_type ();
pat->type = type;
pat->decl = decl;
pat->locus = ((decl && DECL_P (decl))
@@ -714,7 +714,7 @@ store_init_value (tree decl, tree init, int flags)
if (MAYBE_CLASS_TYPE_P (type))
{
- gcc_assert (TYPE_HAS_TRIVIAL_INIT_REF (type)
+ gcc_assert (!type_has_nontrivial_copy_init (type)
|| TREE_CODE (init) == CONSTRUCTOR);
if (TREE_CODE (init) == TREE_LIST)
@@ -727,10 +727,9 @@ store_init_value (tree decl, tree init, int flags)
else if (TREE_CODE (init) == TREE_LIST
&& TREE_TYPE (init) != unknown_type_node)
{
- if (TREE_CODE (decl) == RESULT_DECL)
- init = build_x_compound_expr_from_list (init,
- "return value initializer");
- else if (TREE_CODE (init) == TREE_LIST
+ gcc_assert (TREE_CODE (decl) != RESULT_DECL);
+
+ if (TREE_CODE (init) == TREE_LIST
&& TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
{
error ("cannot initialize arrays using this syntax");
@@ -738,7 +737,7 @@ store_init_value (tree decl, tree init, int flags)
}
else
/* We get here with code like `int a (2);' */
- init = build_x_compound_expr_from_list (init, "initializer");
+ init = build_x_compound_expr_from_list (init, ELK_INIT);
}
/* End of special C++ code. */
@@ -909,7 +908,7 @@ digest_init_r (tree type, tree init, bool nested, int flags)
if (cxx_dialect != cxx98 && nested)
check_narrowing (type, init);
init = convert_for_initialization (0, type, init, flags,
- "initialization", NULL_TREE, 0,
+ ICR_INIT, NULL_TREE, 0,
tf_warning_or_error);
exp = &init;
@@ -963,7 +962,7 @@ digest_init_r (tree type, tree init, bool nested, int flags)
return convert_for_initialization (NULL_TREE, type, init,
flags,
- "initialization", NULL_TREE, 0,
+ ICR_INIT, NULL_TREE, 0,
tf_warning_or_error);
}
}
@@ -1419,18 +1418,14 @@ build_x_arrow (tree expr)
/*overloaded_p=*/NULL,
tf_warning_or_error)))
{
- tree t;
- unsigned ix;
-
if (expr == error_mark_node)
return error_mark_node;
- for (ix = 0; VEC_iterate (tree, types_memoized, ix, t); ix++)
- if (TREE_TYPE (expr) == t)
- {
- error ("circular pointer delegation detected");
- return error_mark_node;
- }
+ if (vec_member (TREE_TYPE (expr), types_memoized))
+ {
+ error ("circular pointer delegation detected");
+ return error_mark_node;
+ }
VEC_safe_push (tree, gc, types_memoized, TREE_TYPE (expr));
last_rval = expr;
@@ -1483,6 +1478,9 @@ build_m_component_ref (tree datum, tree component)
if (error_operand_p (datum) || error_operand_p (component))
return error_mark_node;
+ mark_lvalue_use (datum);
+ mark_rvalue_use (component);
+
ptrmem_type = TREE_TYPE (component);
if (!TYPE_PTR_TO_MEMBER_P (ptrmem_type))
{
@@ -1596,7 +1594,7 @@ build_functional_cast (tree exp, tree parms, tsubst_flags_t complain)
return cp_convert (type, integer_zero_node);
/* This must build a C cast. */
- parms = build_x_compound_expr_from_list (parms, "functional cast");
+ parms = build_x_compound_expr_from_list (parms, ELK_FUNC_CAST);
return cp_build_c_cast (type, parms, complain);
}
@@ -1721,10 +1719,14 @@ merge_exception_specifiers (tree list, tree add)
{
if (!list || !add)
return NULL_TREE;
- else if (!TREE_VALUE (list))
- return add;
+ /* For merging noexcept(true) and throw(), take the more recent one (LIST).
+ A throw(type-list) spec takes precedence over a noexcept(false) spec.
+ Any other noexcept-spec should only be merged with an equivalent one.
+ So the !TREE_VALUE code below is correct for all cases. */
else if (!TREE_VALUE (add))
return list;
+ else if (!TREE_VALUE (list))
+ return add;
else
{
tree orig_list = list;