aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/cp-tree.h
AgeCommit message (Collapse)AuthorFilesLines
2020-01-13 PR c++/92582 - ICE with member template as requirement.Jason Merrill1-1/+1
Here, we weren't recognizing that the template parameter of A is used by the reference to d in the requires-clause of f. Fixed by passing down the active template parameters in the context of normalization, and adding to the mapping any such parameters shared by a member template used in the constraint-expression. * pt.c (struct find_template_parameter_info): Add ctx_parms. (any_template_parm_r): Handle TEMPLATE_DECL. (find_template_parameters): Take parms instead of their depth. * constraint.cc (build_parameter_mapping): Pass them.
2020-01-13PR c++/33799 - destroy return value if local cleanup throws.Jason Merrill1-0/+7
This is a pretty rare situation since the C++11 change to make all destructors default to noexcept, but it is still possible to define throwing destructors, and if a destructor for a local variable throws during the return, we've already constructed the return value, so now we need to destroy it. I handled this somewhat like the new-expression cleanup; as in that case, this cleanup can't properly nest with the cleanups for local variables, so I introduce a cleanup region around the whole function and a flag variable to indicate whether the return value actually needs to be destroyed. Setting the flag requires giving a COMPOUND_EXPR as the operand of a RETURN_EXPR, so I adjust gimplify_return_expr to handle that. This doesn't currently work with deduced return type because we don't know the type when we're deciding whether to introduce the cleanup region. gcc/ * gimplify.c (gimplify_return_expr): Handle COMPOUND_EXPR. gcc/cp/ * cp-tree.h (current_retval_sentinel): New macro. * decl.c (start_preparsed_function): Set up cleanup for retval. * typeck.c (check_return_expr): Set current_retval_sentinel.
2020-01-07init.c (build_new): Add location_t parameter and use it throughout.Paolo Carlini1-3/+4
/gcc/cp 2020-01-07 Paolo Carlini <paolo.carlini@oracle.com> * init.c (build_new): Add location_t parameter and use it throughout. (build_raw_new_expr): Likewise. * parser.c (cp_parser_new_expression): Pass the combined_loc. * pt.c (tsubst_copy_and_build): Adjust call. * cp-tree.h: Update declarations. /libcc1 2020-01-07 Paolo Carlini <paolo.carlini@oracle.com> * libcp1plugin.cc (plugin_build_new_expr): Update build_new call. /gcc/testsuite 2020-01-07 Paolo Carlini <paolo.carlini@oracle.com> * g++.old-deja/g++.bugs/900208_03.C: Check locations too. * g++.old-deja/g++.bugs/900519_06.C: Likewise. From-SVN: r279963
2020-01-01Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r279813
2019-12-30decl2.c (delete_sanity): Add location_t parameter and use it throughout.Paolo Carlini1-3/+4
/gcc/cp 2019-12-30 Paolo Carlini <paolo.carlini@oracle.com> * decl2.c (delete_sanity): Add location_t parameter and use it throughout. * init.c (build_vec_delete_1): Likewise. (build_delete): Likewise. (build_vec_delete): Likewise. (perform_target_ctor): Adjust call. (perform_member_init): Likewise. (build_vec_init): Likewise. * decl.c (cxx_maybe_build_cleanup): Likewise. * pt.c (tsubst_copy_and_build): Likewise. * parser.c (cp_parser_delete_expression): Likewise, pass the combined_loc. * cp-tree.h: Update declarations. /libcc1 2019-12-30 Paolo Carlini <paolo.carlini@oracle.com> * libcp1plugin.cc (plugin_build_unary_expr): Update delete_sanity call. /gcc/testsuite 2019-12-30 Paolo Carlini <paolo.carlini@oracle.com> * g++.dg/init/delete1.C: Check locations too. * g++.dg/ipa/pr85607.C: Likewise. * g++.dg/warn/Wdelete-incomplete-1.C: Likewise. * g++.dg/warn/delete-non-virtual-dtor.C: Likewise. * g++.dg/warn/incomplete1.C: Likewise. From-SVN: r279768
2019-12-19PR c++/66139 - EH cleanups for partially constructed aggregates.Jason Merrill1-0/+1
There were several overlapping PRs about failure to clean up fully constructed subobjects when an exception is thrown during aggregate initialization of a temporary. I fixed this for non-temporaries in the context of 57510, but that fix didn't handle temporaries. So this patch does split_nonconstant_init at gimplification time, which is much smaller than alternatives I tried. PR c++/57510 * cp-gimplify.c (cp_gimplify_init_expr): Use split_nonconstant_init. * typeck2.c (split_nonconstant_init): Handle non-variable dest. (split_nonconstant_init_1): Clear TREE_SIDE_EFFECTS. * tree.c (is_local_temp): New. From-SVN: r279576
2019-12-18typeck.c (cxx_sizeof_or_alignof_type): Add location_t parameter and use it ↵Paolo Carlini1-5/+6
throughout. /gcc/cp 2019-12-18 Paolo Carlini <paolo.carlini@oracle.com> * typeck.c (cxx_sizeof_or_alignof_type): Add location_t parameter and use it throughout. (cxx_sizeof_expr): Likewise. (cxx_alignof_expr): Likewise. (cxx_sizeof_or_alignof_expr): Likewise. (cxx_alignas_expr): Update call. * decl.c (fold_sizeof_expr): Likewise. * pt.c (tsubst_copy): Likewise. (tsubst_copy_and_build): Likewise. * except.c (build_throw): Add location_t parameter and use it. (expand_end_catch_block): Update call. * parser.c (cp_parser_unary_expression): Update cxx_sizeof_or_alignof_type and cxx_sizeof_or_alignof_expr calls, pass the compound location. (cp_parser_throw_expression): Likewise pass the combined location to build_throw. * cp-tree.h: Update declarations. * semantics.c (finish_handler_parms): Use DECL_SOURCE_LOCATION. * decl2.c (check_classfn): Likewise. * except.c (is_admissible_throw_operand_or_catch_parameter): Exploit cp_expr_loc_or_input_loc in one place. * except.c (create_try_catch_expr): Remove, unused. /libcc1 2019-12-18 Paolo Carlini <paolo.carlini@oracle.com> * libcp1plugin.cc (plugin_build_unary_expr): Update build_throw and cxx_sizeof_or_alignof_expr calls. (plugin_build_unary_type_expr): Likewise for cxx_sizeof_or_alignof_type. /gcc/testsuite 2019-12-18 Paolo Carlini <paolo.carlini@oracle.com> * g++.dg/diagnostic/alignof2.C: New. * g++.dg/diagnostic/alignof3.C: Likewise. * g++.dg/diagnostic/incomplete-type-1.C: Likewise. * g++.dg/warn/Wcatch-value-3b.C: Likewise. * g++.dg/cpp0x/alignof3.C: Check location(s) too. * g++.dg/cpp1z/decomp-bitfield1.C: Likewise. * g++.dg/cpp1z/has-unique-obj-representations2.C: Likewise. * g++.dg/expr/sizeof3.C: Likewise. * g++.dg/ext/flexary6.C: Likewise. * g++.dg/ext/vla4.C: Likewise. * g++.dg/template/sizeof11.C: Likewise. * g++.dg/warn/Wcatch-value-1.C: Likewise. * g++.dg/warn/Wcatch-value-2.C: Likewise. * g++.dg/warn/Wcatch-value-3.C: Likewise. * g++.old-deja/g++.brendan/sizeof1.C: Likewise. * g++.old-deja/g++.brendan/sizeof3.C: Likewise. * g++.old-deja/g++.brendan/sizeof4.C: Likewise. * g++.old-deja/g++.eh/ctor1.C: Likewise. * g++.old-deja/g++.jason/ambig1.C: Likewise. * g++.old-deja/g++.other/sizeof4.C: Likewise. From-SVN: r279543
2019-12-18PR c++/12333 - X::~X() with implicit this->.Jason Merrill1-0/+1
this->X::~X() is handled by finish_class_member_access_expr and its lookup_destructor subroutine; let's use it in cp_parser_lookup_name for the case where this-> is implicit. I tried replacing the other destructor code here with just the call to lookup_destructor, but that regressed handling of naming the destructor outside a non-static member function. * parser.c (cp_parser_lookup_name): Use lookup_destructor. * typeck.c (lookup_destructor): No longer static. From-SVN: r279522
2019-12-09typeck.c (check_for_casting_away_constness): Add location_t parameter and ↵Paolo Carlini1-6/+12
use it. gcc/cp 2019-12-09 Paolo Carlini <paolo.carlini@oracle.com> * typeck.c (check_for_casting_away_constness): Add location_t parameter and use it. (maybe_warn_about_useless_cast): Likewise. (maybe_warn_about_cast_ignoring_quals): Likewise. (build_static_cast_1): Likewise. (build_static_cast): Likewise; sets the location of the returned tree. (build_reinterpret_cast_1): Likewise. (build_reinterpret_cast): Likewise; sets the location of the returned tree. (build_const_cast_1): Likewise. (build_const_cast): Likewise; sets the location of the returned tree. (cp_build_c_cast): Likewise. (build_c_cast): Adjust. (build_ptrmemfunc): Adjust calls. (cp_build_unary_op): Pass the location to invert_truthvalue_loc. * rtti.c (build_dynamic_cast_1): Add location_t parameter and use it. (build_dynamic_cast): Likewise. * cp-tree.h: Adjust declarations. * parser.c (cp_parser_postfix_expression): Pass cp_cast_loc to the various build_*_cast functions. (get_cast_suggestion): Adjust calls. (cp_parser_builtin_offsetof): Likewise. * decl.c (reshape_init): Adjust call. * method.c (forward_parm): Likewise. (build_comparison_op): Likewise. * pt.c (tsubst_copy_and_build): Likewise. * semantics.c (finish_omp_reduction_clause): Likewise. (cp_omp_finish_iterators): Likewise. * tree.c (cp_stabilize_reference): Likewise. (move): Likewise. * typeck2.c (build_functional_cast): Likewise. * typeck2.c (build_functional_cast_1): New. (build_functional_cast_1): Calls the latter and sets the location of the returned tree. /libcc1 2019-12-09 Paolo Carlini <paolo.carlini@oracle.com> * libcp1plugin.cc (plugin_build_cast_expr): Adjust build_cast declaration. gcc/testsuite 2019-12-09 Paolo Carlini <paolo.carlini@oracle.com> * c-c++-common/Wcast-align.c: Check location(s) too. * c-c++-common/Wcast-function-type.c: Likewise. * c-c++-common/Wint-to-pointer-cast-1.c: Likewise. * c-c++-common/Wint-to-pointer-cast-2.c: Likewise. * c-c++-common/Wint-to-pointer-cast-3.c: Likewise. * g++.dg/Wcast-function-type.C: Likewise. * g++.dg/addr_builtin-1.C: Likewise. * g++.dg/conversion/const2.C: Likewise. * g++.dg/conversion/dynamic1.C: Likewise. * g++.dg/conversion/ptrmem2.C: Likewise. * g++.dg/conversion/ptrmem3.C: Likewise. * g++.dg/conversion/qual3.C: Likewise. * g++.dg/conversion/reinterpret3.C: Likewise. * g++.dg/cpp0x/constexpr-cast.C: Likewise. * g++.dg/cpp0x/lambda/lambda-conv11.C: Likewise. * g++.dg/cpp0x/nullptr04.C: Likewise. * g++.dg/cpp0x/reinterpret_cast2.C: Likewise. * g++.dg/cpp0x/rv-cast2.C: Likewise. * g++.dg/cpp1y/lambda-conv1.C: Likewise. * g++.dg/cpp1z/noexcept-type7.C: Likewise. * g++.dg/cpp2a/array-conv9.C: Likewise. * g++.dg/expr/cast11.C: Likewise. * g++.dg/expr/static_cast8.C: Likewise. * g++.dg/ext/vector6.C: Likewise. * g++.dg/other/conversion1.C: Likewise. * g++.dg/parse/pr26997.C: Likewise. * g++.dg/rtti/no-rtti.C: Likewise. * g++.dg/tc1/dr137.C: Likewise. * g++.dg/template/cast4.C: Likewise. * g++.dg/warn/Wcast-qual1.C: Likewise. * g++.dg/warn/Wcast-qual2.C: Likewise. * g++.dg/warn/Wconditionally-supported-1.C: Likewise. * g++.dg/warn/Wuseless-cast.C: Likewise. * g++.dg/warn/pr35711.C: Likewise. * g++.old-deja/g++.bugs/900227_01.C: Likewise. * g++.old-deja/g++.bugs/900404_07.C: Likewise. * g++.old-deja/g++.jason/overload1.C: Likewise. * g++.old-deja/g++.jason/rfg26.C: Likewise. * g++.old-deja/g++.jason/rvalue3.C: Likewise. * g++.old-deja/g++.jason/warning2.C: Likewise. * g++.old-deja/g++.mike/dyncast4.C: Likewise. * g++.old-deja/g++.mike/dyncast6.C: Likewise. * g++.old-deja/g++.mike/p11482.C: Likewise. * g++.old-deja/g++.mike/p2573.C: Likewise. * g++.old-deja/g++.mike/p2855.C: Likewise. * g++.old-deja/g++.mike/p7476.C: Likewise. * g++.old-deja/g++.mike/p8039.C: Likewise. * g++.old-deja/g++.other/cast2.C: Likewise. * g++.old-deja/g++.other/cast3.C: Likewise. * g++.old-deja/g++.other/dcast1.C: Likewise. * g++.old-deja/g++.other/dcast2.C: Likewise. From-SVN: r279138
2019-12-06PR c++/92831 - CWG 1299, not extending temporary lifetime for ?:Jakub Jelinek1-1/+3
* cp-tree.h (extend_ref_init_temps): Add a new argument with NULL default arg. * call.c (set_up_extended_ref_temp): Add COND_GUARD argument, pass it down to extend_ref_init_temps. Before pushing cleanup, if COND_GUARD is non-NULL, create a bool temporary if needed, initialize to false and guard the cleanup with the temporary being true. (extend_ref_init_temps_1): Add COND_GUARD argument, pass it down to recursive calls and set_up_extended_ref_temp. Handle COND_EXPR. (extend_ref_init_temps): Add COND_GUARD argument, pass it down to recursive calls and to extend_ref_init_temps_1. * g++.dg/cpp0x/temp-extend2.C: New test. From-SVN: r279064
2019-12-05typeck2.c (build_functional_cast): Add location_t parameter and use it.Paolo Carlini1-1/+2
/gcc/cp 2019-12-05 Paolo Carlini <paolo.carlini@oracle.com> * typeck2.c (build_functional_cast): Add location_t parameter and use it. * cp-tree.h: Update declaration. * parser.c (cp_parser_functional_cast): Adjust call. * call.c (build_op_delete_call): Likewise. (build_new_method_call_1): Likewise. * decl.c (check_initializer): Likewise. * pt.c (tsubst_copy_and_build): Likewise. * semantics.c (finish_compound_literal): Likewise. /libcc1 2019-12-05 Paolo Carlini <paolo.carlini@oracle.com> * libcp1plugin.cc (plugin_build_expression_list_expr): Adjust build_functional_cast call. /testsuite 2019-12-05 Paolo Carlini <paolo.carlini@oracle.com> * g++.dg/diagnostic/functional-cast-to-array-type-1.C: New. * g++.dg/cpp0x/auto25.C: Check location(s) too. * g++.dg/cpp0x/auto28.C: Likewise. * g++.dg/init/reference2.C: Likewise. * g++.dg/parse/template2.C: Likewise. * g++.dg/template/error8.C: Likewise. * g++.old-deja/g++.ns/crash3.C: Likewise. * g++.old-deja/g++.ns/template7.C: Likewise. * g++.old-deja/g++.pt/crash8.C: Likewise. From-SVN: r278987
2019-12-04[C++] Opt out of GNU vector extensions for built-in SVE typesRichard Sandiford1-1/+1
This is the C++ equivalent of r277950. The changes are very similar to there. Perhaps the only noteworthy thing (that I know of) is that the patch continues to treat !gnu_vector_type_p vector types as literal types/potential constexprs. Disabling the GNU vector extensions shouldn't in itself stop the types from being literal types, since whatever the target provides instead might be constexpr material. 2019-12-04 Richard Sandiford <richard.sandiford@arm.com> gcc/cp/ * cp-tree.h (CP_AGGREGATE_TYPE_P): Check for gnu_vector_type_p instead of VECTOR_TYPE. * call.c (build_conditional_expr_1): Restrict vector handling to vectors that satisfy gnu_vector_type_p. * cvt.c (ocp_convert): Only allow vectors to be converted to bool if they satisfy gnu_vector_type_p. (build_expr_type_conversion): Only allow conversions from vectors if they satisfy gnu_vector_type_p. * typeck.c (cp_build_binary_op): Only allow binary operators to be applied to vectors if they satisfy gnu_vector_type_p. (cp_build_unary_op): Likewise unary operators. (build_reinterpret_cast_1): gcc/testsuite/ * g++.target/aarch64/sve/acle/general-c++/gnu_vectors_1.C: New test. * g++.target/aarch64/sve/acle/general-c++/gnu_vectors_2.C: New test. From-SVN: r278957
2019-12-04cp-tree.h (enum cp_tree_index): Add CPTI_SOURCE_LOCATION_IMPL.Jakub Jelinek1-0/+7
* cp-tree.h (enum cp_tree_index): Add CPTI_SOURCE_LOCATION_IMPL. (source_location_impl): Define. (enum cp_built_in_function): Add CP_BUILT_IN_SOURCE_LOCATION. (fold_builtin_source_location): Declare. * cp-gimplify.c: Include output.h, file-prefix-map.h and cgraph.h. (cp_gimplify_expr, cp_fold): Handle CP_BUILT_IN_SOURCE_LOCATION. Formatting fix. (get_source_location_impl_type): New function. (struct source_location_table_entry, struct source_location_table_entry_hash): New types. (source_location_table, source_location_id): New variables. (fold_builtin_source_location): New function. * constexpr.c (cxx_eval_builtin_function_call): Handle CP_BUILT_IN_SOURCE_LOCATION. * tree.c (builtin_valid_in_constant_expr_p): Likewise. Formatting fix. * decl.c (cxx_init_decl_processing): Register __builtin_source_location. * name-lookup.c (get_std_name_hint): Add source_location entry. * g++.dg/cpp2a/srcloc1.C: New test. * g++.dg/cpp2a/srcloc2.C: New test. * g++.dg/cpp2a/srcloc3.C: New test. * g++.dg/cpp2a/srcloc4.C: New test. * g++.dg/cpp2a/srcloc5.C: New test. * g++.dg/cpp2a/srcloc6.C: New test. * g++.dg/cpp2a/srcloc7.C: New test. * g++.dg/cpp2a/srcloc8.C: New test. * g++.dg/cpp2a/srcloc9.C: New test. * g++.dg/cpp2a/srcloc10.C: New test. * g++.dg/cpp2a/srcloc11.C: New test. * g++.dg/cpp2a/srcloc12.C: New test. * g++.dg/cpp2a/srcloc13.C: New test. * g++.dg/cpp2a/srcloc14.C: New test. From-SVN: r278949
2019-12-03PR c++/91363 - P0960R3: Parenthesized initialization of aggregates.Marek Polacek1-0/+7
This patch implements C++20 P0960R3: Parenthesized initialization of aggregates (<wg21.link/p0960>; see R0 for more background info). Essentially, if you have an aggregate, you can now initialize it by (x, y), similarly to {x, y}. E.g. struct A { int x, y; // no A(int, int) ctor (see paren-init14.C for = delete; case) }; A a(1, 2); The difference between ()-init and {}-init is that narrowing conversions are permitted, designators are not permitted, a temporary object bound to a reference does not have its lifetime extended, and there is no brace elision. Further, things like int a[](1, 2, 3); // will deduce the array size const A& r(1, 2.3, 3); // narrowing is OK int (&&rr)[](1, 2, 3); int b[3](1, 2); // b[2] will be value-initialized now work as expected. Note that char f[]("fluff"); has always worked and this patch keeps it that way. Also note that A a((1, 2)) is not the same as A a{{1,2}}; the inner (1, 2) remains a COMPOUND_EXPR. The approach I took was to handle (1, 2) similarly to {1, 2} -- conjure up a CONSTRUCTOR, and introduce LOOKUP_AGGREGATE_PAREN_INIT to distinguish between the two. This kind of initialization is only supported in C++20; I've made no attempt to support it in earlier standards, like we don't support CTAD pre-C++17, for instance. * c-cppbuiltin.c (c_cpp_builtins): Predefine __cpp_aggregate_paren_init=201902 for -std=c++2a. * call.c (build_new_method_call_1): Handle parenthesized initialization of aggregates by building up a CONSTRUCTOR. (extend_ref_init_temps): Do nothing for CONSTRUCTOR_IS_PAREN_INIT. * cp-tree.h (CONSTRUCTOR_IS_PAREN_INIT, LOOKUP_AGGREGATE_PAREN_INIT): Define. * decl.c (grok_reference_init): Handle aggregate initialization from a parenthesized list of values. (reshape_init): Do nothing for CONSTRUCTOR_IS_PAREN_INIT. (check_initializer): Handle initialization of an array from a parenthesized list of values. Use NULL_TREE instead of NULL. * tree.c (build_cplus_new): Handle BRACE_ENCLOSED_INITIALIZER_P. * typeck2.c (digest_init_r): Set LOOKUP_AGGREGATE_PAREN_INIT if it receives a CONSTRUCTOR with CONSTRUCTOR_IS_PAREN_INIT set. Allow narrowing when LOOKUP_AGGREGATE_PAREN_INIT. (massage_init_elt): Don't lose LOOKUP_AGGREGATE_PAREN_INIT when passing flags to digest_init_r. * g++.dg/cpp0x/constexpr-99.C: Only expect an error in C++17 and lesser. * g++.dg/cpp0x/explicit7.C: Likewise. * g++.dg/cpp0x/initlist12.C: Adjust dg-error. * g++.dg/cpp0x/pr31437.C: Likewise. * g++.dg/cpp2a/feat-cxx2a.C: Add __cpp_aggregate_paren_init test. * g++.dg/cpp2a/paren-init1.C: New test. * g++.dg/cpp2a/paren-init10.C: New test. * g++.dg/cpp2a/paren-init11.C: New test. * g++.dg/cpp2a/paren-init12.C: New test. * g++.dg/cpp2a/paren-init13.C: New test. * g++.dg/cpp2a/paren-init14.C: New test. * g++.dg/cpp2a/paren-init15.C: New test. * g++.dg/cpp2a/paren-init16.C: New test. * g++.dg/cpp2a/paren-init17.C: New test. * g++.dg/cpp2a/paren-init18.C: New test. * g++.dg/cpp2a/paren-init19.C: New test. * g++.dg/cpp2a/paren-init2.C: New test. * g++.dg/cpp2a/paren-init3.C: New test. * g++.dg/cpp2a/paren-init4.C: New test. * g++.dg/cpp2a/paren-init5.C: New test. * g++.dg/cpp2a/paren-init6.C: New test. * g++.dg/cpp2a/paren-init7.C: New test. * g++.dg/cpp2a/paren-init8.C: New test. * g++.dg/cpp2a/paren-init9.C: New test. * g++.dg/ext/desig10.C: Adjust dg-error. * g++.dg/template/crash107.C: Likewise. * g++.dg/template/crash95.C: Likewise. * g++.old-deja/g++.jason/crash3.C: Likewise. * g++.old-deja/g++.law/ctors11.C: Likewise. * g++.old-deja/g++.law/ctors9.C: Likewise. * g++.old-deja/g++.mike/net22.C: Likewise. * g++.old-deja/g++.niklas/t128.C: Likewise. From-SVN: r278939
2019-11-27Implement P1814R0, CTAD for alias templates.Jason Merrill1-0/+2
This patch implements C++20 class template argument deduction for alias templates, which works by a moderately arcane transformation of the deduction guides for the underlying class template. When implementing it, it seemed that I could simplify the rules in the draft a bit and get essentially the same effect; I'll be emailing the committee to that effect soon. gcc/cp/ * pt.c (rewrite_tparm_list): Factor out of build_deduction_guide. (maybe_aggr_guide): Check for copy-init here. (alias_ctad_tweaks, deduction_guides_for): New. (ctor_deduction_guides_for): Factor out of do_class_deduction. (ctad_template_p): New. * parser.c (cp_parser_simple_type_specifier): Use it. * constraint.cc (append_constraint): New. gcc/c-family/ * c-cppbuiltin.c (c_cpp_builtins): Update __cpp_deduction_guides. From-SVN: r278786
2019-11-27Fix constrained alias template transparency.Jason Merrill1-1/+3
A constrained alias template can't be treated as equivalent to its underlying template/type for much the same reason that an alias template like void_t can't; we're relying on checking during substitution. * cxx-pretty-print.c (pp_cxx_unqualified_id): Handle alias template-id. * pt.c (complex_alias_template_p): True if constraints. (get_underlying_template, tsubst): Check alias constraints. (push_template_decl_real): Set alias constraints here. * parser.c (cp_parser_alias_declaration): Not here. * constraint.cc (get_constraints): Take const_tree. From-SVN: r278785
2019-11-27PR c++/92206 - ICE with typedef to dependent alias.Jason Merrill1-2/+3
rsandifo's patch for 92206 demonstrated a problem with the existing checking for alias template specializations: they were returning false for a typedef to an alias template specialization. Which is sometimes what the caller wants, and sometimes not: Sometimes we're interested in whether the type was written as an alias template-id, and sometimes whether it represents one. The testcase illustrates a case that remained wrong with the earlier patch: if the typedef is itself an alias template specialization, we can't strip an underlying dependent alias. * pt.c (dependent_alias_template_spec_p) (alias_template_specialization_p): Add transparent_typedefs parameter. (iterative_hash_template_arg, any_template_parm_r) (primary_template_specialization_p, tsubst, dependent_type_p_r): Adjust. * decl.c (check_elaborated_type_specifier): Adjust. * error.c (dump_template_bindings, dump_aggr_type): Adjust. From-SVN: r278784
2019-11-27Diagnose certain constraint errors as hard errors, but otherwise treat them ↵Andrew Sutton1-2/+2
the same as normal SFINAE-type errors. 2019-11-27 Andrew Sutton <asutton@lock3software.com> Diagnose certain constraint errors as hard errors, but otherwise treat them the same as normal SFINAE-type errors. Also, generally clean up the satisfaction functions. gcc/cp/ * constexpr.c (cxx_eval_constant_expression): Use evaluate_concept_check. * constraint.cc (normalize_concept_definition): Accept a diagnostic flag and only cache when not diagnosing errors. (decl_satisfied_cache): Map to trees instead of bools. (satisfy_atom): Guarantee a location for the errors, propagate complain flags to force_rvalue, and emit errors for non-boolean constraints. (get_normalized_constraints_and_args): New overloads. Factored out of satisfy_constraint_expression and satisfy_declaration_constraints. (satisfy_constraint_expression): Propagate diagnostic info to normalization. (satisfy_declaration_constraints): New. Factored out of constraints_satisfied_p. (constraint_satisfaction_value): New. Calls satisfy_constraint_expression or satisfy_declaration_constraints. (constraints_satisfied_p): Call constraint_satisfaction_value. (evaluate_concept_check): Don't take tsubst_falgs_t. Replay satisfaction if an error is encountered. (current_failed_constraint): Moved from pt.c. (diagnose_constraints): Call constraint_satisfaction_value. * cp-tree.h: Update declarations. * pt.c (current_failed_constraint): Moved to constraint.cc. * semantics.c (finish_id_expression_1): Remove a duplicate case. gcc/testsuite/ * g++.dg/concepts/pr84330.C: Update diagnostics. * g++.dg/cpp2a/concepts-requires2.C: Likewise. From-SVN: r278768
2019-11-25typeck.c (cp_build_indirect_ref_1): Add location_t parameter and use it in ↵Paolo Carlini1-3/+5
error messages. /gcc 2019-11-25 Paolo Carlini <paolo.carlini@oracle.com> * typeck.c (cp_build_indirect_ref_1): Add location_t parameter and use it in error messages. (build_x_indirect_ref): Adjust call. (build_indirect_ref): Likewise. (cp_build_fold_indirect_ref): Likewise. (cp_build_array_ref): Likewise. * call.c (build_new_op_1): Likewise. * semantics.c (finish_omp_clauses): Likewise. (finish_omp_depobj): Likewise. * typeck2.c (build_x_arrow): Likewise. * cp-tree.h (cp_build_indirect_ref): Update declaration. * call.c (build_new_op_1): Use location argument in warning_at. * typeck.c (cp_build_modify_expr): Consistently use the location_t argument. /libcc1 2019-11-25 Paolo Carlini <paolo.carlini@oracle.com> * libcp1plugin.cc (plugin_pragma_push_user_expression): Update cp_build_indirect_ref call. /gcc/testsuite 2019-11-25 Paolo Carlini <paolo.carlini@oracle.com> * g++.dg/diagnostic/base-operand-non-pointer-1.C: New. * g++.dg/pr53055.C: Check location too. * g++.old-deja/g++.bugs/900213_02.C: Likewise. * g++.old-deja/g++.bugs/900215_02.C: Likewise. * g++.old-deja/g++.other/badarrow.C: Likewise. * g++.old-deja/g++.other/deref1.C: Likewise. * g++.dg/warn/Wenum-compare.C: Check location too. * g++.dg/cpp0x/initlist26.C: Check location too. * g++.dg/cpp0x/initlist28.C: Likewise. * g++.dg/cpp0x/initlist29.C: Likewise. * g++.dg/cpp0x/initlist33.C: Likewise. * g++.dg/expr/string-2.C: Likewise. * g++.dg/other/ptrmem5.C: Likewise. * g++.old-deja/g++.benjamin/14664-1.C: Likewise. * g++.old-deja/g++.benjamin/14664-2.C: Likewise. * g++.old-deja/g++.brendan/init12.C: Likewise. * g++.old-deja/g++.bugs/900324_04.C: Likewise. * g++.old-deja/g++.ext/array1.C: Likewise. * g++.old-deja/g++.jason/rfg17.C: Likewise. From-SVN: r278685
2019-11-15typeck.c (cp_truthvalue_conversion): Add tsubst_flags_t parameter and use it ↵Paolo Carlini1-1/+1
in calls... /cp 2019-11-15 Paolo Carlini <paolo.carlini@oracle.com> * typeck.c (cp_truthvalue_conversion): Add tsubst_flags_t parameter and use it in calls; also pass the location_t of the expression to cp_build_binary_op and c_common_truthvalue_conversion. * rtti.c (build_dynamic_cast_1): Adjust call. * cvt.c (ocp_convert): Likewise. * cp-gimplify.c (cp_fold): Likewise. * cp-tree.h (cp_truthvalue_conversion): Update declaration. /testsuite 2019-11-15 Paolo Carlini <paolo.carlini@oracle.com> * g++.dg/warn/Walways-true-1.C: Check locations too. * g++.dg/warn/Walways-true-2.C: Likewise. * g++.dg/warn/Walways-true-3.C: Likewise. * g++.dg/warn/Waddress-1.C: Check additional location. From-SVN: r278320
2019-11-15Implement P1816R0, class template argument deduction for aggregates.Jason Merrill1-1/+1
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-13[C++] Fix interaction between aka changes and DR1558 (PR92206)Richard Sandiford1-1/+6
One of the changes in r277281 was to make the typedef variant handling in strip_typedefs pass the raw DECL_ORIGINAL_TYPE to the recursive call, instead of applying TYPE_MAIN_VARIANT first. This PR shows that that interacts badly with the implementation of DR1558, because we then refuse to strip aliases with dependent template parameters and trip: gcc_assert (!typedef_variant_p (result) || ((flags & STF_USER_VISIBLE) && !user_facing_original_type_p (result))); Keeping the current behaviour but suppressing the ICE leads to a duplicate error (the dg-bogus in the first test), so that didn't seem like a good fix. I assume keeping the alias should never actually be necessary for DECL_ORIGINAL_TYPEs, because it will already have been checked somewhere, even for implicit TYPE_DECLs. This patch therefore passes a flag to say that we can safely strip aliases with dependent template parameters. 2019-11-13 Richard Sandiford <richard.sandiford@arm.com> gcc/cp/ PR c++/92206 * cp-tree.h (STF_STRIP_DEPENDENT): New constant. * tree.c (strip_typedefs): Add STF_STRIP_DEPENDENT to the flags when calling strip_typedefs recursively on a DECL_ORIGINAL_TYPE. Don't apply the fix for DR1558 in that case; allow aliases with dependent template parameters to be stripped instead. gcc/testsuite/ PR c++/92206 * g++.dg/cpp0x/alias-decl-pr92206-1.C: New test. * g++.dg/cpp0x/alias-decl-pr92206-2.C: Likewise. * g++.dg/cpp0x/alias-decl-pr92206-3.C: Likewise. From-SVN: r278119
2019-11-06Implement D1907R1 "structural type".Jason Merrill1-0/+1
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-1/+23
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-05Various small C++ changes.Jason Merrill1-3/+14
Wrappers for lookup_qualified_name and build_x_binary_op to make calling them more convenient in places, and a function named contextual_conv_bool for places that want contextual conversion to bool. I noticed that we weren't showing the declaration location when we complain about a call to a non-constexpr function where a constant expression is required. If maybe_instantiate_noexcept doesn't actually instantiate, there's no reason for it to mess with clones. * constexpr.c (explain_invalid_constexpr_fn): Show location of fn. * pt.c (maybe_instantiate_noexcept): Only update clones if we instantiated. * typeck.c (contextual_conv_bool): New. * name-lookup.c (lookup_qualified_name): Add wrapper overload taking C string rather than identifier. * parser.c (cp_parser_userdef_numeric_literal): Use it. * rtti.c (emit_support_tinfos): Use it. * cp-tree.h (ovl_op_identifier): Change to inline functions. (build_x_binary_op): Add wrapper with fewer parms. From-SVN: r277862
2019-11-02typeck.c (composite_pointer_type): Add a const op_location_t& parameter and ↵Paolo Carlini1-1/+2
use it in diagnostics. /cp 2019-11-02 Paolo Carlini <paolo.carlini@oracle.com> * typeck.c (composite_pointer_type): Add a const op_location_t& parameter and use it in diagnostics. (composite_pointer_error): Likewise. (composite_pointer_type_r): Add a const op_location_t& parameter and forward it. (cp_build_binary_op): Adjust calls. (common_pointer_type): Likewise. * call.c (add_builtin_candidate): Likewise. (build_conditional_expr_1): Likewise. * cp-tree.h (composite_pointer_type): Update declaration. * typeck.c (cxx_sizeof_expr): Use cp_expr_loc_or_input_loc in permerror. (cxx_alignof_expr): Likewise. (lvalue_or_else): Likewise. /testsuite 2019-11-02 Paolo Carlini <paolo.carlini@oracle.com> * g++.dg/conversion/ptrmem9.C: Check location. * g++.dg/expr/cond2.C: Likewise. * g++.dg/warn/Waddress-1.C: Check locations. * g++.old-deja/g++.bugs/900324_02.C: Check location. * g++.old-deja/g++.jason/rfg20.C: Likewise. * g++.old-deja/g++.law/typeck1.C: Likewise. * g++.old-deja/g++.rfg/00321_01-.C: Likewise. * g++.old-deja/g++.rfg/00324_02-.C: Likewise. * g++.dg/diagnostic/alignof1.C: New. * g++.dg/expr/sizeof1.C: Check location. * g++.dg/cpp0x/rv-lvalue-req.C: Check locations. From-SVN: r277743
2019-11-02PR c++/88335 - Implement P1073R3: Immediate functionsJakub Jelinek1-2/+13
PR c++/88335 - Implement P1073R3: Immediate functions c-family/ * c-common.h (enum rid): Add RID_CONSTEVAL. * c-common.c (c_common_reswords): Add consteval. cp/ * cp-tree.h (struct lang_decl_fn): Add immediate_fn_p bit. (DECL_IMMEDIATE_FUNCTION_P, SET_DECL_IMMEDIATE_FUNCTION_P): Define. (enum cp_decl_spec): Add ds_consteval. (fold_non_dependent_expr): Add another tree argument defaulted to NULL_TREE. * name-lookup.h (struct cp_binding_level): Add immediate_fn_ctx_p member. * parser.c (cp_keyword_starts_decl_specifier_p): Adjust comments for C++11 and C++20 specifiers. Handle RID_CONSTEVAL. (CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR): Adjust comment. (CP_PARSER_FLAGS_CONSTEVAL): New. (cp_parser_skip_balanced_tokens): New forward declaration. (cp_parser_lambda_declarator_opt): Handle ds_consteval. Set current_binding_level->immediate_fn_ctx_p before parsing parameter list if decl-specifier-seq contains consteval specifier. (cp_parser_decl_specifier_seq): Handle RID_CONSTEVAL. (cp_parser_explicit_instantiation): Diagnose explicit instantiation with consteval specifier. (cp_parser_init_declarator): For consteval or into flags CP_PARSER_FLAGS_CONSTEVAL. (cp_parser_direct_declarator): If CP_PARSER_FLAGS_CONSTEVAL, set current_binding_level->immediate_fn_ctx_p in the sk_function_parms scope. (set_and_check_decl_spec_loc): Add consteval entry, formatting fix. * call.c (build_addr_func): For direct calls to immediate functions use build_address rather than decay_conversion. (build_over_call): Evaluate immediate function invocations. * error.c (dump_function_decl): Handle DECL_IMMEDIATE_FUNCTION_P. * semantics.c (expand_or_defer_fn_1): Use tentative linkage and don't call mark_needed for immediate functions. * typeck.c (cxx_sizeof_or_alignof_expr): Likewise. Formatting fix. (cp_build_addr_expr_1): Reject taking address of immediate function outside of immediate function. * decl.c (validate_constexpr_redeclaration): Diagnose consteval vs. non-consteval or vice versa redeclaration. Use SET_DECL_IMMEDIATE_FUNCTION_P if new_decl is immediate function. (check_tag_decl): Use %qs with keyword string to simplify translation. Handle ds_consteval. (start_decl): Adjust diagnostics for static or thread_local variables in immediate functions. (grokfndecl): Call sorry_at on virtual consteval. Use %qs with keyword to string to simplify translation. Diagnose consteval main. Use SET_DECL_IMMEDIATE_FUNCTION_P for consteval. (grokdeclarator): Handle consteval. Use %qs with keyword strings to simplify translation. Use separate ifs instead of chained else if for invalid specifiers. For constinit clear constinit_p rather than constexpr_p. * constexpr.c (find_immediate_fndecl): New function. (cxx_eval_outermost_constant_expr): Allow consteval calls returning void. Diagnose returning address of immediate function from consteval evaluation. (fold_non_dependent_expr_template): Add OBJECT argument, pass it through to cxx_eval_outermost_constant_expr. (fold_non_dependent_expr): Add OBJECT argument, pass it through to fold_non_dependent_expr_template. (fold_non_dependent_init): Adjust fold_non_dependent_expr_template caller. * method.c (defaulted_late_check): Adjust diagnostics for consteval. * lambda.c (maybe_add_lambda_conv_op): Copy over DECL_DECLARED_CONSTEXPR_P and DECL_IMMEDIATE_FUNCTION_P bits from callop to both artificial functions. * init.c (build_value_init): Don't do further processing if build_special_member_call returned a TREE_CONSTANT. Formatting fix. testsuite/ * g++.dg/cpp2a/consteval1.C: New test. * g++.dg/cpp2a/consteval2.C: New test. * g++.dg/cpp2a/consteval3.C: New test. * g++.dg/cpp2a/consteval4.C: New test. * g++.dg/cpp2a/consteval5.C: New test. * g++.dg/cpp2a/consteval6.C: New test. * g++.dg/cpp2a/consteval7.C: New test. * g++.dg/cpp2a/consteval8.C: New test. * g++.dg/cpp2a/consteval9.C: New test. * g++.dg/cpp2a/consteval10.C: New test. * g++.dg/cpp2a/consteval11.C: New test. * g++.dg/cpp2a/consteval12.C: New test. * g++.dg/cpp2a/consteval13.C: New test. * g++.dg/cpp2a/consteval14.C: New test. * g++.dg/ext/consteval1.C: New test. From-SVN: r277733
2019-11-02PR c++/91369 - Implement P0784R7: constexpr newJakub Jelinek1-0/+6
PR c++/91369 - Implement P0784R7: constexpr new * cp-tree.h (CALL_FROM_NEW_OR_DELETE_P): Define. * init.c (build_new_1, build_vec_delete_1, build_delete): Set CALL_FROM_NEW_OR_DELETE_P on the CALL_EXPR to allocator functions. * constexpr.c (is_std_allocator_allocate): Only allow global replaceable allocator functions if CALL_FROM_NEW_OR_DELETE_P or in std::allocate<T>::{,de}allocate. (potential_constant_expression_1): Likewise. * g++.dg/cpp2a/constexpr-new6.C: New test. * g++.dg/cpp2a/constexpr-new7.C: New test. From-SVN: r277732
2019-10-31re PR c++/90947 (Simple lookup table of array of strings is miscompiled)Jakub Jelinek1-0/+5
PR c++/90947 * tree.h (type_initializer_zero_p): Remove. * tree.c (type_initializer_zero_p): Remove. cp/ * cp-tree.h (type_initializer_zero_p): Declare. * decl.c (reshape_init_array_1): Formatting fix. * tree.c (type_initializer_zero_p): New function. Moved from ../tree.c, use next_initializable_field, formatting fix. Return false for TYPE_NON_AGGREGATE_CLASS types. From-SVN: r277656
2019-10-30cp-tree.h (omp_declare_variant_finalize, [...]): Declare.Jakub Jelinek1-0/+2
* 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-29Add a simulate_builin_function_decl langhookRichard Sandiford1-0/+1
Although it's possible to define the SVE intrinsics in a normal header file, it's much more convenient to define them directly in the compiler. This also speeds up compilation and gives better error messages. The idea is therefore for arm_sve.h (the main intrinsics header file) to have the pragma: #pragma GCC aarch64 "arm_sve.h" telling GCC to define (almost) everything arm_sve.h needs to define. The target then needs a way of injecting new built-in function declarations during compilation. The main hook for defining built-in functions is add_builtin_function. This is designed for use at start-up, and so has various features that are correct in that context but not for the pragma above: (1) the location is always BUILTINS_LOCATION, whereas for arm_sve.h it ought to be the location of the pragma. (2) the function is only immediately visible if it's in the implementation namespace, whereas the pragma is deliberately injecting functions into the general namespace. (3) there's no attempt to emulate a normal function declaration in C or C++, whereas functions declared by the pragma should be checked in the same way as an open-coded declaration would be. E.g. we should get an error if there was a previous incompatible declaration. (4) in C++, the function is treated as extern "C" and so can't be overloaded, whereas SVE intrinsics do use function overloading. This patch therefore adds a hook that targets can use to inject the equivalent of a source-level function declaration, but bound to a BUILT_IN_MD function. The main SVE intrinsic patch has tests to make sure that we report an error for conflicting definitions that appear either before or after including arm_sve.h. 2019-10-29 Richard Sandiford <richard.sandiford@arm.com> gcc/ * langhooks.h (lang_hooks::simulate_builtin_function_decl): New hook. (simulate_builtin_function_decl): Declare. * langhooks-def.h (LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL): Define. (LANG_HOOKS_INITIALIZER): Include it. * langhooks.c (add_builtin_function_common): Rename to... (build_builtin_function): ...this. Add a location parameter and use it instead of BUILTINS_LOCATION. Remove the hook parameter and return the decl instead. (add_builtin_function): Update accordingly, passing the returned decl to the lang hook. (add_builtin_function_ext_scope): Likewise (simulate_builtin_function_decl): New function. gcc/c/ * c-tree.h (c_simulate_builtin_function_decl): Declare. * c-decl.c (c_simulate_builtin_function_decl): New function. * c-objc-common.h (LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL): Define to the above. gcc/cp/ * cp-tree.h (cxx_simulate_builtin_function_decl): Declare. * decl.c (cxx_simulate_builtin_function_decl): New function. * cp-objcp-common.h (LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL): Define to the above. From-SVN: r277554
2019-10-24Finish moving constraint and logic functionality of out pt.c.Andrew Sutton1-2/+9
Also, reimplement and re-enable subsumption caching. gcc/cp/ * config-lang.in (gtfiles): Add logic.cc. * constraint.cc (atomic_constraints_identical_p): Add assertions. (hash_atomic_constraint): Likewise. (constraints_equivalent_p): New. (inchash::add_constraint): New. (iterative_hash_constraint): New. (decl_constraints): Moved from pt.c. (get_constraints): Likewise. (set_constraints): Likewise. (remove_constraints): Likewise. * cp-tree.h (CONSTR_P): New. (init_constraint_processing): Remove. (constraints_equivalent_p, iterative_hash_constraint): Declare. * decl.c (cxx_init_decl_processing): Don't initialize constraints. * logic.cc (subsumption_entry): Moved from pt.c. (subsumption_hasher): Likewise. (subsumption_cache): Likewise. (lookup_subsumption): Likewise. (save_subsumption): Likewise. (subsumes_constraints_nonnull): Use subsumption cache. * pt.c: Move aforementioned declarations out of this file. (init_constraint_processing): Remove. From-SVN: r277407
2019-10-24[C++ PATCH] 'std' identifier not neededNathan Sidwell1-5/+1
https://gcc.gnu.org/ml/gcc-patches/2019-10/msg01707.html * cp-tree.c (CPTI_STD_IDENTIFIER): Delete. (std_identifier): Delete. (DECL_NAME_SPACE_STD_P): Compare against std_node. * decl.c (initialize_predefined_identifiers): 'std' is not needed. (cxx_init_decl_processing): Adjust creation of ::std. Use {push,pop}_nested_namespace. (cxx_builtin_function): Use {push,pop}_nested_namespace. * except.c (init_exception_processing): Likewise. * rtti.c (init_rtti_processing): Likewise. From-SVN: r277365
2019-10-22[C++] Avoid exposing internal details in aka typesRichard Sandiford1-2/+11
This patch extends r276951 to work for C++ too. 2019-10-22 Richard Sandiford <richard.sandiford@arm.com> gcc/cp/ * cp-tree.h (STF_USER_VISIBLE): New constant. (strip_typedefs, strip_typedefs_expr): Take a flags argument. * tree.c (strip_typedefs, strip_typedefs_expr): Likewise, updating mutual calls accordingly. When STF_USER_VISIBLE is true, only look through typedefs if user_facing_original_type_p. * error.c (dump_template_bindings, type_to_string): Pass STF_USER_VISIBLE to strip_typedefs. (dump_type): Likewise, unless pp_c_flag_gnu_v3 is set. gcc/testsuite/ * g++.dg/diagnostic/aka5.h: New test. * g++.dg/diagnostic/aka5a.C: Likewise. * g++.dg/diagnostic/aka5b.C: Likewise. * g++.target/aarch64/diag_aka_1.C: Likewise. From-SVN: r277281
2019-10-18[C++ PATCH] anon type namesNathan Sidwell1-6/+9
https://gcc.gnu.org/ml/gcc-patches/2019-10/msg01354.html I noticed that we use a bitfield flag to note types with names for linkage purposes: typedef struct {} foo; but, we can infer this by comparing TYPE_STUB_DECL and TYPE_DECL of the main variant. It's only checked in two places -- the C++ parser and the objective C++ encoder. * cp-tree.h (struct lang_type): Remove was_anonymous. (TYPE_WAS_UNNAMED): Implement by checking TYPE_DECL & TYPE_STUB_DECL. * decl.c (name_unnamed_type): Don't set TYPE_WAS_UNNAMED. From-SVN: r277155
2019-10-10* cp-tree.h (template_info_decl_check): Check ENABLE_TREE_CHECKING.Jason Merrill1-29/+33
From-SVN: r276787
2019-10-09Implement C++20 P0388R4, DR 1307, and DR 330.Marek Polacek1-1/+5
This patch implements P0388R4, Permit conversions to arrays of unknown bound, <http://wg21.link/p0388r4>. CWG 393 allowed references to arrays of unknown bound and this C++20 feature allows conversions like void f(int(&)[]); int arr[1]; void g() { f(arr); } int(&r)[] = arr; The proposal seemed fairly straightforward but it turned out to be quite shifty. I found out that I needed to implement DR 2352 (done), and also DR 1307 (done in this patch). The latter DR added wording for list-initialization ranking of references to arrays which this proposal extends. DR 330 was also implemented in this patch. PR c++/91364 - P0388R4: Permit conversions to arrays of unknown bound. PR c++/69531 - DR 1307: Differently bounded array parameters. PR c++/88128 - DR 330: Qual convs and pointers to arrays of pointers. * call.c (build_array_conv): Build ck_identity at the beginning of the conversion. (standard_conversion): Pass bounds_none to comp_ptr_ttypes_const. (maybe_warn_array_conv): New. (convert_like_real): Call it. Add an error message about converting from arrays of unknown bounds. (conv_get_original_expr): New. (nelts_initialized_by_list_init): New. (conv_binds_to_array_of_unknown_bound): New. (compare_ics): Implement list-initialization ranking based on array sizes, as specified in DR 1307 and P0388R. * cp-tree.h (comp_ptr_ttypes_const): Adjust declaration. (compare_bounds_t): New enum. * typeck.c (comp_array_types): New bool and compare_bounds_t parameters. Use them. (structural_comptypes): Adjust the call to comp_array_types. (similar_type_p): Handle ARRAY_TYPE. (build_const_cast_1): Pass bounds_none to comp_ptr_ttypes_const. (comp_ptr_ttypes_real): Don't check cv-quals of ARRAY_TYPEs. Use comp_array_types to compare array types. Look through arrays as per DR 330. (comp_ptr_ttypes_const): Use comp_array_types to compare array types. Look through arrays as per DR 330. * g++.dg/conversion/qual1.C: New test. * g++.dg/conversion/qual2.C: New test. * g++.dg/conversion/qual3.C: New test. * g++.dg/conversion/ref2.C: New test. * g++.dg/conversion/ref3.C: New test. * g++.dg/cpp0x/initlist-array3.C: Remove dg-error. * g++.dg/cpp0x/initlist-array7.C: New test. * g++.dg/cpp0x/initlist-array8.C: New test. * g++.dg/cpp2a/array-conv1.C: New test. * g++.dg/cpp2a/array-conv10.C: New test. * g++.dg/cpp2a/array-conv11.C: New test. * g++.dg/cpp2a/array-conv12.C: New test. * g++.dg/cpp2a/array-conv13.C: New test. * g++.dg/cpp2a/array-conv14.C: New test. * g++.dg/cpp2a/array-conv15.C: New test. * g++.dg/cpp2a/array-conv16.C: New test. * g++.dg/cpp2a/array-conv17.C: New test. * g++.dg/cpp2a/array-conv2.C: New test. * g++.dg/cpp2a/array-conv3.C: New test. * g++.dg/cpp2a/array-conv4.C: New test. * g++.dg/cpp2a/array-conv5.C: New test. * g++.dg/cpp2a/array-conv6.C: New test. * g++.dg/cpp2a/array-conv7.C: New test. * g++.dg/cpp2a/array-conv8.C: New test. * g++.dg/cpp2a/array-conv9.C: New test. * g++.old-deja/g++.bugs/900321_01.C: Adjust dg-error. * testsuite/23_containers/span/lwg3255.cc: Adjust test to match the post-P0388R4 behavior. From-SVN: r276771
2019-10-09Update the concepts implementation to conform to C++20.Jason Merrill1-117/+241
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-0/+9
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-27cp-tree.h (class iloc_sentinel): New.Jason Merrill1-0/+18
* cp-tree.h (class iloc_sentinel): New. We didn't already have a sentinel for input_location, and while temp_override would work, it would also happily set input_location to 0, which breaks things that try to look up the associated filename. * decl.c (grokdeclarator, finish_enum_value_list): Use it. * mangle.c (mangle_decl_string): Use it. * pt.c (perform_typedefs_access_check): Use it. From-SVN: r276191
2019-09-27[C][C++] Allow targets to check calls to BUILT_IN_MD functionsRichard Sandiford1-2/+4
For SVE, we'd like the frontends to check calls to target-specific built-in functions in the same way that they already do for "normal" builtins. This patch adds a target hook for that and extends check_builtin_function_arguments accordingly. A slight complication is that when TARGET_RESOLVE_OVERLOADED_BUILTIN has resolved an overload, it can use build_function_call_vec to build the call to the underlying non-overloaded function decl. This in turn coerces the arguments to the function type and then calls check_builtin_function_arguments to check the final call. If the target does find a problem in this final call, it can be useful to refer to the original overloaded function decl in diagnostics, since that's what the user wrote. The patch therefore passes the original decl as a final optional parameter to build_function_call_vec. 2019-09-27 Richard Sandiford <richard.sandiford@arm.com> gcc/ * target.def (check_builtin_call): New target hook. * doc/tm.texi.in (TARGET_CHECK_BUILTIN_CALL): New @hook. * doc/tm.texi: Regenerate. gcc/c-family/ * c-common.h (build_function_call_vec): Take the original function decl as an optional final parameter. (check_builtin_function_arguments): Take the original function decl. * c-common.c (check_builtin_function_arguments): Likewise. Handle all built-in functions, not just BUILT_IN_NORMAL ones. Use targetm.check_builtin_call to check BUILT_IN_MD functions. gcc/c/ * c-typeck.c (build_function_call_vec): Take the original function decl as an optional final parameter. Pass all built-in calls to check_builtin_function_arguments. gcc/cp/ * cp-tree.h (build_cxx_call): Take the original function decl as an optional final parameter. (cp_build_function_call_vec): Likewise. * call.c (build_cxx_call): Likewise. Pass all built-in calls to check_builtin_function_arguments. * typeck.c (build_function_call_vec): Take the original function decl as an optional final parameter and pass it to cp_build_function_call_vec. (cp_build_function_call_vec): Take the original function decl as an optional final parameter and pass it to build_cxx_call. From-SVN: r276176
2019-09-23PR c++/91844 - Implement CWG 2352, Similar types and reference binding.Marek Polacek1-0/+1
* call.c (reference_related_p): Use similar_type_p instead of same_type_p. (reference_compatible_p): Update implementation to match CWG 2352. * cp-tree.h (similar_type_p): Declare. * typeck.c (similar_type_p): New. * g++.dg/cpp0x/pr33930.C: Add dg-error. * g++.dg/cpp0x/ref-bind1.C: New test. * g++.dg/cpp0x/ref-bind2.C: New test. * g++.dg/cpp0x/ref-bind3.C: New test. * g++.old-deja/g++.pt/spec35.C: Remove dg-error. From-SVN: r276058
2019-09-15[C++ PATCH] simplify clone predicateNathan Sidwell1-4/+7
https://gcc.gnu.org/ml/gcc-patches/2019-09/msg00904.html * cp-tree.h (DECL_CLONED_FUNCTION_P): Reimplement using IDENTIFIER_CDTOR_P, correct documentation. (DECL_CLONED_FUNCTION): Directly access field. (decl_cloned_function_p): Delete. * class.c (decl_cloned_function_p): Delete. * pt.c (instantiate_template_1): Check DECL_CHAIN is a decl. From-SVN: r275727
2019-09-14Formatting and comment syntax adjustments.Jason Merrill1-18/+18
From-SVN: r275717
2019-09-06[PATCH] Deprecate -frepo option.Nathan Sidwell1-15/+2
https://gcc.gnu.org/ml/gcc-patches/2019-09/msg00379.html PR c++/91125 * cp-tree.h (IDENTIFIER_REPO_CHOSEN, DECL_REPO_AVAILABLE_P): Delete. (struct lang_decl_base): Remove repo_available_p. * decl.c (duplicate_decls): Don't copy DECL_REPO_AVAILABLE_P. From-SVN: r275456
2019-09-06[C++ PATCH] Reserve a decl_lang bitNathan Sidwell1-9/+3
https://gcc.gnu.org/ml/gcc-patches/2019-09/msg00365.html Reserve TREE_LANG_FLAG_3 for modules. gcc/cp/ * cp-tree.h (DECL_CONSTRUCTION_VTABLE_P): Delete. (DECL_NON_TRIVIALLY_INITIALIZED_P): Move to TREE_LANG_FLAG_6. * class.c (build_ctor_vtbl_group): Don't set DECL_CONSTRUCTION_VTABLE_P. * decl2.c (determine_visibility_from_class): Don't check DECL_CONSTRUCTION_VTABLE_P anymore. From-SVN: r275455
2019-09-06Remove support for repo files (PR c++/91125).Martin Liska1-6/+0
2019-09-06 Martin Liska <mliska@suse.cz> PR c++/91125 * Makefile.in: Remove tlink.o. * collect2.c (do_link): New function isolated from do_tlink. (main): Use. * collect2.h (do_tlink): Remove declaration of do_tlink. * doc/extend.texi: Remove documentation of -frepo. * doc/invoke.texi: Likewise. * doc/sourcebuild.texi: Remove cleanup-repo-files. * tlink.c: Remove. 2019-09-06 Martin Liska <mliska@suse.cz> PR c++/91125 * c-common.c: Remove definition of flag_use_repository. * c-common.h: Likewise. * c-opts.c (c_common_handle_option): Do not handle OPT_frepo option. * c.opt: Mark the option with Deprecated. 2019-09-06 Martin Liska <mliska@suse.cz> PR c++/91125 * Make-lang.in: Remove repo.o. * config-lang.in: Likewise. * cp-tree.h (init_repo): Remove declarations of repo-related functions. (repo_emit_p): Likewise. (repo_export_class_p): Likewise. (finish_repo): Likewise. * decl2.c (import_export_class): Always set -1 value/ (mark_needed): Remove -frepo from comment. (import_export_decl): Similarly here. (c_parse_final_cleanups): Remove call of finish_repo. * lex.c (cxx_init): Remove call to init_repo. * optimize.c (can_alias_cdtor): Remove dead condition. * pt.c (push_template_decl_real): Update comment. (instantiate_decl): Remove dead code used for -frepo. * repo.c: Remove. 2019-09-06 Martin Liska <mliska@suse.cz> PR c++/91125 * g++.dg/parse/repo1.C: Remove. * g++.dg/rtti/repo1.C: Remove. * g++.dg/template/repo1.C: Remove. * g++.dg/template/repo10.C: Remove. * g++.dg/template/repo11.C: Remove. * g++.dg/template/repo2.C: Remove. * g++.dg/template/repo3.C: Remove. * g++.dg/template/repo4.C: Remove. * g++.dg/template/repo5.C: Remove. * g++.dg/template/repo6.C: Remove. * g++.dg/template/repo7.C: Remove. * g++.dg/template/repo8.C: Remove. * g++.dg/template/repo9.C: Remove. * g++.old-deja/g++.pt/instantiate4.C: Remove. * g++.old-deja/g++.pt/instantiate6.C: Remove. * g++.old-deja/g++.pt/repo1.C: Remove. * g++.old-deja/g++.pt/repo2.C: Remove. * g++.old-deja/g++.pt/repo3.C: Remove. * g++.old-deja/g++.pt/repo4.C: Remove. * lib/g++.exp: Remove removal of repo files. * lib/gcc-dg.exp: Likewise. * lib/obj-c++.exp: Likewise. From-SVN: r275450
2019-09-05[C++ PATCH] vtable decl markingNathan Sidwell1-3/+4
https://gcc.gnu.org/ml/gcc-patches/2019-08/msg02063.html * cp-tree.h (DECL_VTABLE_OR_VTT_P): Forward to DECL_VIRTUAL_P. From-SVN: r275404
2019-08-31Add source location to TRAIT_EXPR.Jason Merrill1-1/+5
Since TRAIT_EXPR is exceptional, maybe_wrap_with_location won't wrap it, so we need to put its location in the TRAIT_EXPR node itself. * cp-tree.h (TRAIT_EXPR_LOCATION): New. (struct tree_trait_expr): Add locus field. * parser.c (cp_parser_trait_expr): Pass trait_loc down. * pt.c (tsubst_copy_and_build) [TRAIT_EXPR]: Likewise. * semantics.c (finish_trait_expr): Add location parm. * tree.c (cp_expr_location): Handle TRAIT_EXPR. From-SVN: r275260
2019-08-29decl.c (check_var_type): Add location_t parameter and use it.Paolo Carlini1-1/+1
/cp 2019-08-29 Paolo Carlini <paolo.carlini@oracle.com> * decl.c (check_var_type): Add location_t parameter and use it. (grokdeclarator): Adjust call. * pt.c (tsubst_decl): Likewise. * cp-tree.h: Adjust declaration. /testsuite 2019-08-29 Paolo Carlini <paolo.carlini@oracle.com> * g++.dg/spellcheck-typenames.C: Adjust expected locations. * g++.dg/cpp0x/pr84676.C: Check locations. * g++.dg/other/pr88187.C: Likewise. * g++.dg/parse/crash13.C: Likewise. * g++.dg/parse/crash46.C: Likewise. * g++.dg/parse/template28.C: Likewise. * g++.dg/parse/typename4.C: Likewise. From-SVN: r275025