aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/class.c
AgeCommit message (Collapse)AuthorFilesLines
2020-11-02c++: Don't purge the satisfaction cachesPatrick Palka1-3/+0
The adoption of P2104 ("Disallow changing concept values") means we can memoize the result of satisfaction indefinitely and no longer have to clear the satisfaction caches on various events that would affect satisfaction. To that end, this patch removes the invalidation routine clear_satisfaction_cache and adjusts its callers appropriately. This provides a large reduction in compile time and memory use in some cases. For example, on the libstdc++ test std/ranges/adaptor/join.cc, compile time and memory usage drops nearly 75%, from 7.5s/770MB to 2s/230MB, with a --enable-checking=release compiler. gcc/cp/ChangeLog: * class.c (finish_struct_1): Don't call clear_satisfaction_cache. * constexpr.c (clear_cv_and_fold_caches): Likewise. Remove bool parameter. * constraint.cc (clear_satisfaction_cache): Remove definition. * cp-tree.h (clear_satisfaction_cache): Remove declaration. (clear_cv_and_fold_caches): Remove bool parameter. * typeck2.c (store_init_value): Remove argument to clear_cv_and_fold_caches. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-complete1.C: Delete test that became ill-formed after P2104.
2020-10-14c++: DECL_FRIEND_P cleanupNathan Sidwell1-2/+3
DECL_FRIEND_P's meaning has changed over time. It now (almost) means the the friend function decl has not been met via an explicit decl. This completes that transition, renaming it to DECL_UNIQUE_FRIEND_P, so one doesn't think it is the sole indicator of friendliness (plenty of friends do not have the flag set). This allows reduction in the complexity of managing the field -- all in duplicate_decls now. gcc/cp/ * cp-tree.h (struct lang_decl_fn): Adjust context comment. (DECL_FRIEND_P): Replace with ... (DECL_UNIQUE_FRIEND_P): ... this. Only for FUNCTION_DECLs. (DECL_FRIEND_CONTEXT): Adjust. * class.c (add_implicitly_declared_members): Detect friendly spaceship from context. * constraint.cc (remove_constraints): Use a checking assert. (maybe_substitute_reqs_for): Use DECL_UNIQUE_FRIEND_P. * decl.c (check_no_redeclaration_friend_default_args): DECL_UNIQUE_FRIEND_P is signficant, not hiddenness. (duplicate_decls): Adjust DECL_UNIQUE_FRIEND_P clearing. (redeclaration_error_message): Use DECL_UNIQUE_FRIEND_P. (start_preparsed_function): Correct in-class friend processing. Refactor some initializers. (grokmethod): Directly check friend decl-spec. * decl2.c (grokfield): Check DECL_UNIQUE_FRIEND_P. * friend.c (do_friend): Set DECL_UNIQUE_FRIEND_P first, remove extraneous conditions. Don't re set it afterwards. * name-lookup.c (lookup_elaborated_type_1): Simplify revealing code. (do_pushtag): Likewise. * pt.c (optimize_specialization_lookup_p): Check DECL_UNIQUE_FRIEND_P. (push_template_decl): Likewise. Drop unneeded friend setting. (type_dependent_expression_p): Check DECL_UNIQUE_FRIEND_P. libcc1/ * libcp1plugin.cc (plugin_add_friend): Set DECL_UNIQUE_FRIEND_P.
2020-10-02c++: cleanup ctor_omit_inherited_parms [PR97268]Nathan Sidwell1-126/+133
ctor_omit_inherited_parms was being somewhat abused. What I'd missed is that it checks for a base-dtor name, before proceeding with the check. But we ended up passing it that during cloning before we'd completed the cloning. It was also using DECL_ORIGIN to get to the in-charge ctor, but we sometimes zap DECL_ABSTRACT_ORIGIN, and it ends up processing the incoming function -- which happens to work. so, this breaks out a predicate that expects to get the incharge ctor, and will tell you whether its base ctor will need to omit the parms. We call that directly during cloning. Then the original fn is essentially just a wrapper, but uses DECL_CLONED_FUNCTION to get to the in-charge ctor. That uncovered abuse in add_method, which was happily passing TEMPLATE_DECLs to it. Let's not do that. add_method itself contained a loop mostly containing an 'if (nomatch) continue' idiom, except for a final 'if (match) {...}' check, which itself contained instances of the former idiom. I refactored that to use the former idiom throughout. In doing that I found a place where we'd issue an error, but then not actually reject the new member. gcc/cp/ * cp-tree.h (base_ctor_omit_inherited_parms): Declare. * class.c (add_method): Refactor main loop, only pass fns to ctor_omit_inherited_parms. (build_cdtor_clones): Rename bool parms. (clone_cdtor): Call base_ctor_omit_inherited_parms. * method.c (base_ctor_omit_inherited_parms): New, broken out of ... (ctor_omit_inherited_parms): ... here, call it with DECL_CLONED_FUNCTION. gcc/testsuite/ * g++.dg/inherit/pr97268.C: New.
2020-09-09c++: Fix resolving the address of overloaded pmf [PR96647]Patrick Palka1-0/+13
In resolve_address_of_overloaded_function, currently only the second pass over the overload set (which considers just the function templates in the overload set) checks constraints and performs return type deduction when necessary. But as the testcases below show, we need to do the same when considering non-template functions during the first pass. gcc/cp/ChangeLog: PR c++/96647 * class.c (resolve_address_of_overloaded_function): Check constraints_satisfied_p and perform return-type deduction via maybe_instantiate_decl when considering non-template functions in the overload set. * cp-tree.h (maybe_instantiate_decl): Declare. * decl2.c (maybe_instantiate_decl): Remove static. gcc/testsuite/ChangeLog: PR c++/96647 * g++.dg/cpp0x/auto-96647.C: New test. * g++.dg/cpp0x/error9.C: New test. * g++.dg/cpp2a/concepts-fn6.C: New test.
2020-08-27vec: add exact argument for various grow functions.Martin Liska1-2/+3
gcc/ada/ChangeLog: * gcc-interface/trans.c (gigi): Set exact argument of a vector growth function to true. (Attribute_to_gnu): Likewise. gcc/ChangeLog: * alias.c (init_alias_analysis): Set exact argument of a vector growth function to true. * calls.c (internal_arg_pointer_based_exp_scan): Likewise. * cfgbuild.c (find_many_sub_basic_blocks): Likewise. * cfgexpand.c (expand_asm_stmt): Likewise. * cfgrtl.c (rtl_create_basic_block): Likewise. * combine.c (combine_split_insns): Likewise. (combine_instructions): Likewise. * config/aarch64/aarch64-sve-builtins.cc (function_expander::add_output_operand): Likewise. (function_expander::add_input_operand): Likewise. (function_expander::add_integer_operand): Likewise. (function_expander::add_address_operand): Likewise. (function_expander::add_fixed_operand): Likewise. * df-core.c (df_worklist_dataflow_doublequeue): Likewise. * dwarf2cfi.c (update_row_reg_save): Likewise. * early-remat.c (early_remat::init_block_info): Likewise. (early_remat::finalize_candidate_indices): Likewise. * except.c (sjlj_build_landing_pads): Likewise. * final.c (compute_alignments): Likewise. (grow_label_align): Likewise. * function.c (temp_slots_at_level): Likewise. * fwprop.c (build_single_def_use_links): Likewise. (update_uses): Likewise. * gcc.c (insert_wrapper): Likewise. * genautomata.c (create_state_ainsn_table): Likewise. (add_vect): Likewise. (output_dead_lock_vect): Likewise. * genmatch.c (capture_info::capture_info): Likewise. (parser::finish_match_operand): Likewise. * genrecog.c (optimize_subroutine_group): Likewise. (merge_pattern_info::merge_pattern_info): Likewise. (merge_into_decision): Likewise. (print_subroutine_start): Likewise. (main): Likewise. * gimple-loop-versioning.cc (loop_versioning::loop_versioning): Likewise. * gimple.c (gimple_set_bb): Likewise. * graphite-isl-ast-to-gimple.c (translate_isl_ast_node_user): Likewise. * haifa-sched.c (sched_extend_luids): Likewise. (extend_h_i_d): Likewise. * insn-addr.h (insn_addresses_new): Likewise. * ipa-cp.c (gather_context_independent_values): Likewise. (find_more_contexts_for_caller_subset): Likewise. * ipa-devirt.c (final_warning_record::grow_type_warnings): Likewise. (ipa_odr_read_section): Likewise. * ipa-fnsummary.c (evaluate_properties_for_edge): Likewise. (ipa_fn_summary_t::duplicate): Likewise. (analyze_function_body): Likewise. (ipa_merge_fn_summary_after_inlining): Likewise. (read_ipa_call_summary): Likewise. * ipa-icf.c (sem_function::bb_dict_test): Likewise. * ipa-prop.c (ipa_alloc_node_params): Likewise. (parm_bb_aa_status_for_bb): Likewise. (ipa_compute_jump_functions_for_edge): Likewise. (ipa_analyze_node): Likewise. (update_jump_functions_after_inlining): Likewise. (ipa_read_edge_info): Likewise. (read_ipcp_transformation_info): Likewise. (ipcp_transform_function): Likewise. * ipa-reference.c (ipa_reference_write_optimization_summary): Likewise. * ipa-split.c (execute_split_functions): Likewise. * ira.c (find_moveable_pseudos): Likewise. * lower-subreg.c (decompose_multiword_subregs): Likewise. * lto-streamer-in.c (input_eh_regions): Likewise. (input_cfg): Likewise. (input_struct_function_base): Likewise. (input_function): Likewise. * modulo-sched.c (set_node_sched_params): Likewise. (extend_node_sched_params): Likewise. (schedule_reg_moves): Likewise. * omp-general.c (omp_construct_simd_compare): Likewise. * passes.c (pass_manager::create_pass_tab): Likewise. (enable_disable_pass): Likewise. * predict.c (determine_unlikely_bbs): Likewise. * profile.c (compute_branch_probabilities): Likewise. * read-rtl-function.c (function_reader::parse_block): Likewise. * read-rtl.c (rtx_reader::read_rtx_code): Likewise. * reg-stack.c (stack_regs_mentioned): Likewise. * regrename.c (regrename_init): Likewise. * rtlanal.c (T>::add_single_to_queue): Likewise. * sched-deps.c (init_deps_data_vector): Likewise. * sel-sched-ir.c (sel_extend_global_bb_info): Likewise. (extend_region_bb_info): Likewise. (extend_insn_data): Likewise. * symtab.c (symtab_node::create_reference): Likewise. * tracer.c (tail_duplicate): Likewise. * trans-mem.c (tm_region_init): Likewise. (get_bb_regions_instrumented): Likewise. * tree-cfg.c (init_empty_tree_cfg_for_function): Likewise. (build_gimple_cfg): Likewise. (create_bb): Likewise. (move_block_to_fn): Likewise. * tree-complex.c (tree_lower_complex): Likewise. * tree-if-conv.c (predicate_rhs_code): Likewise. * tree-inline.c (copy_bb): Likewise. * tree-into-ssa.c (get_ssa_name_ann): Likewise. (mark_phi_for_rewrite): Likewise. * tree-object-size.c (compute_builtin_object_size): Likewise. (init_object_sizes): Likewise. * tree-predcom.c (initialize_root_vars_store_elim_1): Likewise. (initialize_root_vars_store_elim_2): Likewise. (prepare_initializers_chain_store_elim): Likewise. * tree-ssa-address.c (addr_for_mem_ref): Likewise. (multiplier_allowed_in_address_p): Likewise. * tree-ssa-coalesce.c (ssa_conflicts_new): Likewise. * tree-ssa-forwprop.c (simplify_vector_constructor): Likewise. * tree-ssa-loop-ivopts.c (addr_offset_valid_p): Likewise. (get_address_cost_ainc): Likewise. * tree-ssa-loop-niter.c (discover_iteration_bound_by_body_walk): Likewise. * tree-ssa-pre.c (add_to_value): Likewise. (phi_translate_1): Likewise. (do_pre_regular_insertion): Likewise. (do_pre_partial_partial_insertion): Likewise. (init_pre): Likewise. * tree-ssa-propagate.c (ssa_prop_init): Likewise. (update_call_from_tree): Likewise. * tree-ssa-reassoc.c (optimize_range_tests_cmp_bitwise): Likewise. * tree-ssa-sccvn.c (vn_reference_lookup_3): Likewise. (vn_reference_lookup_pieces): Likewise. (eliminate_dom_walker::eliminate_push_avail): Likewise. * tree-ssa-strlen.c (set_strinfo): Likewise. (get_stridx_plus_constant): Likewise. (zero_length_string): Likewise. (find_equal_ptrs): Likewise. (printf_strlen_execute): Likewise. * tree-ssa-threadedge.c (set_ssa_name_value): Likewise. * tree-ssanames.c (make_ssa_name_fn): Likewise. * tree-streamer-in.c (streamer_read_tree_bitfields): Likewise. * tree-vect-loop.c (vect_record_loop_mask): Likewise. (vect_get_loop_mask): Likewise. (vect_record_loop_len): Likewise. (vect_get_loop_len): Likewise. * tree-vect-patterns.c (vect_recog_mask_conversion_pattern): Likewise. * tree-vect-slp.c (vect_slp_convert_to_external): Likewise. (vect_bb_slp_scalar_cost): Likewise. (vect_bb_vectorization_profitable_p): Likewise. (vectorizable_slp_permutation): Likewise. * tree-vect-stmts.c (vectorizable_call): Likewise. (vectorizable_simd_clone_call): Likewise. (scan_store_can_perm_p): Likewise. (vectorizable_store): Likewise. * expr.c: Likewise. * vec.c (test_safe_grow_cleared): Likewise. * vec.h (vec_safe_grow): Likewise. (vec_safe_grow_cleared): Likewise. (vl_ptr>::safe_grow): Likewise. (vl_ptr>::safe_grow_cleared): Likewise. * config/c6x/c6x.c (insn_set_clock): Likewise. gcc/c/ChangeLog: * gimple-parser.c (c_parser_gimple_compound_statement): Set exact argument of a vector growth function to true. gcc/cp/ChangeLog: * class.c (build_vtbl_initializer): Set exact argument of a vector growth function to true. * constraint.cc (get_mapped_args): Likewise. * decl.c (cp_maybe_mangle_decomp): Likewise. (cp_finish_decomp): Likewise. * parser.c (cp_parser_omp_for_loop): Likewise. * pt.c (canonical_type_parameter): Likewise. * rtti.c (get_pseudo_ti_init): Likewise. gcc/fortran/ChangeLog: * trans-openmp.c (gfc_trans_omp_do): Set exact argument of a vector growth function to true. gcc/lto/ChangeLog: * lto-common.c (lto_file_finalize): Set exact argument of a vector growth function to true.
2020-07-31Set and test no-warning bit to avoid -Wnonnull for synthesized expressions.Martin Sebor1-2/+8
Resolves: PR c++/96003 spurious -Wnonnull calling a member on the result of static_cast gcc/c-family/ChangeLog: PR c++/96003 * c-common.c (check_function_arguments_recurse): Return early when no-warning bit is set. gcc/cp/ChangeLog: PR c++/96003 * class.c (build_base_path): Set no-warning bit on the synthesized conditional expression in static_cast. gcc/testsuite/ChangeLog: PR c++/96003 * g++.dg/warn/Wnonnull7.C: New test.
2020-07-28c++: better fixup_type_variantsNathan Sidwell1-6/+4
fixup_type_variants was almost doing all that finish_struct needs. May as well make it do it all. gcc/cp/ * class.c (fixup_type_variants): Copy TYPE_SIZE and TYPE_SIZE_UINIT. (finish_struct): Call it.
2020-07-27c++: Name as_base typeNathan Sidwell1-2/+7
The as-base type never got a name. For modules I needed to give it a name to serialize properly, and it's useful when debugging the compiler, so we may as well have it on trunk. There's also a bug where its fields can have NSDMIs from the main class. This happens to be silent on trunk, but can be a GC leak where we retain a deferred parse node there. (On modules it blows up, because we're not prepared to serialize deferred parse nodes, as they should never survive parsing. gcc/cp/ * cp-tree.h (enum cp_tree_index): Add CPTI_AS_BASE_IDENTIFIER. (as_base_identifier): Define. * decl.c (initialize_predifined_identifiers): Initialize as_base identifier. * class.c (layout_class_type): Name the as-base type. Zap NSDMI its fields may have.
2020-07-22c++: Don't add enums to class's decl_listNathan Sidwell1-5/+8
We don't need to add CONST_DECLs to a template decl's decl list. Also made the code flow a bit clearer. gcc/cp/ * class.c (maybe_add_class_template_decl_list): Don't add CONST_DECLs.
2020-07-14c++: Refactor some class fnsNathan Sidwell1-16/+17
Storing CLASSTYPE_AS_BASE in a local variable makes some code clearer (and textually no longer). For some reason we store a DECL in a variable called 'value', which is confusing. gcc/cp/ * class.c (build_base_field_1): Cache CLASSTYPE_AS_BASE. (build_self_reference): Rename value -> decl. (dump_class_hierarchy_1): Cache CLASSTYPE_AS_BASE.
2020-07-14c++: Comments & formattingNathan Sidwell1-4/+8
I found some bad formatting and misleading or incomplete comments during my spelunking around the c++FE. May as well clean up trunk and record what I noted. gcc/cp/ * cp-tree.h: Correct some tree lang flag comments, reformat some structure definitions. Note some structure sizes. Clarify some comments. (yyungetc): Delete. Not been a thing for some time. * class.c (copy_fndecl_with_name): Comment. (check_bases_and_members): Unnecessary {}. (layout_class_type): Comment. * cp-tree.def (UNBOUND_CLASS_TEMPLATE): Adjust comment. * decl.c: Fix some formatting & whitespace issues. (function_requirements_equivalent_p): Note why substitutions are needed. * decl2.c (no_linkage_error): Note that heroics about 'typedef struct { ... };' are no longer needed. * method.c: Whitespace. * name-lookup.c: Whitespace. (add_decl_to_level): Reformat a line. (print_binding_stack): Mark as DEBUG_FUNCTION. (has_using_namespace_std_directive_p): Delete comment. * pt.c: Whitespace * ptree.c: Whitespace. * rtti.c: Whitespace & comment. * tree.c: Comment. * typeck.c (structural_comptypes): Add comment.
2020-07-10c++: [[no_unique_address]] fixes. [PR96105]Jason Merrill1-7/+20
We were wrongly checking is_empty_class on the result of strip_array_types rather than the actual field type. We weren't considering the alignment of the data member. We needed to handle unions the same way as layout_nonempty_base_or_field. gcc/cp/ChangeLog: PR c++/96105 PR c++/96052 PR c++/95976 * class.c (check_field_decls): An array of empty classes is not an empty data member. (layout_empty_base_or_field): Handle explicit alignment. Fix union handling. gcc/testsuite/ChangeLog: PR c++/96105 PR c++/96052 PR c++/95976 * g++.dg/cpp2a/no_unique_address4.C: New test. * g++.dg/cpp2a/no_unique_address5.C: New test. * g++.dg/cpp2a/no_unique_address6.C: New test.
2020-07-01c++: Expose cloning form predicatesNathan Sidwell1-27/+41
A further adjustment of the function cloning. Rather than have copy_fndecl_with_name deduce whether a particular cdtor needs a vtt_parm and/or has inherited parms to drop, pass that information in from the caller. In particular build_cdtor_clones knows when its building the particular cdtors that might need these. On the modules branch I need to clone cdtors before the underlying class information is necessarily complete. There build_cdtor_clones is externally callable to facilitate that. gcc/cp/ * class.c (copy_fndecl_with_name): Add additional predicate args, do not deduce them locally. (copy_operator_fn): Adjust copy_fndecl_with_name call. (build_clone): Add vtt and inherited predicate args. Pass through to copy_fndecl_with_name call. (build_cdtor_clones): Likewise, pass through to build_clone as needed. (build_cdtor): Determine vtt and inherited here. * cp-tree.h (DECL_NEEDS_CTT_PARM_P): Delete.
2020-06-30c++: Tweak function cloning namesNathan Sidwell1-7/+15
On the modules branch I need to expose an intermediate step of the function cloning, but before that it'd be nice to rationalize the names somewhat, now that we also use that API for copying the equality operator. Jason's recent patch caused me some pain by altering the same code. I can only blame myself for not pushing some bits sooner. Anyway, this patch makes the newly renamed copy_fndecl_with_name static, and adds a wrapper copy_operator_fn, that takes an operator code. The cdtor cloning functions are renamed to explicitly note they expect cdtors. A followup patch will move some of the logic from copy_fndecl_with_name to build_cdtor_clones. gcc/cp/ * cp-tree.h (copy_fndecl_with_name): Rename to ... (copy_operatorn_fn): ... this. Change arg type. (clone_function_decl): Rename to ... (clone_cdtor): ... this. * class.c (copy_fndecl_with_name): Make static. (copy_operator_fn): New wrapper. (build_clones): Rename to ... (build_cdtor_clones): ... this. (clone_function_decl): Rename to ... (clone_cdtor): ... this. Adjust build_clones calls. (clone_constructors_and_destructors): Adjust clone_function_decl calls. * method.c (implicitly_declare_fn): Adjust copy_fndecl_with_name call. (lazily_declare_fn): Adjust clone_function_decl call. * pt.c (tsubst_function_decl): Likewise. (instantiate_template_1): Likewise. libcc1/ * libcp1plugin.cc (plugin_build_decl): Adjust clone_function_decl call.
2020-06-24c++: Fix ICE with using and virtual function. [PR95719]Jason Merrill1-0/+4
conversion_path points to the base where we found the using-declaration, not where the function is actually a member; look up the actual base. And then maybe look back to the derived class if the base is primary. gcc/cp/ChangeLog: PR c++/95719 * call.c (build_over_call): Look up the overrider in base_binfo. * class.c (lookup_vfn_in_binfo): Look through BINFO_PRIMARY_P. gcc/testsuite/ChangeLog: PR c++/95719 * g++.dg/tree-ssa/final4.C: New test.
2020-06-17c++: implicit operator== adjustments from P2002.Jason Merrill1-29/+57
P2002R1, adopted at the February C++ meeting, made several refinements to the wording for operator<=>. This implements clarifications in how the implicit operator== is declared: as a duplicate of the operator<=>, with only the return type and name changed. To that end I factored out the declaration copying from build_clone. gcc/cp/ChangeLog: * cp-tree.h (copy_fndecl_with_name): Declare. * class.c (copy_fndecl_with_name): Split out from... (build_clone): ...here. (add_implicitly_declared_members): Add op== to TYPE_FIELDS. * method.c (implicitly_declare_fn): Use copy_fndecl_with_name. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/spaceship-synth9.C: New test.
2020-06-04c++: Fix FE devirt with diamond inheritance [PR95158]Jason Merrill1-0/+14
This started breaking in GCC 8 because of the fix for PR15272; after that change, we (correctly) remember the lookup from template parsing time that found Base::foo through the non-dependent MiddleB base, and so we overlook the overrider in MiddleA. But given that, the devirtualization condition from the fix for PR59031 is insufficient; we know that d has to be a Derived, and we found Base::foo in Base, but forcing a non-virtual call gets the wrong function. Fixed by removing the PR59031 code that the PR67184 patch moved to build_over_call, and instead looking up the overrider in BINFO_VIRTUALS. gcc/cp/ChangeLog: PR c++/95158 * class.c (lookup_vfn_in_binfo): New. * call.c (build_over_call): Use it. * cp-tree.h (resolves_to_fixed_type_p): Add default argument. (lookup_vfn_in_binfo): Declare. gcc/testsuite/ChangeLog: PR c++/95158 * g++.dg/template/virtual5.C: New test.
2020-06-01c++: vptr ubsan and object of known type [PR95466]Jason Merrill1-6/+2
Another case where we can't find the OBJ_TYPE_REF_OBJECT in the OBJ_TYPE_REF_EXPR. So let's just evaluate the sanitize call first. gcc/cp/ChangeLog: PR c++/95466 PR c++/95311 PR c++/95221 * class.c (build_vfn_ref): Revert 95311 change. * cp-ubsan.c (cp_ubsan_maybe_instrument_member_call): Build a COMPOUND_EXPR. gcc/testsuite/ChangeLog: PR c++/95466 * g++.dg/ubsan/vptr-17.C: New test.
2020-05-29c++: P0848R3 and member function templates [PR95181]Patrick Palka1-4/+11
When comparing two special member function templates to see if one hides the other (as per P0848R3), we need to check satisfaction which we can't do on templates. So this patch makes add_method skip the eligibility test on member function templates and just lets them coexist. gcc/cp/ChangeLog: PR c++/95181 * class.c (add_method): Let special member function templates coexist if they are not equivalently constrained, or in a class template. gcc/testsuite/ChangeLog: PR c++/95181 * g++.dg/concepts/pr95181.C: New test. * g++.dg/concepts/pr95181-2.C: New test. Co-authored-by: Jason Merrill <jason@redhat.com>
2020-05-29c++: vptr ubsan and derived class [PR95311].Jason Merrill1-2/+6
We weren't able to find OBJ_TYPE_REF_OBJECT walking through OBJ_TYPE_REF_EXPR because we had folded away the ADDR_EXPR. gcc/cp/ChangeLog: PR c++/95311 PR c++/95221 * class.c (build_vfn_ref): Don't fold the INDIRECT_REF. gcc/testsuite/ChangeLog: PR c++/95311 * g++.dg/ubsan/vptr-16.C: New test.
2020-05-14c++: Missing SFINAE with lookup_fnfields [PR78446]Patrick Palka1-1/+1
Here we're failing to do SFINAE in build_op_call when looking up the class's operator() via lookup_fnfields, which calls lookup_member always with complain=tf_warning_or_error; from there we would complain about an ambiguous lookup for operator(). This patch fixes this by adding a tsubst_flags_t parameter to lookup_fnfields and adjusting all its callers appropriately. gcc/cp/ChangeLog: PR c++/78446 * call.c (build_op_call): Pass complain to lookup_fnfields. (build_special_member_call): Likewise. * class.c (type_requires_array_cookie): Pass tf_warning_or_error to lookup_fnfields. * cp-tree.h (lookup_fnfields): Add tsubst_flags_t parameter. * except.c (build_throw): Pass tf_warning_or_error to lookup_fnfields. * init.c (build_new_1): Pass complain to lookup_fnfields. * method.c (locate_fn_flags): Likewise. * name-lookup.c (lookup_name_real_1): Pass tf_warning_or_error to lookup_fnfields. * pt.c (tsubst_baselink): Pass complain to lookup_fnfields. * search.c (lookup_fnfields): New 'complain' parameter. Pass it to lookup_member. gcc/testsuite/ChangeLog: PR c++/78446 * g++.dg/template/sfinae31.C: New test.
2020-05-13c++: Replace "C++2a" with "C++20".Jason Merrill1-5/+5
C++20 isn't final quite yet, but all that remains is formalities, so let's go ahead and change all the references. I think for the next C++ standard we can just call it C++23 rather than C++2b, since the committee has been consistent about time-based releases rather than feature-based. gcc/c-family/ChangeLog 2020-05-13 Jason Merrill <jason@redhat.com> * c.opt (std=c++20): Make c++2a the alias. (std=gnu++20): Likewise. * c-common.h (cxx_dialect): Change cxx2a to cxx20. * c-opts.c: Adjust. * c-cppbuiltin.c: Adjust. * c-ubsan.c: Adjust. * c-warn.c: Adjust. gcc/cp/ChangeLog 2020-05-13 Jason Merrill <jason@redhat.com> * call.c, class.c, constexpr.c, constraint.cc, decl.c, init.c, lambda.c, lex.c, method.c, name-lookup.c, parser.c, pt.c, tree.c, typeck2.c: Change cxx2a to cxx20. libcpp/ChangeLog 2020-05-13 Jason Merrill <jason@redhat.com> * include/cpplib.h (enum c_lang): Change CXX2A to CXX20. * init.c, lex.c: Adjust.
2020-05-07c++: Fix spelling of non-staticMarek Polacek1-4/+4
I was looking at DR 296 and noticed that we say "nonstatic" instead of "non-static", which is the version the standard uses. So this patch fixes the spelling throughout the front end. Did not check e.g. non-dependent or any other. * decl.c (grok_op_properties): Fix spelling of non-static. * typeck.c (build_class_member_access_expr): Likewise. * g++.dg/other/operator1.C: Adjust expected message. * g++.dg/overload/operator2.C: Likewise. * g++.dg/template/error30.C: Likewise. * g++.old-deja/g++.jason/operator.C: Likewise.
2020-04-29c++, middle-end, rs6000: Fix C++17 ABI incompatibilities during class layout ↵Jakub Jelinek1-1/+5
and [[no_unique_address]] handling [PR94707] As reported by Iain and David, powerpc-darwin and powerpc-aix* have C++14 vs. C++17 ABI incompatibilities which are not fixed by mere adding of cxx17_empty_base_field_p calls. Unlike the issues that were seen on other targets where the artificial empty base field affected function argument passing or returning of values, on these two targets the difference is during class layout, not afterwards (e.g. struct empty_base {}; struct S : public empty_base { unsigned long long l[2]; }; will have different __alignof__ (S) between C++14 and C++17 (or possibly with double instead of unsigned long long too)). I've tried: struct X { }; struct Y { int : 0; }; struct Z { int : 0; Y y; }; struct U : public X { X q; }; struct A { float a, b, c, d; }; struct B : public X { float a, b, c, d; }; struct C : public Y { float a, b, c, d; }; struct D : public Z { float a, b, c, d; }; struct E : public U { float a, b, c, d; }; struct F { [[no_unique_address]] X x; float a, b, c, d; }; struct G { [[no_unique_address]] Y y; float a, b, c, d; }; struct H { [[no_unique_address]] Z z; float a, b, c, d; }; struct I { [[no_unique_address]] U u; float a, b, c, d; }; struct J { float a, b; [[no_unique_address]] X x; float c, d; }; struct K { float a, b; [[no_unique_address]] Y y; float c, d; }; struct L { float a, b; [[no_unique_address]] Z z; float c, d; }; struct M { float a, b; [[no_unique_address]] U u; float c, d; }; #define T(S, s) extern S s; extern void foo##s (S); int bar##s () { foo##s (s); return 0; } T (A, a) T (B, b) T (C, c) T (D, d) T (E, e) T (F, f) T (G, g) T (H, h) T (I, i) T (J, j) T (K, k) T (L, l) T (M, m) testcase on powerpc64-linux. Results: G++ 9 -std=c++14 A, B, C passed in fprs, the rest in gprs G++ 9 -std=c++17 A passed in fprs, the rest in gprs current trunk -std=c++14 & 17 A, B, C passed in fprs, the rest in gprs patched trunk -std=c++14 & 17 A, B, C, F, G, J, K passed in fprs, the rest in gprs clang++ [*] -std=c++14 & 17 A, B, C, F, G, J, K passed in fprs, the rest in gprs [*] clang version 11.0.0 (git@github.com:llvm/llvm-project.git 5c352e69e76a26e4eda075e20aa6a9bb7686042c) Is that what we want? I think it matches the stated intent of P0840R2 or what Jason/Jonathan said, and doing something different like e.g. not treating C, G and K as homogenous because of the int : 0 in empty bases or in zero sized [[no_unique_address] fields would be quite hard to implement (because for C++14 the FIELD_DECL just isn't there). 2020-04-29 Jakub Jelinek <jakub@redhat.com> PR target/94707 * tree-core.h (tree_decl_common): Note decl_flag_0 used for DECL_FIELD_ABI_IGNORED. * tree.h (DECL_FIELD_ABI_IGNORED): Define. * calls.h (cxx17_empty_base_field_p): Change into a temporary macro, check DECL_FIELD_ABI_IGNORED flag with no "no_unique_address" attribute. * calls.c (cxx17_empty_base_field_p): Remove. * tree-streamer-out.c (pack_ts_decl_common_value_fields): Handle DECL_FIELD_ABI_IGNORED. * tree-streamer-in.c (unpack_ts_decl_common_value_fields): Likewise. * lto-streamer-out.c (hash_tree): Likewise. * config/rs6000/rs6000-call.c (rs6000_aggregate_candidate): Rename cxx17_empty_base_seen to empty_base_seen, change type to int *, adjust recursive calls, use DECL_FIELD_ABI_IGNORED instead of cxx17_empty_base_field_p, if "no_unique_address" attribute is present, propagate that to the caller too. (rs6000_discover_homogeneous_aggregate): Adjust rs6000_aggregate_candidate caller, emit different diagnostics when c++17 empty base fields are present and when empty [[no_unique_address]] fields are present. * config/rs6000/rs6000.c (rs6000_special_round_type_align, darwin_rs6000_special_round_type_align): Skip DECL_FIELD_ABI_IGNORED fields. * class.c (build_base_field): Set DECL_FIELD_ABI_IGNORED on C++17 empty base artificial FIELD_DECLs. (layout_class_type): Set DECL_FIELD_ABI_IGNORED on empty class field_poverlapping_p FIELD_DECLs. * lto-common.c (compare_tree_sccs_1): Handle DECL_FIELD_ABI_IGNORED. * g++.target/powerpc/pr94707-1.C: New test. * g++.target/powerpc/pr94707-2.C: New test. * g++.target/powerpc/pr94707-3.C: New test. * g++.target/powerpc/pr94707-4.C: New test. * g++.target/powerpc/pr94707-5.C: New test. * g++.target/powerpc/pr94707-4.C: New test.
2020-04-22c++: Change -Weffc++ diagnostic to use "declare" (PR 94698)Jonathan Wakely1-2/+2
Change the wording again, for the reasons given by Jason in https://gcc.gnu.org/pipermail/gcc-patches/2020-April/544362.html PR translation/94698 * class.c (check_field_decls): Change "define" to "declare" in -Weffc++ diagnostics.
2020-04-22c++: Fix misuse of "override" in -Weffc++ warnings (PR 94698)Jonathan Wakely1-2/+2
These warnings have nothing to do with virtual functions, so "override" is inappropriate. The warnings are just talking about defining special members, so let's say that. PR translation/94698 * class.c (check_field_decls): Change "override" to "define" in -Weffc++ diagnostics.
2020-03-26c++: Fix up user_provided_p [PR81349]Jakub Jelinek1-6/+4
The standard says: "A function is user-provided if it is user-declared and not explicitly defaulted or deleted on its first declaration." I don't see anything about function templates having different rules here, but user_provided_p does return true for all TEMPLATE_DECLs. The following patch fixes it by treating as user-provided only templates that aren't deleted. 2020-03-26 Jakub Jelinek <jakub@redhat.com> PR c++/81349 * class.c (user_provided_p): Use STRIP_TEMPLATE instead of returning true for all TEMPLATE_DECLs. * g++.dg/cpp1z/pr81349.C: New test.
2020-03-09c++: Fix ABI issue with alignas on armv7hl [PR94050]Marek Polacek1-0/+4
The static_assert in the following test was failing on armv7hl because we were disregarding the alignas specifier on Cell. BaseShape's data takes up 20B on 32-bit architectures, but we failed to round up its TYPE_SIZE. This happens since the <https://gcc.gnu.org/ml/gcc-patches/2019-06/msg01189.html> patch: here, in layout_class_type for TenuredCell, we see that the size of TenuredCell and its CLASSTYPE_AS_BASE match, so we set CLASSTYPE_AS_BASE (t) = t; While TYPE_USER_ALIGN of TenuredCell was 0, because finalize_type_size called from finish_record_layout reset it, TYPE_USER_ALIGN of its CLASSTYPE_AS_BASE still remained 1. After we replace it, it's no longer 1. Then we perform layout_empty_base_or_field for TenuredCell and since TYPE_USER_ALIGN of its CLASSTYPE_AS_BASE is now 0, we don't do this adjustment: if (CLASSTYPE_USER_ALIGN (type)) { rli->record_align = MAX (rli->record_align, CLASSTYPE_ALIGN (type)); if (warn_packed) rli->unpacked_align = MAX (rli->unpacked_align, CLASSTYPE_ALIGN (type)); TYPE_USER_ALIGN (rli->t) = 1; } where rli->t is BaseShape. Then finalize_record_size won't use the correct rli->record_align and therefore /* Round the size up to be a multiple of the required alignment. */ TYPE_SIZE (rli->t) = round_up (unpadded_size, TYPE_ALIGN (rli->t)); after this we end up with the wrong size. Since the original fix was to avoid creating extra copies for LTO purposes, I think the following fix should be acceptable. PR c++/94050 - ABI issue with alignas on armv7hl. * class.c (layout_class_type): Don't replace a class's CLASSTYPE_AS_BASE if their TYPE_USER_ALIGN don't match. * g++.dg/abi/align3.C: New test.
2020-02-27Fix broken type comparison assertNathan Sidwell1-2/+2
In implementing Jason's suggested direction for 93933, the compiler exploded in a surprising way. Turns out an assert had been passing NULLS to comptypes, and therefore not checking what it intended. Further comptypes, could silently accept such nulls under most circumstances. * class.c (adjust_clone_args): Correct arg-checking assert. * typeck.c (comptypes): Assert not nulls.
2020-02-26coroutines: Amend parameter handling to match n4849.Iain Sandoe1-0/+13
In n4849 and preceding versions, [class.copy.elision] (1.3) appears to confer additional permissions on coroutines to elide parameter copies. After considerable discussion on this topic by email and during the February 2020 WG21 meeting, it has been determined that there are no additional permissions applicable to coroutine parameter copy elision. The content of that clause in the standard is expected to be amended eventually to clarify this. Other than this, the handling of parameter lifetimes is expected to be as per n4849: * A copy is made before the promise is constructed * If the promise CTOR uses the parms, then it should use the copy where appropriate. * The param copy lifetimes end after the promise is destroyed (during the coroutine frame destruction). * Otherwise, C++20 copy elision rules apply. (as an aside) In practice, we expect that copy elision can only occur when the coroutine body is fully inlined, possibly in conjunction with heap allocation elision. The patch: * Reorders the copying process to precede the promise CTOR and ensures the correct use. * Copies all params into the frame regardless of whether the coro body uses them (this is a bit unfortunate, and we should figure out an amendment for C++23). gcc/cp/ChangeLog: 2020-02-26 Iain Sandoe <iain@sandoe.co.uk> * class.c (classtype_has_non_deleted_copy_ctor): New. * coroutines.cc (struct param_info): Keep track of params that are references, and cache the original type and whether the DTOR is trivial. (build_actor_fn): Handle param copies always, and adjust the handling for references. (register_param_uses): Only handle uses here. (classtype_has_non_deleted_copy_ctor): New. (morph_fn_to_coro): Adjust param copy handling to match n4849 by reordering ahead of the promise CTOR and always making a frame copy, even if the param is unused in the coroutine body. * cp-tree.h (classtype_has_non_deleted_copy_ctor): New. gcc/testsuite/ChangeLog: 2020-02-26 Iain Sandoe <iain@sandoe.co.uk> * g++.dg/coroutines/coro1-refs-and-ctors.h: New. * g++.dg/coroutines/torture/func-params-07.C: New test. * g++.dg/coroutines/torture/func-params-08.C: New test.
2020-02-21PR c++/93753 - ICE on a flexible array followed by a member in an anonymous ↵Martin Sebor1-0/+2
struct with an initializer gcc/cp/ChangeLog: PR gcov-profile/93753 * class.c (check_flexarrays): Tighten up a test for potential members of anonymous structs or unions. gcc/testsuite/ChangeLog: PR gcov-profile/93753 * g++.dg/ext/flexary36.C: New test. * g++.dg/lto/pr93166_0.C: Make struct with flexarray valid.
2020-02-14c++: Fix thinko in enum_min_precision [PR61414]Jakub Jelinek1-1/+1
When backporting the PR61414 fix to 8.4, I've noticed that the caching of prec is actually broken, as it would fail to actually store the computed precision into the hash_map's value and so next time we'd think the enum needs 0 bits. 2020-02-14 Jakub Jelinek <jakub@redhat.com> PR c++/61414 * class.c (enum_min_precision): Change prec type from int to int &. * g++.dg/cpp0x/enum39.C: New test.
2020-02-12c++: Fix implicit friend operator==.Jason Merrill1-1/+5
It seems that in writing testcases for the operator<=> proposal I didn't include any tests for implicitly declared friend operator==, and consequently it didn't work. 2020-02-11 Jason Merrill <jason@redhat.com> PR c++/93675 * class.c (add_implicitly_declared_members): Use do_friend. * method.c (implicitly_declare_fn): Fix friend handling. (decl_remember_implicit_trigger_p): New. (synthesize_method): Use it. * decl2.c (mark_used): Use it.
2020-01-14PR c++/92590 - wrong handling of inherited default ctor.Jason Merrill1-2/+3
I thought my earlier fix for 91930 was an obvious bug fix, but apparently an inherited constructor does not count as user-declared. So this patch reverts that change and the other follow-on patches, and fixes 91930 differently, by not letting the inherited default constructor hide the implicitly-declared default constructor. * class.c (add_method): A constrained inherited ctor doesn't hide an implicit derived ctor. Revert: PR c++/91930 - ICE with constrained inherited default ctor. * name-lookup.c (do_class_using_decl): Set TYPE_HAS_USER_CONSTRUCTOR for inherited constructor. PR c++/92552 - ICE with inherited constrained default ctor. * pt.c (instantiate_class_template_1): Copy TYPE_HAS_USER_CONSTRUCTOR. PR c++/92594 - ICE with inherited trivial default ctor. * method.c (trivial_fn_p): Treat an inherited default constructor like a normal default constructor.
2020-01-06PR c++/92552 - ICE with inherited constrained default ctor.Jason Merrill1-1/+0
We set TYPE_HAS_USER_CONSTRUCTOR on the template type in lookup_using_decl, but we didn't copy it to the instantiation. Setting it in one_inherited_ctor is too late, as that gets called after we decide whether to set CLASSTYPE_LAZY_DEFAULT_CTOR. This change affects other testcases as well; the changes are fixes for the other inherited constructor tests as well. * pt.c (instantiate_class_template_1): Copy TYPE_HAS_USER_CONSTRUCTOR. * class.c (one_inherited_ctor): Don't set it here. From-SVN: r279936
2020-01-01Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r279813
2019-12-11re PR c++/92869 (C++17 wrongly reports aggregate type as not-aggregate (when ↵Jakub Jelinek1-1/+7
explicitly defaulted ctors are added)) PR c++/92869 * class.c (finish_struct): For C++17 and earlier, check type_has_user_provided_or_explicit_constructor rather than TYPE_HAS_USER_CONSTRUCTOR whether to set CLASSTYPE_NON_AGGREGATE. * g++.dg/cpp0x/aggr3.C: New test. From-SVN: r279241
2019-12-10Fix C++20 structural type vs. private base.Jason Merrill1-18/+36
In my patch to implement C++20 "structural type" I tried to set the access flags on the artificial base fields appropriately, but failed. I was copying TREE_PRIVATE from the binfo, but TREE_PRIVATE on binfo is just a temporary cache for dfs_access_in_type; we really need to get the inheritance access information from BINFO_BASE_ACCESSES. * class.c (build_base_field_1): Take access parameter. (build_base_field): Likewise. (build_base_fields, layout_virtual_bases): Pass it. * tree.c (structural_type_p): Improve private base diagnostic. From-SVN: r279184
2019-12-05PR c++/91353 - P1331R2: Allow trivial default init in constexpr contexts.Marek Polacek1-2/+8
This patch implements C++20 P1331, allowing trivial default initialization in constexpr contexts. * c-cppbuiltin.c (c_cpp_builtins): Adjust the value of __cpp_constexpr. * class.c (trivial_default_constructor_is_constexpr): Return true in C++20. * constexpr.c (cx_check_missing_mem_inits): Allow missing field initializers in C++20. (cxx_eval_call_expression): Don't clear CONSTRUCTOR_NO_CLEARING for constexpr constructors in C++20. (reduced_constant_expression_p): Don't set FIELD for union and array types. Skip empty class fields without initializers. * decl.c (check_for_uninitialized_const_var): Permit trivial default initialization in constexpr. (next_initializable_field): Don't skip vptr fields. * method.c (walk_field_subobs): Still consider a constructor that doesn't initialize all the members constexpr. * g++.dg/cpp0x/constexpr-array6.C: Adjust dg-error. * g++.dg/cpp0x/constexpr-ctor.C: Likewise. * g++.dg/cpp0x/constexpr-diag3.C: Likewise. * g++.dg/cpp0x/constexpr-diag4.C: Likewise. * g++.dg/cpp0x/constexpr-ex3.C: Likewise. * g++.dg/cpp0x/constexpr-template2.C: Likewise. * g++.dg/cpp0x/constexpr-union2.C: Likewise. * g++.dg/cpp0x/lambda/lambda-mangle.C: Rip out a piece of code ... * g++.dg/cpp0x/lambda/lambda-mangle6.C: ... and put it here. * g++.dg/cpp0x/pr79118.C: Adjust dg-error. * g++.dg/cpp1y/constexpr-83921-3.C: Likewise. * g++.dg/cpp1y/constexpr-neg1.C: Likewise. * g++.dg/cpp1z/constexpr-lambda12.C: Likewise. * g++.dg/cpp1z/feat-cxx1z.C: Use -std=c++17. * g++.dg/cpp2a/constexpr-init1.C: New test. * g++.dg/cpp2a/constexpr-init2.C: New test. * g++.dg/cpp2a/constexpr-init3.C: New test. * g++.dg/cpp2a/constexpr-init4.C: New test. * g++.dg/cpp2a/constexpr-init5.C: New test. * g++.dg/cpp2a/constexpr-init6.C: New test. * g++.dg/cpp2a/constexpr-init7.C: New test. * g++.dg/cpp2a/constexpr-init8.C: New test. * g++.dg/cpp2a/constexpr-init9.C: New test. * g++.dg/cpp2a/constexpr-init10.C: New test. * g++.dg/cpp2a/constexpr-init11.C: New test. * g++.dg/cpp2a/constexpr-init12.C: New test. * g++.dg/cpp2a/constexpr-init13.C: New test. * g++.dg/cpp2a/constexpr-init14.C: New test. * g++.dg/cpp2a/constexpr-init15.C: New test. * g++.dg/cpp2a/constexpr-try5.C: Adjust dg-error. * g++.dg/cpp2a/feat-cxx2a.C: Test __cpp_constexpr. * g++.dg/cpp2a/lambda-mangle.C: New test. * g++.dg/debug/dwarf2/pr44641.C: Skip for c++2a. * g++.dg/ext/stmtexpr21.C: Adjust dg-error. Co-Authored-By: Jakub Jelinek <jakub@redhat.com> From-SVN: r279019
2019-11-26re PR c++/61414 (enum class bitfield size-checking needs a separate warning ↵Jakub Jelinek1-1/+55
flag controlling it) PR c++/61414 * c-attribs.c (handle_mode_attribute): Add mode attribute to ENUMERAL_TYPEs. * class.c (enum_to_min_precision): New hash_map. (enum_min_precision): New function. (check_bitfield_decl): Use it. * g++.dg/cpp0x/enum23.C: Remove xfail. * g++.dg/cpp0x/enum28.C: New test. From-SVN: r278736
2019-11-15Implement P1816R0, class template argument deduction for aggregates.Jason Merrill1-1/+13
Rather than reimplement brace elision here, we call reshape_init and then discard the result. We needed to set CLASSTYPE_NON_AGGREGATE a bit more in this patch, since outside a template it's set in check_bases_and_members. * pt.c (maybe_aggr_guide, collect_ctor_idx_types): New. (is_spec_or_derived): Split out from do_class_deduction. (build_deduction_guide): Handle aggregate guide. * class.c (finish_struct): Set CLASSTYPE_NON_AGGREGATE in a template. * cp-tree.h (CP_AGGREGATE_TYPE_P): An incomplete class is not an aggregate. From-SVN: r278298
2019-11-06Implement D1907R1 "structural type".Jason Merrill1-3/+6
ISO C++ paper D1907R1 proposes "structural type" as an alternative to the current notion of "strong structural equality", which has various problems. I'm implementing it to give people a chance to try it. The build_base_field changes are to make it easier for structural_type_p to see whether a base is private or protected. * tree.c (structural_type_p): New. * pt.c (invalid_nontype_parm_type_p): Use it. * class.c (build_base_field_1): Take binfo. Copy TREE_PRIVATE. (build_base_field): Pass binfo. From-SVN: r277902
2019-11-05Implement C++20 operator<=>.Jason Merrill1-0/+49
There are three major pieces to this support: scalar operator<=>, synthesis of comparison operators, and rewritten/reversed overload resolution (e.g. a < b becomes 0 > b <=> a). Unlike other defaulted functions, where we use synthesized_method_walk to semi-simulate what the definition of the function will be like, this patch determines the characteristics of a comparison operator by trying to define it. My handling of non-dependent rewritten operators in templates can still use some work: build_min_non_dep_op_overload can't understand the rewrites and crashes, so I'm avoiding it for now by clearing *overload. This means we'll do name lookup again at instantiation time, which can incorrectly mean a different result. I'll poke at this more in stage 3. I'm leaving out a fourth section ("strong structural equality") even though I've implemented it, because it seems likely to change radically tomorrow. Thanks to Tim van Deurzen and Jakub for implementing lexing of the <=> operator, and Jonathan for the initial <compare> header. gcc/cp/ * cp-tree.h (struct lang_decl_fn): Add maybe_deleted bitfield. (DECL_MAYBE_DELETED): New. (enum special_function_kind): Add sfk_comparison. (LOOKUP_REWRITTEN, LOOKUP_REVERSED): New. * call.c (struct z_candidate): Add rewritten and reversed methods. (add_builtin_candidate): Handle SPACESHIP_EXPR. (add_builtin_candidates): Likewise. (add_candidates): Don't add a reversed candidate if the parms are the same. (add_operator_candidates): Split out from build_new_op_1. Handle rewritten and reversed candidates. (add_candidate): Swap conversions of reversed candidate. (build_new_op_1): Swap them back. Build a second operation for rewritten candidates. (extract_call_expr): Handle rewritten calls. (same_fn_or_template): New. (joust): Handle rewritten and reversed candidates. * class.c (add_implicitly_declared_members): Add implicit op==. (classtype_has_op, classtype_has_defaulted_op): New. * constexpr.c (cxx_eval_binary_expression): Handle SPACESHIP_EXPR. (cxx_eval_constant_expression, potential_constant_expression_1): Likewise. * cp-gimplify.c (genericize_spaceship): New. (cp_genericize_r): Use it. * cp-objcp-common.c (cp_common_init_ts): Handle SPACESHIP_EXPR. * decl.c (finish_function): Handle deleted function. * decl2.c (grokfield): SET_DECL_FRIEND_CONTEXT on defaulted friend. (mark_used): Check DECL_MAYBE_DELETED. Remove assumption that defaulted functions are non-static members. * error.c (dump_expr): Handle SPACESHIP_EXPR. * method.c (type_has_trivial_fn): False for sfk_comparison. (enum comp_cat_tag, struct comp_cat_info_t): New types. (comp_cat_cache): New array variable. (lookup_comparison_result, lookup_comparison_category) (is_cat, cat_tag_for, spaceship_comp_cat) (spaceship_type, genericize_spaceship) (common_comparison_type, early_check_defaulted_comparison) (comp_info, build_comparison_op): New. (synthesize_method): Handle sfk_comparison. Handle deleted. (get_defaulted_eh_spec, maybe_explain_implicit_delete) (explain_implicit_non_constexpr, implicitly_declare_fn) (defaulted_late_check, defaultable_fn_check): Handle sfk_comparison. * name-lookup.c (get_std_name_hint): Add comparison categories. * tree.c (special_function_p): Add sfk_comparison. * typeck.c (cp_build_binary_op): Handle SPACESHIP_EXPR. 2019-11-05 Tim van Deurzen <tim@kompiler.org> Add new tree code for the spaceship operator. gcc/cp/ * cp-tree.def: Add new tree code. * operators.def: New binary operator. * parser.c: Add new token and tree code. libcpp/ * cpplib.h: Add spaceship operator for C++. * lex.c: Implement conditional lexing of spaceship operator for C++20. 2019-11-05 Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ * libsupc++/compare: New header. * libsupc++/Makefile.am (std_HEADERS): Add compare. * include/std/version: Define __cpp_lib_three_way_comparison. * include/std/functional: #include <compare>. From-SVN: r277865
2019-11-01[C++ PATCH] cleanup check_field_declsNathan Sidwell1-139/+141
https://gcc.gnu.org/ml/gcc-patches/2019-11/msg00012.html cp/ * class.c (check_field_decls): Refactor. testsuite/ * g++.dg/template/fn.C: New. From-SVN: r277707
2019-10-30cp-tree.h (omp_declare_variant_finalize, [...]): Declare.Jakub Jelinek1-0/+8
* cp-tree.h (omp_declare_variant_finalize, build_local_temp): Declare. * decl.c: Include omp-general.h. (declare_simd_adjust_this): Add forward declaration. (omp_declare_variant_finalize_one, omp_declare_variant_finalize): New function. (cp_finish_decl, finish_function): Call omp_declare_variant_finalize. * parser.c (cp_finish_omp_declare_variant): Adjust parsing of the variant id-expression and propagate enough information to omp_declare_variant_finalize_one in the attribute so that it can finalize it. * class.c (finish_struct): Call omp_declare_variant_finalize. * tree.c (build_local_temp): No longer static, remove forward declaration. * c-c++-common/gomp/declare-variant-2.c: Add a test with , before match clause. * c-c++-common/gomp/declare-variant-6.c: Expect diagnostics also from C++ FE and adjust regexp so that it handles C++ pretty printing of function names. * g++.dg/gomp/declare-variant-1.C: New test. * g++.dg/gomp/declare-variant-2.C: New test. * g++.dg/gomp/declare-variant-3.C: New test. * g++.dg/gomp/declare-variant-4.C: New test. * g++.dg/gomp/declare-variant-5.C: New test. From-SVN: r277613
2019-10-15[C++ PATCH] clone_function_decl breakupNathan Sidwell1-26/+37
https://gcc.gnu.org/ml/gcc-patches/2019-10/msg01083.html This patch, from the modules branch, breaks out function cloning from the method vector updating. We have a new function, build_clones, which does the building, returning a count of the number of clones (2 or 3). clone_function_decl separately adds them to the method vector, if they should be added. I suppose this could have used FOR_EVERY_CLONE, but I went with the counting scheme. * class.c (build_clones): Break out of clone_function_decl. Just build the clones. (clone_function_decl): Call build_clones, then maybe add them to the method vector. From-SVN: r276998
2019-10-15[C++ PATCH] build_clone cleanupNathan Sidwell1-15/+12
https://gcc.gnu.org/ml/gcc-patches/2019-10/msg01069.html build_clone is recursive when applied to a template, but I found the control flow confusing. this makes it clearer and moves some decls to their initializers. * class.c (build_clone): Refactor to clarify recursiveness. From-SVN: r276992
2019-10-09Update the concepts implementation to conform to C++20.Jason Merrill1-0/+3
gcc/c-family/ * c-cppbuiltin.c (c_cpp_builtins): Use new feature test values for concepts when -std=c++2a. Bump __cpp_concepts to 201907. * c.opt: Add -Wconcepts-ts. * c-opts.c (c_common_post_options): Warn when -fconcepts is used with -std=c++2a. Disable warning for -fconcepts in C++20 mode. (set_std_cxx2a): Enable concepts by default. gcc/cp/ * call.c (build_new_function_call): Don't evaluate concepts here. (constraint_failure): Don't record the template. (print_z_candidate): Don't extract the template. * class.c (add_method): When overloading, hide ineligible special member fns. (check_methods): Set TYPE_HAS_COMPLEX_* here. * constexpr.c (cxx_eval_constant_expression): Evaluate concepts. (maybe_initialize_fundef_copies_table): Remove. (get_fundef_copy): Use hash_map_safe_get_or_insert. (clear_cv_and_fold_caches): Clear the satisfaction cache. * constraint.cc (known_non_bool_p): New. (parsing_constraint_expression_sentinel): Renamed from expanding_constraint_sentinel. (check_constraint_operands): New. (check_constraint_atom): New. (finish_constraint_binary_op): New. (finish_constraint_or_expr): Likewise. (finish_constraint_and_expr): Likewise. (finish_constraint_primary_expr): Likewise. (combine_constraint_expressions): New. (finish_requires_expr): Add location parm. (get_concept_definition): Return the initializer of concept definitions. (get_template_head_requirements): New. (get_trailing_function_requirements): New. (deduce_constrained_parameter): Check if the identifier or template-id is a concept definition. (resolve_concept_definition_check): Removed. (resolve_variable_concept_check): Removed. (resolve_concept_check): New. (resolve_constraint_check): Handle concept definitions. converting arguments. (function_concept_check_p): Removed. (variable_concept_check_p): Removed. (unpack_concept_check): New. (get_concept_check_template): New. (build_call_check): Moved and renamed to build_function_check. (build_concept_check_arguments): make static. (build_function_check): Always do overload resolution in order to force conversion of template arguments (i.e., actually check that the use of a concept is valid). (build_standard_check): Renamed from build_real_concept_check. (build_real_concept_check): Build checks for C++2a concepts by (build_wildcard_concept_check): New. (build_concept_check): Use build_real_concept_check. New overload. (build_constraints): Save expressions, not normalized constraints. (build_concept_id): New. Pass tf_warning_or_error. (build_type_constraint): New. (finish_type_constraints): New. (associate_classtype_constraints): Also add constraints to union types. Note the original declaration in errors. Don't return error_mark_node in order to avoid an assertion later. (push_down_pack_expansion): Remove. (finish_shorthand_constraint): Make fold expressions, not naked parameter packs. Always apply the constraint to each template argument. (check_introduction_list): New. Fail if not enough names are introduced. (finish_template_introduction): Don't normalize constraints. Pass tsubst flags. Check for insufficient introductions. (placeholder_extract_concept_and_args): Handle the template-id case. Unpack function concept checks correctly. (tsubst_simple_requirement): Return errors if they occur. Don't process as a template. (tsubst_type_requirement): Likewise. (type_deducible_p): New. Wrap the input expression in parens for the purpose of deduction. (expression_convertible_t): New. (tsubst_compound_requirement): Use new deduction, conversion predicates. (tsubst_nested_requirement): Return errors if they occur. Don't process as a template. Instantiate and evaluate the nested requirement. (tsubst_valid_expression_requirement): New. (tsubst_simple_requirement): Use tsubst_valid_expression_requirement. (tsubst_compound_requirement): Use tsubst_valid_expression_requirement. (check_constaint_variables): New. (tsubst_constraint_variables): Check that type substitutions are valid. (tsubst_requires_expr): Likewise. Produce new requires-exprs during template substitution. Copy the previous local specialization stack, so references to non-local parameters can be found. Use cp_unevaluated. (tsubst_constraint): New. Don't evaluate concept checks. (subst_info): New. (norm_info): New. Used to build a normalization tree for concept check diagnostics. (debug_parameter_mapping): New. (debug_argument_list): New. (expand_concept): Removed. (normalize_logical_operation): Pass subst_info through call. (normalize_pack_expansion): Remove. (normalize_simple_requirement): Removed (normalize_type_requirement): Removed (normalize_compound_requirement): Removed (normalize_nested_requirement): Removed (normalize_requirement): Removed (normalize_requirements): Removed (normalize_requires_expression): Removed (normalize_variable_concept_check): Removed. (normalize_function_concept_check): Removed. (normalize_concept_check): Merged all normalize_*_check here. Substitute through written template arguments before normalizing the definition. Only substitute the innermost template arguments. (check_for_logical_overloads): Delete. (map_arguments): New. Associate template parameters with arguments. (build_parameter_mapping): New. Extract used parameters. (normalize_expression): Rewrite. (normalize_conjunction): Removed (normalize_disjunction): Removed (normalize_predicate_constraint): Removed (normalize_parameterized_constraint): Removed (normalized_map): New variable. (get_normalized_constraints): New entry point for normalization. Establishes a timer. (get_normalized_constraints_from_info): New. (get_normalized_constraints_from_decl): New. Turn on template processing prior to normalization. Handle inheriting ctors. Build the normalization arguments from the full set of template parameters of the most general template. This guarantees that we have no concrete arguments in the parameter mapping (e.g., from template members of class templates). Cache normalizations. (normalize_concept_definition): New. Cache normalizations. (normalize_template_requirements): New. (normalize_nontemplate_requirements): New. (normalize_constraint_expression): New. (tsubst_parameter_mapping): New. (get_mapped_args): New. (parameter_mapping_equivalent_p): New. Use template_args_equal. (atomic_constraints_identical_p): New. (hash_atomic_constraint): New. (satisfying_constraint_p): New. Guard against recursive evaluation of constraints during satisfaction. (satisfy_conjunction): New. (satisfy_disjunction): New. (sat_entry): New class for hashing satisfaction results. (sat_hasher): New hash traits. (sat_cache): New. (get_satisfaction): New. Returns cached satisfaction result. (save_satisfaction): New. Caches a satisfaction result. (clear_satisfaction_cache): New. (satisfaction_cache): New. Helps manage satisfaction cache requests. (decl_satisfied_cache): New. (satisfy_atom): New. (satisfy_constraint_r): New. (satisfy_constraint): Use new satisfaction algorithm. (evaluate_concept_check): New. (evaluate_concept): Removed. (evaluate_function_concept): Removed. (evaluate_variable_concept): Removed. (satisfy_constraint_expression): New. (constraint_expression_satisfied_p): New. (constraints_satisfied_p): Use strip_inheriting_ctors. Use push_/pop_access_scope. (more_constrained): Normalize before calling out to subsumption. Allow classes as arguments. (strictly_subsumes): Allow non-templates as arguments. Accept a new template argument. (weakly_subsumes): New. (at_least_as_constrained): Removed. (diagnose_other_expression): Removed. (diagnose_predicate_constraint): Removed. (diagnose_pack_expansion): Removed. (diagnose_check_constraint): Removed. (diagnose_logical_constraint): Removed. (diagnose_expression_constraint): Removed. (diagnose_type_constraint): Removed. (diagnose_implicit_conversion_constraint): Removed. (diagnose_argument_deduction_constraint): Removed. (diagnose_exception_constraint): Removed. (diagnose_parameterized_constraint): Removed. (diagnose_argument_deduction_constraint): Removed. (diagnose_argument_deduction_constraint): Removed. (diagnose_argument_deduction_constraint): Removed. (diagnose_trait_expr): New. (diagnose_requires_expr): New. (diagnose_atomic_constraint): New. (diagnose_valid_expression) Stop wrongly diagnosing valid expressions. Don't substitute as if in template decls. This causes substitution to generate expressions that aren't suitable for use with the noexcept routines. (diagnose_valid_type) Likewise. (diagnose_compound_requirement) Actually emit diagnostics for the causes of errors.Call force_paren_expr_uneval. (diagnose_declaration_constraints): Turn on template processing to suppress certain analyses. * cp-objcp-common.c (cp_common_init_ts): Make concepts typed. (cp_get_debug_type): Use hash_map_safe_*. * cp-tree.h: New function declarations for semantic actions, other facilities. Remove declaration no longer used or needed. Remove unused _CONSTR macros. (LANG_DECL_HAS_MIN): Add CONCEPT_DECL. (template_info_decl_check): Factor macro check into an inline function. (DECL_TEMPLATE_INFO): Use new check facility. (finish_concept_definition): New. Don't invalid concept declarations with invalid initializers. (find_template_parameters): New. (concept_definition_p): New. (concept_check_p): New. (variable_concept_check_p): New. (force_paren_expr_uneval): New. (ovl_iterator::using_p): A USING_DECL by itself was also introduced by a using-declaration. (struct tree_template_info): Use tree_base instead of tree_common. Add tmpl and args fields. (TI_TEMPLATE, TI_ARGS): Adjust. (DECLTYPE_FOR_INIT_CAPTURE): Remove. (CONSTR_CHECK, CONSTR_INFO, CONSTR_EXPR, CONSTR_CONTEXT): New. (ATOMIC_CONSTR_MAP, TRAIT_EXPR_LOCATION): New. (struct tree_trait_expr): Add locus field. (enum tsubst_flags): Add tf_norm as a hint to generate normalization context when diagnosing constraint failure. * cp-tree.def: Remove unused _CONSTR nodes and rename PRED_CONSTR to ATOMIC_CONSTR. (CONCEPT_DECL): New. * cxx-pretty-print.c: Remove constraint printing code. (pp_cxx_concept_definition): New. (pp_cxx_template_declaration): Print concept definitions. (pp_cxx_check_constraint): Update printing for concept definitions. (pp_cxx_nested_name_specifier): Fix a weird case where we're printing '::::' for concepts. (simple_type_specifier): Print requirements for placeholder types. (pp_cxx_constrained_type_spec): Print the associated requirements of a placeholder type. (pp_cxx_compound_requirement): Add space before the '->'. (pp_cxx_parameter_mapping): Print the parameter mapping. (pp_cxx_atomic_constraint): Use the function above. * decl.c (redeclaration_error_message): New error for concepts. (grokdeclarator): Check for and disallow decltype(auto) in parameter declarations. (grokfndecl): Don't normalize constraints. Add check for constraints on declaration. (grokvardecl): Don't normalize constraints. (grok_special_member_properties): Don't set TYPE_HAS_COMPLEX_*. (function_requirements_equivalent_p): New. Compare trailing requires clauses. Compare combined constraints in pre-C++20 mode. (decls_match): Compare trailing requires clauses. Compare template heads for function templates. Remove old constraint comparison. Simplify comparison of functions, function templates. (duplicate_function_template_decls): New. Refactor a nasty if condition into a single predicate. (require_deduced_type): Don't complain if we already complained about deduction failure. (finish_function): Perform auto deduction to ensure that constraints are checked even when functions contain no return statements. Only do auto deduction if we haven't previously seen any return statements. This prevents multiple diagnostics of the same error. (store_decomp_type): Remove. (cp_finish_decomp): Use hash_map_safe_put. * error.c: Remove constraint printing code. (dump_decl): Dump concept definitions. Handle wildcard declarations. (dump_template_decl): Likewise. (dump_type): Print associated requirements for placeholder types. (rebuild_concept_check): New. (maybe_print_single_constraint_context): New. (maybe_print_constraint_context): Recursively print nested contexts. * init.c (get_nsdmi): Use hash_map_safe_*. * lambda.c (maybe_add_lambda_conv_op): Bail if deduction failed. (add_capture): Copy parameter packs from init. (lambda_capture_field_type): Always use auto for init-capture. * logic.cc: Completely rewrite. (constraint_hash): New. (clause/ctor): Save atoms in the hash table. (replace): Save atoms during replacement. (insert): Save atoms during insertion. (contains): Only search the hash table for containment. (clause): Keep a hash of atomic constraints. (clause::clause): Explicitly copy the hash table when copying. (disjunction_p, conjunction_p, atomic_p, dnf_size, cnf_size): New. (diagnose_constraint_size): New. (subsumes_constraints_nonnull): Compare the sizes of normalized formula to determine the cheapest decomposition. * name-lookup.c (diagnose_name_conflict): Diagnose name issues with concepts. (matching_fn_p): Check constraints. (push_class_level_binding_1): Move overloaded functions case down, accept FUNCTION_DECL as target_decl. * parser.c (enum required_token): New required token for auto. (make_location): Add overload taking lexer as last parm. (cp_parser_required_error): Diagnose missing auto. (cp_parser_diagnose_ungrouped_constraint_plain): New. (cp_parser_diagnose_ungrouped_constraint_plain): New. (cp_parser_constraint_primary_expression): New. Tentatively parse the primary expression. If that fails tentatively parse a lower precedence expression in order to diagnose the error. (cp_parser_check_non_logical_constraint): New. Performs a trial parse of the right-hand-side of non-logical operators in order to generate good diagnostics. (cp_parser_constraint_logical_and_expression): New. (cp_parser_constraint_logical_or_expression): New. (cp_parser_requires_clause_expression): New. (cp_parser_requires_clause): Renamed to cp_parser_constraint_expression. (cp_parser_requires_clause_opt): Parse the requires-clause differently in -fconcepts and -std=c++2a modes. (cp_parser_requirement_list): Rename to cp_parser_requirement_seq. Rewrite so that semicolons are parsed along with requirements, not the sequence. (cp_parser_simple_requirement): Expect a semicolon at end. (cp_parser_compound_requirement): Expect a semicolon at end. Only allow trailing-return-type with -fconcepts-ts. (cp_parser_nested_requirement): Expect a semicolon at end. Parse constraint-expressions. (cp_parser_concept_definition): New. Don't fail parsing the concept definition if the initializer is ill-formed. Don't declare the concept before parsing the initializer. (cp_parser_constraint_expression): Declare earlier. (cp_parser_type_requirement): Current scope is not valid. (cp_parser_requires_expression): Commit to the tentative parse. (cp_parser_decl_specifier_seq): Warn when concept appears to be used as a decl-specifier. (cp_parser_template_declaration_after_parameters): Parse concept definitions. (cp_parser_template_id): Don't try to resolve a concept template-id yet. (cp_parser_template_id_expr): Resolve it as a concept check. (cp_parser_decl_specifier_seq): Warn on 'concept bool'. (cp_parser_type_parameter): Combine expressions not constraints. (cp_parser_explicit_template_declaration): Combine expressions not constraints. (cp_parser_maybe_concept_name): Removed. (cp_parser_simple_type_specifier): Handle an error condition of a bad constrained type specifier. Expect auto or decltype after a concept name. Also handle the case where we have a template-id as a concept check. (cp_parser_template_introduction): Diagnose errors on invalid introductions. Give up if it doesn't start with a concept name. Pedwarn if not -fconcepts-ts. (synthesize_implicit_template_parm): Don't do consistent binding. Use a new flag for constrained parameters. Combine expressions, not constraints. Fail if we get a placeholder in block scope. Placeholders that do not constrain types are not allowed in parameter declarations, so don't handle them. (cp_parser_placeholder_type_specifier): New. Implement parsing of placeholder type specifiers following a concept name or partial concept check. Disallow decltype(auto) parameters. (cp_parser_nested_name_specifier_opt): If the token is already CPP_NESTED_NAME_SPECIFIER, leave it alone. (cp_parser_id_expression, cp_parser_unqualified_id): Call cp_parser_template_id_expr. (cp_parser_placeholder_type_specifier): Add tentative parm. Don't expect a WILDCARD_DECL. (cp_parser_trait_expr): Pass trait_loc down. (cp_parser_postfix_expression): Do set location of dependent member call. * pt.c (finish_concept_definition): New. (push_template_decl_real): Handle concept definitions. (start_concept_definition): Let push_template_decl_real handle the creation of the template. (get_constraints): Return null if the table hasn't been initialized. (tsubst_copy_and_build): Build template-id expressions for concept checks. [TRAIT_EXPR]: Pass trait_loc down. (lookup_template_class_1): Add the template name to the constraint failure diagnostic. (lookup_and_finish_template_variable): Build concept checks with the correct arguments. (tsubst_function_decl): Don't substitute through constraints. Always associate constraints with functions. (template_parm_level_and_index): Make non-static. (for_each_template_parm_r): Handle requires expressions. (keep_template_parm): New. (find_template_parameters): New. (more_specialized_fn): Change how winners and losers are chosen. (make_constrained_auto): Don't normalize constraints. (template_parameters_equivalent_p): New. Compare template parameters. Add a comparison for implicitly vs. explicitly declared parameters. (template_parameter_lists_equivalent_p): New. Compare template parameter lists. (template_requirements_equivalent_p): New. (template_heads_equivalent_p): New. Compare template heads. (template_parameter_constraints_equivalent_p): New. (is_compatible_template_arg): Use weakly_subsumes. (maybe_new_partial_specialization): Use new constraint comparison for finding specializations. (process_partial_specialization): Pass main template as argument. (more_specialized_partial_spec): Don't immediately return when detecting a winner. (make_constrained_auto): Handle concept definitions. (do_auto_deduction): Update auto deduction for new concept model. Extract the function concept correctly; rename constr to check to reflect the kind of node. (tsubst): Adjust wildcard argument during substitution. [DECLTYPE_TYPE]: Remove init-capture handling. (tsubst_copy_and_build): Build concept checks, not template ids. Defer checks of function concepts. Handle concepts before variable templates. Handle calls to function concepts explicitly. (coerce_template_parms): Use concept_definition_p. Handle a deduction error where a potentially empty pack can be supplied after the last parameter of a concept. (finish_template_variable): Don't process concepts here. (instantiation_dependent_r): Use concept_check_p. (tsubst_template_args): Make non-static. (make_constrained_placeholder_type): New. Refactored from make_constrained_auto. (make_constrained_auto) Use make_constrained_placeholder_type. (make_constrained_decltype_auto) New. (tsubst_function_parms): New. (value_dependent_expression_p) [TEMPLATE_ID_EXPR]: Use concept_definition_p. (push_access_scope, pop_access_scope): No longer static. (tsubst_template_parm): Substitute TEMPLATE_PARM_CONSTRAINTS. (tsubst_friend_function): Use tsubst_constraint. Use generic_targs_for. (get_underlying_template) Use generic_targs_for. (uses_parameter_packs): Return tree. (gen_elem_of_pack_expansion_instantiation): Don't push local_specialization_stack. (prepend_one_capture): New. (tsubst_lambda_expr): Use prepend_one_capture. Don't touch local_specializations. (template_parms_level_to_args): No longer static. (add_outermost_template_args): Likewise. (find_template_parameter_info): New. Provide context for finding template parameters. (keep_template_parm): Don't keep parameters declared at depth levels greater than those of the template parameters of the source declaration. Don't propagate cv-qualified types. Return 0, so we find all template parameters, not the just first. (any_template_parm_r): New. Handle cases that are mishandled by for_each_template_parm_r. (generic_targs_for): Factor out of coerce_template_args_for_ttp. (tsubst_argument_pack): Factor out of tsubst_template_args. (constraint_sat_entry): Removed. (constraint_sat_hasher): Removed. (concept_spec_entry): Removed. (concept_spec_hasher): Removed. (constraint_memos): Removed. (concept_memos): Removed. (lookup_constraint_satisfaction): Removed. (memoize_constraint_satisfaction): Removed. (lookup_concept_satisfaction): Removed. (memoize_concept_satisfaction): Removed. (concept_expansions): Removed. (get_concept_expansion): Removed. (save_concept_expansion): Removed. (init_constraint_processing): Remove initialization of non-existing resources. (find_template_requirement): New. Search for the sub-requirement within the associated constraints. (convert_generic_types_to_packs): Also transform the associated constraint and update the current template requirements. (store_defaulted_ttp, lookup_defaulted_ttp): Remove. (add_defaults_to_ttp): Use hash_map_safe_*. * semantics.c (finish_call_expr): Diagnose calls to concepts. Handle concept checks explicitly. (finish_id_expression): Evaluate variable concepts as part of id-expression processing. Don't treat variable concepts as variables, and don't process function concepts as plain id-expressions. (force_paren_expr): Add even_uneval parm. (finish_trait_expr): Add location parm. * tree.c (special_memfn_p): New. (cp_expr_location): Handle TRAIT_EXPR. * typeck.c (check_return_expr): Actually use the diagnostic kind when performing return-type deduction. * typeck2.c (build_functional_cast): Don't rely on the location of 'auto'. gcc/testsuite/ * lib/target-supports.exp (check_effective_target_concepts): Check for std=c++2a. gcc/ * doc/invoke.texi: Document -fconcepts-ts. From-SVN: r276764
2019-10-05PR c++/91369 - Implement P0784R7: constexpr newJakub Jelinek1-4/+40
PR c++/91369 - Implement P0784R7: constexpr new c-family/ * c-cppbuiltin.c (c_cpp_builtins): Predefine __cpp_constexpr_dynamic_alloc=201907 for -std=c++2a. cp/ * cp-tree.h (enum cp_tree_index): Add CPTI_HEAP_UNINIT_IDENTIFIER, CPTI_HEAP_IDENTIFIER and CPTI_HEAP_DELETED_IDENTIFIER. (heap_uninit_identifier, heap_identifier, heap_deleted_identifier): Define. (type_has_constexpr_destructor, build_new_constexpr_heap_type, cxx_constant_dtor): Declare. * class.c (type_maybe_constexpr_default_constructor): Make static. (type_maybe_constexpr_destructor, type_has_constexpr_destructor): New functions. (finalize_literal_type_property): For c++2a, don't clear CLASSTYPE_LITERAL_P for types without trivial destructors unless they have non-constexpr destructors. (explain_non_literal_class): For c++2a, complain about non-constexpr destructors rather than about non-trivial destructors. * constexpr.c: Include stor-layout.h. (struct constexpr_global_ctx): New type. (struct constexpr_ctx): Add global field, remove values and constexpr_ops_count. (cxx_replaceable_global_alloc_fn): New inline function. (cxx_eval_call_expression): For c++2a allow calls to replaceable global allocation functions, for new return address of a heap uninit var, for delete record its deletion. Change ctx->values->{get,put} to ctx->global->values.{get,put}. (non_const_var_error): Add auto_diagnostic_group sentinel. Emit special diagnostics for heap variables. (cxx_eval_store_expression): Change ctx->values->{get,put} to ctx->global->values.{get,put}. (cxx_eval_loop_expr): Initialize jump_target if NULL. Change new_ctx.values->remove to ctx->global->values.remove. (cxx_eval_constant_expression): Change *ctx->constexpr_ops_count to ctx->global->constexpr_ops_count. Change ctx->values->{get,put} to ctx->global->values.{get,put}. <case NOP_EXPR>: Formatting fix. On cast of replaceable global allocation function to some pointer type, adjust the type of the heap variable and change name from heap_uninit_identifier to heap_identifier. (find_heap_var_refs): New function. (cxx_eval_outermost_constant_expr): Add constexpr_dtor argument, handle evaluation of constexpr dtors and add tracking of heap variables. Use tf_no_cleanup for get_target_expr_with_sfinae. (cxx_constant_value): Adjust cxx_eval_outermost_constant_expr caller. (cxx_constant_dtor): New function. (maybe_constant_value, fold_non_dependent_expr_template, maybe_constant_init_1): Adjust cxx_eval_outermost_constant_expr callers. (potential_constant_expression_1): Ignore clobbers. Allow COND_EXPR_IS_VEC_DELETE for c++2a. * decl.c (initialize_predefined_identifiers): Add heap identifiers. (decl_maybe_constant_destruction): New function. (cp_finish_decl): Don't clear TREE_READONLY for constexpr variables with non-trivial, but constexpr destructors. (register_dtor_fn): For constexpr variables with constexpr non-trivial destructors call cxx_maybe_build_cleanup instead of adding destructor calls at runtime. (expand_static_init): For constexpr variables with constexpr non-trivial destructors call cxx_maybe_build_cleanup. (grokdeclarator): Allow constexpr destructors for c++2a. Formatting fix. (cxx_maybe_build_cleanup): For constexpr variables with constexpr non-trivial destructors call cxx_constant_dtor instead of adding destructor calls at runtime. * init.c: Include stor-layout.h. (build_new_constexpr_heap_type, maybe_wrap_new_for_constexpr): New functions. (build_new_1): For c++2a and new[], add cast around the alloc call to help constexpr evaluation figure out the type of the heap storage. (build_vec_delete_1): Set DECL_INITIAL of tbase and emit a DECL_EXPR for it instead of initializing an uninitialized variable. * method.c: Include intl.h. (SFK_CTOR_P, SFK_DTOR_P, SFK_ASSIGN_P, SFK_COPY_P, SFK_MOVE_P): Move definitions earlier. (process_subob_fn): Add sfk argument, adjust non-constexpr call diagnostics based on it. (walk_field_subobs): Formatting fixes. Adjust process_subob_fn caller. (synthesized_method_base_walk): Likewise. (synthesized_method_walk): Set *constexpr_p to true for dtors in c++2a. Fix up DR number in comment. (implicitly_declare_fn): Formatting fix. * typeck2.c (store_init_value): Don't call cp_fully_fold_init on initializers of automatic non-constexpr variables in constexpr functions. testsuite/ * g++.dg/cpp0x/constexpr-delete2.C: Adjust expected diagnostics for c++2a. * g++.dg/cpp0x/locations1.C: Only expect constexpr ~S() diagnostics in c++17_down, adjust expected wording. * g++.dg/cpp1y/constexpr-new.C: Only expect diagnostics in c++17_down. * g++.dg/cpp2a/constexpr-dtor1.C: New test. * g++.dg/cpp2a/constexpr-dtor2.C: New test. * g++.dg/cpp2a/constexpr-dtor3.C: New test. * g++.dg/cpp2a/constexpr-new1.C: New test. * g++.dg/cpp2a/constexpr-new2.C: New test. * g++.dg/cpp2a/constexpr-new3.C: New test. * g++.dg/cpp2a/constexpr-new4.C: New test. * g++.dg/cpp2a/feat-cxx2a.C: Add __cpp_constinit and __cpp_constexpr_dynamic_alloc tests. Tweak __cpp_* tests for c++2a features to use style like older features, including #ifdef test. * g++.dg/ext/is_literal_type3.C: New test. From-SVN: r276622
2019-09-28PR c++/91921 - stray warning with -Woverloaded-virtual.Marek Polacek1-5/+5
* class.c (warn_hidden): Only emit the second part of -Woverloaded-virtual if the first part was issued. Use inform instead warning_at. * g++.dg/warn/Woverloaded-2.C: New. * g++.dg/warn/Woverloaded-2.h: New. * g++.dg/warn/pr61945.C: Turn dg-warning into dg-message. * g++.old-deja/g++.mike/warn6.C: Likewise. * g++.old-deja/g++.warn/virt1.C: Likewise. From-SVN: r276249