aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
AgeCommit message (Collapse)AuthorFilesLines
2020-11-02c++: Fixup some vardecls and whitespaceNathan Sidwell1-13/+10
Move some var decls to their initializers. Correct some whitespace. gcc/cp/ * decl.c (start_decl_1): Refactor declarations. Fixup some whitespace. (lookup_and_check_tag): Fixup some whitespace.
2020-11-02c++: refactor duplicate declsNathan Sidwell1-23/+29
A couple of paths in duplicate decls dealing with templates and builtins were overly complicated. Fixing thusly. gcc/cp/ * decl.c (duplicate_decls): Refactor some template & builtin handling.
2020-11-02c++: Delete unused hash typeNathan Sidwell2-29/+0
Since I redid block-scope extern decls, the need for a uid->decl hasher has gone away. Deleting thusly. gcc/cp/ * cp-tree.h (struct cxx_int_tree_map): Delete. (struct cxx_int_tree_map_hasher): Delete. * cp-gimplify.c (cxx_int_tree_map_hasher::equal): Delete. (cxx_int_tree_map_hasher::hash): Delete.
2020-11-02c++: Don't purge the satisfaction cachesPatrick Palka5-19/+4
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-11-01Objective-C++ : Address a FIXME.Iain Sandoe1-9/+4
We can avoid the spurious additional complaint about a closing ')' by short-circuiting the test in the case we know there's a syntax error already reported. gcc/cp/ChangeLog: * parser.c (cp_parser_objc_at_property_declaration): Use any exisiting syntax error to suppress complaints about a missing closing parenthesis in parsing property attributes. gcc/testsuite/ChangeLog: * obj-c++.dg/property/at-property-1.mm: Adjust test after fixing spurious error output.
2020-10-30openmp: Handle non-static data members in allocate clause and other C++ ↵Jakub Jelinek2-13/+21
allocate fixes This allows specification of non-static data members in allocate clause like it can be specified in other privatization clauses and adds a new testcase that covers also handling of that clause in templates. 2020-10-30 Jakub Jelinek <jakub@redhat.com> * semantics.c (finish_omp_clauses) <case OMP_CLAUSE_ALLOCATE>: Handle non-static members in methods. * pt.c (tsubst_omp_clauses): Handle OMP_CLAUSE_ALLOCATE. * c-c++-common/gomp/allocate-1.c (qux): Add another test. * g++.dg/gomp/allocate-1.C: New test.
2020-10-30Daily bump.GCC Administrator1-0/+92
2020-10-29c++: Implement CWG 625: Use of auto as template-arg [PR97479]Marek Polacek1-2/+16
This patch implements CWG 625 which prohibits using auto in a template argument. A few tests used this construction. Since this usage was allowed by the Concepts TS, we only give an error in C++20. gcc/cp/ChangeLog: DR 625 PR c++/97479 * parser.c (cp_parser_type_id_1): Reject using auto as a template-argument in C++20. gcc/testsuite/ChangeLog: DR 625 PR c++/97479 * g++.dg/cpp0x/auto3.C: Update dg-error. * g++.dg/cpp0x/auto9.C: Likewise. * g++.dg/cpp2a/concepts-pr84979-2.C: Likewise. * g++.dg/cpp2a/concepts-pr84979-3.C: Likewise. * g++.dg/cpp2a/concepts-pr84979.C: Likewise. * g++.dg/DRs/dr625.C: New test.
2020-10-29c++: Deducing type from initializer_list<auto> [PR93107]Marek Polacek1-1/+7
In this testcase we weren't able to deduce b's type: template<typename T> void Task() { } auto b = { &Task<int> }; because resolve_nondeduced_context doesn't iterate on the {}'s elements. So make sure to look into {} too. We don't need to handle nested {} here. We could either tweak resolve_nondeduced_context to handle CONSTRUCTORs or add a _ctor version, but then resolve_nondeduced_context_or_error would need some changes too -- it'd have to check the result of a call to r_n_c for each element. gcc/cp/ChangeLog: PR c++/93107 * pt.c (do_auto_deduction): Call resolve_nondeduced_context for the elements of a { } list. gcc/testsuite/ChangeLog: PR c++/93107 * g++.dg/cpp0x/initlist-deduce3.C: New test.
2020-10-29c++: Reject float <=> enum.Marek Polacek1-2/+11
As [depr.arith.conv.enum] says, these are ill-formed. gcc/cp/ChangeLog: * typeck.c (do_warn_enum_conversions): Don't warn for SPACESHIP_EXPR. (cp_build_binary_op): Reject float <=> enum or enum <=> float. Use CP_INTEGRAL_TYPE_P instead of INTEGRAL_OR_ENUMERATION_TYPE_P. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/enum-conv1.C: Remove unused code. * g++.dg/cpp2a/spaceship-err5.C: New test.
2020-10-29c++: Simplify constraint normalization routinesPatrick Palka3-54/+24
Many of the high-level constraint normalization routines allow the caller to supply the initial template arguments for normalization, but in practice all of the callers supply something equivalent to the identity mapping(*). This patch hard-codes this prevalent choice of initial template arguments by making get_normalized_constraints always pass NULL_TREE as the args to normalize_expression. This admits some simplifications in the high-level routines, such as removing their 'args' parameter and consolidating the two versions of normalize_constraint_expression. (*): In particular, a set of generic template arguments or NULL_TREE. In the case of the two-parm version of normalize_constraint_expression, we were suspiciously using the template arguments of a concept-id when normalizing the concept-id as a constraint-expression. gcc/cp/ChangeLog: * constraint.cc (get_normalized_constraints): Remove 'args' parameter. Pass NULL_TREE as the initial template arguments to normalize_expression. (get_normalized_constraints_from_info): Remove 'args' parameter and adjust the call to get_normalized_constraints. (get_normalized_constraints_from_decl): Remove 'args' local variable and adjust call to get_normalized_constraints_from_info. (normalize_concept_definition): Remove 'args' local variable and adjust call to get_normalized_constraints. (normalize_constraint_expression): Remove the two-parameter overload. Remove 'args' parameter from the three-parameter overload and update function comment accordingly. Remove default argument from 'diag' parameter. Adjust call to get_normalized_constraints. (finish_nested_requirement): Adjust call to normalize_constraint_expression. (strictly_subsumes): Remove 'args' parameter. Adjust call to get_normalized_constraints_from_info. (weakly_subsumes): Likewise. * cp-tree.h (strictly_subsumes): Remove 'args' parameter. (weakly_subsumes): Likewise. * pt.c (process_partial_specialization): Adjust call to strictly_subsumes. (is_compatible_template_arg): Adjust call to weakly_subsumes.
2020-10-29c++: Tolerate empty initial args during normalization [PR97412]Patrick Palka1-1/+2
When normalizing the constraint-expression of a nested-requirement, we pass NULL_TREE as the initial template arguments for normalization, but tsubst_argument_pack is not prepared to handle a NULL_TREE args vector. This causes us to ICE when normalizing a variadic concept as part of a nested-requirement. This patch fixes the ICE by guarding the call to tsubst_template_args in normalize_concept_check appropriately. This will also enable us to simplify many of the normalization routines to just pass NULL_TREE (instead of a set of generic template arguments) as the initial template arguments. gcc/cp/ChangeLog: PR c++/97412 * constraint.cc (normalize_concept_check): Don't call tsubst_template_args when 'args' is NULL. gcc/testsuite/ChangeLog: PR c++/97412 * g++.dg/cpp2a/concepts-variadic2.C: New test.
2020-10-29c++: Fix constexpr cleanup error handling.Jason Merrill1-6/+4
In this testcase, the primary evaluation successfully produces 'true', and then running one of the cleanups hits a double delete, making the whole thing not a valid constant expression. So we were returning 'true' wrapped in a NOP_EXPR to indicate its non-constancy, but evaluating that again is a perfectly acceptable constant expression, so we weren't getting the verbose diagnostic we were looking for. So if non_constant_p gets set other than for overflow, go back to the original expression. With this change, we should never hit the manifestly_const_eval test, and the is-constant-evaluated1.C test passes without it. gcc/cp/ChangeLog: PR c++/97388 * constexpr.c (cxx_eval_outermost_constant_expr): Revert to original expression if evaluation sets non_constant_p. gcc/testsuite/ChangeLog: PR c++/97388 * g++.dg/cpp2a/constexpr-dtor8.C: New test.
2020-10-29c++: Fix constexpr dtors vs invisible ref [PR97388]Jakub Jelinek1-7/+12
For arguments passed by invisible reference, in the IL until genericization we have the source types on the callee side and while on the caller side we already pass references to the actual argument slot in the caller, we undo that in cxx_bind_parameters_in_call's if (TREE_ADDRESSABLE (type)) /* Undo convert_for_arg_passing work here. */ x = convert_from_reference (x); This works fine most of the time, except when the type also has constexpr destructor; in that case the destructor is invoked in the caller and thus the unsharing we do to make sure that the callee doesn't modify caller's values is in that case undesirable, it prevents the changes done in the callee propagating to the caller which should see them for the constexpr dtor evaluation. The following patch fixes that. While it could be perhaps done for all TREE_ADDRESSABLE types, I don't see the need to change the behavior if there is no constexpr non-trivial dtor. Jason: And we need to avoid memoizing the call, because a later equivalent call also needs to modify its argument. And we don't need to unshare constructors when we aren't memoizing the call, because we already unshared them when evaluating the TARGET_EXPR representing the copy-initialization of the argument. 2020-10-20 Jakub Jelinek <jakub@redhat.com> Jason Merrill <jason@redhat.com> PR c++/97388 * constexpr.c (cxx_bind_parameters_in_call): Set non_constant_args if the parameter type has a non-trivial destructor. (cxx_eval_call_expression): Only unshare arguments if we're memoizing this evaluation. * g++.dg/cpp2a/constexpr-dtor5.C: New test. * g++.dg/cpp2a/constexpr-dtor6.C: New test. * g++.dg/cpp2a/constexpr-dtor7.C: New test.
2020-10-29c++: Diagnose constexpr delete [] new int; and delete new int[N]; [PR95808]Jakub Jelinek3-5/+59
This patch diagnoses delete [] new int; and delete new int[1]; in constexpr contexts by remembering IDENTIFIER_OVL_OP_FLAGS (DECL_NAME (fun)) & OVL_OP_FLAG_VEC from the operator new and checking it at operator delete time. 2020-10-29 Jakub Jelinek <jakub@redhat.com> PR c++/95808 * cp-tree.h (enum cp_tree_index): Add CPTI_HEAP_VEC_UNINIT_IDENTIFIER and CPTI_HEAP_VEC_IDENTIFIER. (heap_vec_uninit_identifier, heap_vec_identifier): Define. * decl.c (initialize_predefined_identifiers): Initialize those identifiers. * constexpr.c (cxx_eval_call_expression): Reject array allocations deallocated with non-array deallocation or non-array allocations deallocated with array deallocation. (non_const_var_error): Handle heap_vec_uninit_identifier and heap_vec_identifier too. (cxx_eval_constant_expression): Handle also heap_vec_uninit_identifier and in that case during initialization replace it with heap_vec_identifier. (find_heap_var_refs): Handle heap_vec_uninit_identifier and heap_vec_identifier too. * g++.dg/cpp2a/constexpr-new15.C: New test.
2020-10-29c++: Stop (most) function-scope entities having a template headerNathan Sidwell1-63/+80
Currently push_template_decl (mostly) decides whether to add a template header to an entity by seeing if it has DECL_LANG_SPECIFIC. That might have been a useful predicate at one time, but basing semantic implications on how we've decided to represent decls is bound to be brittle. And indeed it is, as more decls grow a use for lang-specific. In particular I discovered that function-scope VAR_DECLs couild grow lang-specific, and thereby get a template header. There's no need for that, and it breaks an invariant modules was expected. This patch changes that, and bases the descision on the properties of the decl. In particular the only function-scope decl that gets a template header is an implicit-typedef. I also cleaned up the behaviour of it building a template-info only to ignore it. gcc/cp/ * pt.c (push_template_decl): Do not give function-scope entities other than implicit typedefs a template header. Do not readd template info to a redeclared template.
2020-10-29Daily bump.GCC Administrator1-0/+67
2020-10-28c++: Improve the MVP -Wparentheses diagnostic.Marek Polacek2-3/+14
I noticed that declarator->parenthesized is, for this warning, only set to the opening paren. But we can easily make it a range and generate a nicer diagnostic. Moreover, we can then offer a fix-it hint. TL;DR: This patch changes mvp3.C:8:7: warning: unnecessary parentheses in declaration of ‘i’ [-Wparentheses] 8 | int (i); | ^ to mvp3.C:8:7: warning: unnecessary parentheses in declaration of ‘i’ [-Wparentheses] 8 | int (i); | ^~~ mvp3.C:8:7: note: remove parentheses 8 | int (i); | ^~~ | - - Tested by using -fdiagnostics-generate-patch and verifying that the generated patch DTRT. gcc/cp/ChangeLog: * decl.c (grokdeclarator): Offer a fix-it hint for the "unnecessary parentheses in declaration" warning. * parser.c (cp_parser_direct_declarator): When setting declarator->parenthesized, use a location range. gcc/testsuite/ChangeLog: * g++.dg/warn/mvp3.C: New test.
2020-10-28c++: Deprecate arithmetic convs on different enums [PR97573]Marek Polacek2-11/+136
I noticed that C++20 P1120R0 deprecated certain arithmetic conversions as outlined in [depr.arith.conv.enum], but we don't warn about them. In particular, "If one operand is of enumeration type and the other operand is of a different enumeration type or a floating-point type, this behavior is deprecated." These will likely become ill-formed in C++23, so we should warn by default in C++20. To this effect, this patch adds two new warnings (like clang++): -Wdeprecated-enum-enum-conversion and -Wdeprecated-enum-float-conversion. They are enabled by default in C++20. In older dialects, to enable these warnings you can now use -Wenum-conversion which I made available in C++ too. Note that unlike C, in C++ it is not enabled by -Wextra, because that breaks bootstrap. We already warn about comparisons of two different enumeration types via -Wenum-compare, the rest is handled in this patch: we're performing the usual arithmetic conversions in these contexts: - an arithmetic operation, - a bitwise operation, - a comparison, - a conditional operator, - a compound assign operator. Using the spaceship operator as enum <=> real_type is ill-formed but we don't reject it yet. We should also address [depr.array.comp] too, but it's not handled in this patch. gcc/c-family/ChangeLog: PR c++/97573 * c-opts.c (c_common_post_options): In C++20, turn on -Wdeprecated-enum-enum-conversion and -Wdeprecated-enum-float-conversion. * c.opt (Wdeprecated-enum-enum-conversion, Wdeprecated-enum-float-conversion): New options. (Wenum-conversion): Allow for C++ too. gcc/cp/ChangeLog: PR c++/97573 * call.c (build_conditional_expr_1): Warn about the deprecated enum/real type conversion in C++20. Also warn about a non-enumerated and enumerated type in ?: when -Wenum-conversion is on. * typeck.c (do_warn_enum_conversions): New function. (cp_build_binary_op): Call it. gcc/ChangeLog: PR c++/97573 * doc/invoke.texi: Document -Wdeprecated-enum-enum-conversion and -Wdeprecated-enum-float-conversion. -Wenum-conversion is no longer C/ObjC only. gcc/testsuite/ChangeLog: PR c++/97573 * g++.dg/cpp0x/linkage2.C: Add dg-warning. * g++.dg/parse/attr3.C: Likewise. * g++.dg/cpp2a/enum-conv1.C: New test. * g++.dg/cpp2a/enum-conv2.C: New test. * g++.dg/cpp2a/enum-conv3.C: New test.
2020-10-28c++: Prevent warnings for value-dependent exprs [PR96742]Marek Polacek1-2/+5
Here, in r11-155, I changed the call to uses_template_parms to type_dependent_expression_p_push to avoid a crash in C++98 in value_dependent_expression_p on a non-constant expression. But that prompted a host of complaints that we now warn for value-dependent expressions in templates. Those warnings are technically valid, but people still don't want them because they're awkward to avoid. This patch uses value_dependent_expression_p or type_dependent_expression_p. But make sure that we don't ICE in value_dependent_expression_p by checking potential_constant_expression first. gcc/cp/ChangeLog: PR c++/96675 PR c++/96742 * pt.c (tsubst_copy_and_build): Call value_dependent_expression_p or type_dependent_expression_p instead of type_dependent_expression_p_push. But only call value_dependent_expression_p for expressions that are potential_constant_expression. gcc/testsuite/ChangeLog: PR c++/96675 PR c++/96742 * g++.dg/warn/Wdiv-by-zero-3.C: Turn dg-warning into dg-bogus. * g++.dg/warn/Wtautological-compare3.C: New test. * g++.dg/warn/Wtype-limits5.C: New test. * g++.old-deja/g++.pt/crash10.C: Remove dg-warning.
2020-10-28c++: Member template function lookup failure [PR94799]Marek Polacek1-7/+6
My earlier patch for this PR, r11-86, broke pybind11. That patch changed cp_parser_class_name to also consider the object expression scope (parser->context->object_type) to fix parsing of p->template A<T>::foo(); // consider p's scope too Here we reject b.operator typename B<T>::type(); because 'typename_p' in cp_parser_class_name uses 'scope', which means that 'typename_p' will be true for the example above. Then we create a TYPENAME_TYPE via make_typename_type, which fails when tsubsting it; the code basically created 'typename B::B' and then we complain that there is no member named 'B' in 'A<int>'. So, when deciding if we should create a TYPENAME_TYPE, don't consider the object_type scope, like we did pre-r11-86. gcc/cp/ChangeLog: PR c++/94799 * parser.c (cp_parser_class_name): Use parser->scope when setting typename_p. gcc/testsuite/ChangeLog: PR c++/94799 * g++.dg/template/lookup16.C: New test.
2020-10-28c++: GCC accepts junk before fold-expression [PR86773]Marek Polacek1-0/+2
Here we accept a bogus expression before a left fold: Recall that a fold expression looks like: fold-expression: ( cast-expression fold-operator ... ) ( ... fold-operator cast-expression ) ( cast-expression fold-operator ... fold-operator cast-expression ) but here we have ( cast-expression ... fold-operator cast-expression ) The best fix seems to just return error_mark_node when we know this code is invalid, and let the subsequent code report that a ) was expected. gcc/cp/ChangeLog: PR c++/86773 * parser.c (cp_parser_fold_expression): Return error_mark_node if a left fold is preceded by an expression. gcc/testsuite/ChangeLog: PR c++/86773 * g++.dg/cpp1z/fold12.C: New test.
2020-10-28c++: Make OMP UDR DECL_LOCAL_DECL_P earlierNathan Sidwell2-6/+15
I discovered that we were pushing an OMP UDR in a template before setting DECL_LOCAL_DECL. This caused the template machinery to give it some template info. It doesn't need that, and this changes the parser to set it earlier. We have to adjust instantiate_body to not try and access such a function's non-existant template_info. The access checks that we're no longer doing are the same as those we did on the containing function anyway. So nothing is lost. gcc/cp/ * parser.c (cp_parser_omp_declare_reduction): Set DECL_LOCAL_DECL_P before push_template_decl. * pt.c (instantiate_body): Nested fns do not have template_info.
2020-10-28c++: Check constraints before instantiation from mark_used [PR95132]Patrick Palka1-10/+10
This makes mark_used check constraints of a function _before_ calling maybe_instantiate_decl, so that we don't try instantiating a function (as part of return type deduction) with unsatisfied constraints. gcc/cp/ChangeLog: PR c++/95132 * decl2.c (mark_used): Move up the constraints_satisfied_p check so that we check constraints before calling maybe_instantiate_decl. gcc/testsuite/ChangeLog: PR c++/95132 * g++.dg/cpp2a/concepts-fn7.C: New test.
2020-10-28c++: Refactor push_template_declNathan Sidwell1-17/+15
Sadly I need to wander into push_template_decl again. But here's a piece of RAII goodness first. gcc/cp/ * pt.c (push_template_decl): Refactor for some RAII.
2020-10-28openmp: Parsing and some semantic analysis of OpenMP allocate clauseJakub Jelinek3-1/+152
This patch adds parsing of OpenMP allocate clause, but still ignores it during OpenMP lowering where we should for privatized variables with allocate clause use the corresponding allocators rather than allocating them on the stack. 2020-10-28 Jakub Jelinek <jakub@redhat.com> gcc/ * tree-core.h (enum omp_clause_code): Add OMP_CLAUSE_ALLOCATE. * tree.h (OMP_CLAUSE_ALLOCATE_ALLOCATOR, OMP_CLAUSE_ALLOCATE_COMBINED): Define. * tree.c (omp_clause_num_ops, omp_clause_code_name): Add allocate clause. (walk_tree_1): Handle OMP_CLAUSE_ALLOCATE. * tree-pretty-print.c (dump_omp_clause): Likewise. * gimplify.c (gimplify_scan_omp_clauses, gimplify_adjust_omp_clauses, gimplify_omp_for): Likewise. * tree-nested.c (convert_nonlocal_omp_clauses, convert_local_omp_clauses): Likewise. * omp-low.c (scan_sharing_clauses): Likewise. gcc/c-family/ * c-pragma.h (enum pragma_omp_clause): Add PRAGMA_OMP_CLAUSE_ALLOCATE. * c-omp.c: Include bitmap.h. (c_omp_split_clauses): Handle OMP_CLAUSE_ALLOCATE. gcc/c/ * c-parser.c (c_parser_omp_clause_name): Handle allocate. (c_parser_omp_clause_allocate): New function. (c_parser_omp_all_clauses): Handle PRAGMA_OMP_CLAUSE_ALLOCATE. (OMP_FOR_CLAUSE_MASK, OMP_SECTIONS_CLAUSE_MASK, OMP_PARALLEL_CLAUSE_MASK, OMP_SINGLE_CLAUSE_MASK, OMP_TASK_CLAUSE_MASK, OMP_TASKGROUP_CLAUSE_MASK, OMP_DISTRIBUTE_CLAUSE_MASK, OMP_TEAMS_CLAUSE_MASK, OMP_TARGET_CLAUSE_MASK, OMP_TASKLOOP_CLAUSE_MASK): Add PRAGMA_OMP_CLAUSE_ALLOCATE. * c-typeck.c (c_finish_omp_clauses): Handle OMP_CLAUSE_ALLOCATE. gcc/cp/ * parser.c (cp_parser_omp_clause_name): Handle allocate. (cp_parser_omp_clause_allocate): New function. (cp_parser_omp_all_clauses): Handle PRAGMA_OMP_CLAUSE_ALLOCATE. (OMP_FOR_CLAUSE_MASK, OMP_SECTIONS_CLAUSE_MASK, OMP_PARALLEL_CLAUSE_MASK, OMP_SINGLE_CLAUSE_MASK, OMP_TASK_CLAUSE_MASK, OMP_TASKGROUP_CLAUSE_MASK, OMP_DISTRIBUTE_CLAUSE_MASK, OMP_TEAMS_CLAUSE_MASK, OMP_TARGET_CLAUSE_MASK, OMP_TASKLOOP_CLAUSE_MASK): Add PRAGMA_OMP_CLAUSE_ALLOCATE. * semantics.c (finish_omp_clauses): Handle OMP_CLAUSE_ALLOCATE. * pt.c (tsubst_omp_clauses): Likewise. gcc/testsuite/ * c-c++-common/gomp/allocate-1.c: New test. * c-c++-common/gomp/allocate-2.c: New test. * c-c++-common/gomp/clauses-1.c (omp_allocator_handle_t): New typedef. (foo, bar, baz): Add allocate clauses where allowed.
2020-10-28Daily bump.GCC Administrator1-0/+40
2020-10-27c++: Kill nested_udtsNathan Sidwell6-298/+25
During the implementation of modules I added myself a note to implement nested_udt handling. It wasn't obvious to me what they were for and nothing seemed to be broken in ignoring them. I figured something would eventually pop up and I'd add support. Nothing popped up. Investigating on trunk discovered 3 places where we look at the nested-udts. I couldn't figure how the one in lookup_field_r was needed -- surely the regular lookup would find the type. It turned out that code was unreachable. So we can delete it. Next in do_type_instantiation, we walk the nested-utd table instantiating types. But those types are also on the TYPE_FIELDS list, which we've just iterated over. So I can move the handling into that loop. The final use is in handling structs that have a typedef name for linkage purposes. Again, we can just iterate over TYPE_FIELDS. (As commented, we probably don't need to do even that, as a DR, whose number I forget, requires such structs to only have C-like things in them. But I didn't go that far. Having removed all the uses of nested-udts, I can remove their creation from name-lookup, and as the only instance of a binding_table object, we can remove all that code too. gcc/cp/ * cp-tree.h (struct lang_type): Delete nested_udts field. (CLASSTYPE_NESTED_UTDS): Delete. * name-lookup.h (binding_table, binding_entry): Delete typedefs. (bt_foreach_proc): Likewise. (struct binding_entry_s): Delete. (SCOPE_DEFAULT_HT_SIZE, CLASS_SCOPE_HT_SIZE) (NAMESPACE_ORDINARY_HT_SIZE, NAMESPACE_STD_HT_SIZE) (GLOBAL_SCOPE_HT_SIZE): Delete. (binding_table_foreach, binding_table_find): Delete declarations. * name-lookup.c (ENTRY_INDEX): Delete. (free_binding_entry): Delete. (binding_entry_make, binding_entry_free): Delete. (struct binding_table_s): Delete. (binding_table_construct, binding_table_free): Delete. (binding_table_new, binding_table_expand): Delete. (binding_table_insert, binding_table_find): Delete. (binding_table_foreach): Delete. (maybe_process_template_type_declaration): Delete CLASSTYPE_NESTED_UTDS insertion. (do_pushtag): Likewise. * decl2.c (bt_reset_linkage_1): Fold into reset_type_linkage_1. (reset_type_linkage_2, bt_reset_linkage_2): Fold into reset_type_linkage. * pt.c (instantiate_class_template_1): Delete NESTED_UTDs comment. (bt_instantiate_type_proc): Delete. (do_type_instantiation): Instantiate implicit typedef fields. Delete NESTED_UTD walk. * search.c (lookup_field_r): Delete unreachable NESTED_UTD search.
2020-10-27c++: Small cleanup for do_type_instantiationNathan Sidwell2-56/+41
In working on a bigger cleanup I noticed some opportunities to make do_type_instantiation's control flow simpler. gcc/cp/ * parser.c (cp_parser_explicit_instantiation): Refactor some RAII. * pt.c (bt_instantiate_type_proc): DATA is the tree, pass type to do_type_instantiation. (do_type_instantiation): Require T to be a type. Refactor for some RAII.
2020-10-27Daily bump.GCC Administrator1-0/+12
2020-10-26c++: Implement __is_nothrow_constructible and __is_nothrow_assignableVille Voutilainen4-4/+36
gcc/c-family/ChangeLog: * c-common.c (__is_nothrow_assignable): New. (__is_nothrow_constructible): Likewise. * c-common.h (RID_IS_NOTHROW_ASSIGNABLE): New. (RID_IS_NOTHROW_CONSTRUCTIBLE): Likewise. gcc/cp/ChangeLog: * cp-tree.h (CPTK_IS_NOTHROW_ASSIGNABLE): New. (CPTK_IS_NOTHROW_CONSTRUCTIBLE): Likewise. (is_nothrow_xible): Likewise. * method.c (is_nothrow_xible): New. (is_trivially_xible): Tweak. * parser.c (cp_parser_primary_expression): Handle the new RID_*. (cp_parser_trait_expr): Likewise. * semantics.c (trait_expr_value): Handle the new RID_*. (finish_trait_expr): Likewise. libstdc++-v3/ChangeLog: * include/std/type_traits (__is_nt_constructible_impl): Remove. (__is_nothrow_constructible_impl): Adjust. (is_nothrow_default_constructible): Likewise. (__is_nt_assignable_impl): Remove. (__is_nothrow_assignable_impl): Adjust.
2020-10-25Daily bump.GCC Administrator1-0/+7
2020-10-24c++: Fix verify_ctor_sanity ICE [PR96241]Marek Polacek1-2/+9
The code added in r10-6437 caused us to create a CONSTRUCTOR when we're {}-initializing an aggregate. Then we pass this new CONSTRUCTOR down to cxx_eval_constant_expression which, if the CONSTRUCTOR isn't TREE_CONSTANT or reduced_constant_expression_p, calls cxx_eval_bare_aggregate. In this case the CONSTRUCTOR wasn't reduced_constant_expression_p because for r_c_e_p a CONST_DECL isn't good enough so it returns false. So we go to cxx_eval_bare_aggregate where we crash, because ctx->ctor wasn't set up properly. So my fix is to do so. Since we're value-initializing, I'm not setting CONSTRUCTOR_NO_CLEARING. To avoid keeping a garbage constructor around, I call free_constructor in case the evaluation did not use it. gcc/cp/ChangeLog: PR c++/96241 * constexpr.c (cxx_eval_array_reference): Set up ctx->ctor if we are initializing an aggregate. Call free_constructor on the new CONSTRUCTOR if it isn't returned from cxx_eval_constant_expression. gcc/testsuite/ChangeLog: PR c++/96241 * g++.dg/cpp0x/constexpr-96241.C: New test. * g++.dg/cpp1y/constexpr-96241.C: New test.
2020-10-24Daily bump.GCC Administrator1-0/+5
2020-10-23c, c++: Implement -Wsizeof-array-div [PR91741]Marek Polacek1-2/+8
This patch implements a new warning, -Wsizeof-array-div. It warns about code like int arr[10]; sizeof (arr) / sizeof (short); where we have a division of two sizeof expressions, where the first argument is an array, and the second sizeof does not equal the size of the array element. See e.g. <https://www.viva64.com/en/examples/v706/>. Clang makes it possible to suppress the warning by parenthesizing the second sizeof like this: sizeof (arr) / (sizeof (short)); so I followed suit. In the C++ FE this was rather easy, because finish_parenthesized_expr already set TREE_NO_WARNING. In the C FE I've added a new tree code, PAREN_SIZEOF_EXPR, to discern between the non-() and () versions. This warning is enabled by -Wall. An example of the output: x.c:5:23: warning: expression does not compute the number of elements in this array; element type is ‘int’, not ‘short int’ [-Wsizeof-array-div] 5 | return sizeof (arr) / sizeof (short); | ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ x.c:5:25: note: add parentheses around ‘sizeof (short int)’ to silence this warning 5 | return sizeof (arr) / sizeof (short); | ^~~~~~~~~~~~~~ | ( ) x.c:4:7: note: array ‘arr’ declared here 4 | int arr[10]; | ^~~ gcc/c-family/ChangeLog: PR c++/91741 * c-common.c (verify_tree): Handle PAREN_SIZEOF_EXPR. (c_common_init_ts): Likewise. * c-common.def (PAREN_SIZEOF_EXPR): New tree code. * c-common.h (maybe_warn_sizeof_array_div): Declare. * c-warn.c (sizeof_pointer_memaccess_warning): Unwrap NOP_EXPRs. (maybe_warn_sizeof_array_div): New function. * c.opt (Wsizeof-array-div): New option. gcc/c/ChangeLog: PR c++/91741 * c-parser.c (c_parser_binary_expression): Implement -Wsizeof-array-div. (c_parser_postfix_expression): Set PAREN_SIZEOF_EXPR. (c_parser_expr_list): Handle PAREN_SIZEOF_EXPR like SIZEOF_EXPR. * c-tree.h (char_type_p): Declare. * c-typeck.c (char_type_p): No longer static. gcc/cp/ChangeLog: PR c++/91741 * typeck.c (cp_build_binary_op): Implement -Wsizeof-array-div. gcc/ChangeLog: PR c++/91741 * doc/invoke.texi: Document -Wsizeof-array-div. gcc/testsuite/ChangeLog: PR c++/91741 * c-c++-common/Wsizeof-pointer-div.c: Add dg-warning. * c-c++-common/Wsizeof-array-div1.c: New test. * g++.dg/warn/Wsizeof-array-div1.C: New test. * g++.dg/warn/Wsizeof-array-div2.C: New test.
2020-10-23Daily bump.GCC Administrator1-0/+23
2020-10-22c++: Handle RANGE_EXPR index in init_subob_ctx [PR97328]Patrick Palka1-2/+9
In the testcase below, we're ICEing during constexpr evaluation of the CONSTRUCTOR {.data={{}, [1 ... 7]={}}} of type 'vector'. The interesting thing about this CONSTRUCTOR is that it has a RANGE_EXPR index for an element initializer which doesn't satisfy reduced_constant_expression_p (because the field 't' is uninitialized). This is a problem because init_subob_ctx currently punts on setting up a sub-aggregate initialization context when given a RANGE_EXPR index, so we later trip over the asserts in verify_ctor_sanity when recursing into cxx_eval_bare_aggregate on this element initializer. Fix this by making init_subob_ctx set up an appropriate initialization context when supplied a RANGE_EXPR index. gcc/cp/ChangeLog: PR c++/97328 * constexpr.c (init_subob_ctx): Don't punt on RANGE_EXPR indexes, instead build a sub-aggregate initialization context with no subobject. gcc/testsuite/ChangeLog: PR c++/97328 * g++.dg/cpp2a/constexpr-init19.C: New test. * g++.dg/cpp2a/constexpr-init20.C: New test.
2020-10-22c++: constexpr evaluation and bare EMPTY_CLASS_EXPR [PR96575]Patrick Palka1-8/+6
In the testcase below, folding of the initializer for 'ret' inside the instantiated f<lambda>::lambda ends up yielding an initializer for which potential_constant_expression returns false. This causes finish_function to mark the lambda as non-constexpr, which ultimately causes us to reject 'f(g)' as a call to a non-constexpr function. The initializer for 'ret' inside f<lambda>::lambda, prior to folding, is the CALL_EXPR <lambda(S)>::operator() (&cb, ({}, <<< Unknown tree: empty_class_expr >>>;)) where the second argument is a COMPOUND_EXPR whose second operand is an EMPTY_CLASS_EXPR that was formed by build_class_a. cp_fully_fold_init is able to only partially fold this initializer: it gets rid of the side-effectless COMPOUND_EXPR to obtain <lambda(S)>::operator() (&cb, <<< Unknown tree: empty_class_expr >>>) as the final initializer for 'ret'. This initializer no longer satifies potential_constant_expression due to the bare EMPTY_CLASS_EXPR which is not wrapped in a COMPOUND_EXPR. (cp_fully_fold_init first tries maybe_constant_value on the original CALL_EXPR, but constexpr evaluation punts upon seeing __builtin_is_constant_evaluated, since manifestly_const_eval is false.) To fix this, it seems we could either make cp_fold preserve the COMPOUND_EXPR trees produced by build_call_a, or we could improve the constexpr machinery to treat EMPTY_CLASS_EXPR trees as first-class citizens. Assuming it's safe to continue folding away these COMPOUND_EXPRs, the second approach seems cleaner, so this patch implements the second approach. gcc/cp/ChangeLog: PR c++/96575 * constexpr.c (cxx_eval_constant_expression) <case EMPTY_CLASS_EXPR>: Lower it to a CONSTRUCTOR. (potential_constant_expression_1) <case COMPOUND_EXPR>: Remove now-redundant handling of COMPOUND_EXPR with EMPTY_CLASS_EXPR second operand. <case EMPTY_CLASS_EXPR>: Return true instead of false. gcc/testsuite/ChangeLog: PR c++/96575 * g++.dg/cpp1z/constexpr-96575.C: New test.
2020-10-22c++: Check DECL_TEMPLATE_PARM_P in duplicate_decls [PR97511]Patrick Palka1-0/+3
This makes duplicate_decls differentiate a TYPE_DECL for an alias template from a TYPE_DECL for one of its template parameters. The recently added assert in template_parm_to_arg revealed this latent issue because merging of the two TYPE_DECLs cleared the DECL_TEMPLATE_PARM_P flag. With this patch, we now also correctly diagnose the name shadowing in the below testcase (as required by [temp.local]/6). gcc/cp/ChangeLog: PR c++/97511 * decl.c (duplicate_decls): Return NULL_TREE if DECL_TEMPLATE_PARM_P differ. gcc/testsuite/ChangeLog: PR c++/97511 * g++.dg/template/shadow3.C: New test.
2020-10-21Daily bump.GCC Administrator1-0/+5
2020-10-20c++: block-scope extern decl with default argsNathan Sidwell1-0/+46
In adding the DECL_LOCAL_DECL handling, I'd forgotten that the parm-decls also need cloning -- and resetting of their DECL_CONTEXT. Also, any default args need droping when adding an alias, as those are not propagated. The std's not totally clear on this latter point when there's no exising namespace decl, but that seems like the right thing and is what clang does. gcc/cp/ * name-lookup.c (push_local_extern_decl_alias): Reconstextualize alias' parm decls. Drop any default args. gcc/testsuite/ * g++.dg/lookup/local-extern.C: New.
2020-10-20Daily bump.GCC Administrator1-0/+10
2020-10-19coroutines: Emit error for invalid promise return types [PR97438].Iain Sandoe1-0/+25
At one stage, use cases were proposed for allowing the promise type to contain both return_value and return_void. That was not accepted into C++20, so we should reject it as per the PR. gcc/cp/ChangeLog: PR c++/97438 * coroutines.cc (struct coroutine_info): Add a field to record that we emitted a promise type error. (coro_promise_type_found_p): Check for the case that the promise type contains both return_void and return_value. Emit an error if so, with information about the wrong type methods. gcc/testsuite/ChangeLog: PR c++/97438 * g++.dg/coroutines/pr97438.C: New test.
2020-10-17Daily bump.GCC Administrator1-0/+12
2020-10-16c++: Fix nullptr deref [pr97460[Nathan Sidwell1-1/+2
My changes to friend handling meant that there are now cases where a friend doesn't get a lang-specific object. So we need to check there is one before looking inside it. PR c++/97460 gcc/cp/ * pt.c (push_template_decl): Check DECL_LANG_SPECIFIC in friend case. gcc/testsuite/ * g++.dg/template/pr97460.C: New.
2020-10-16c++: Fix null deref at EOF [PR96258]Nathan Sidwell1-4/+2
cp_parser_declaration peeks at 1 or 2 tokens, when I changed it not to peek past EOF, I set the second token to NULL. But there are paths through the function that just look at the second token. Fixed by setting that token to EOF rather than NULL in this case. PR c++/96258 gcc/cp/ * parser.c (cp_parser_declaration): Make token2 point to EOF if token1 was EOF. gcc/testsuite/ * g++.dg/parse/pr96258.C: New.
2020-10-16Daily bump.GCC Administrator1-0/+17
2020-10-15c++: Fix [[deprecated]] and implicit operator==. [PR97358]Jason Merrill1-0/+8
Trying to diagnose the problem with an implicit copy function breaks if the function isn't actually a copy function. gcc/cp/ChangeLog: PR c++/95844 * decl.c (copy_fn_p): Return false for a function that is neither a constructor nor an assignment operator. (move_signature_fn_p): Likewise. gcc/testsuite/ChangeLog: PR c++/95844 * g++.dg/cpp2a/spaceship-eq10.C: New test.
2020-10-15c++: Improve printing of pointers-to-members [PR97406, PR85901]Marek Polacek1-1/+32
This PR points out that when printing the parameter mapping for a pointer-to-member-function, the output was truncated: [with T = void (X::*] Fixed by printing the abstract declarator for pointers-to-members in cxx_pretty_printer::type_id. So now we print: [with T = void (X::*)()] But when I tried a pointer-to-data-member, I got [with T = ‘offset_type’ not supported by simple_type_specifier)‘offset_type’ not supported by direct_abstract_declarator] so had to fix that too so that we now print: [with T = int X::*] or [with T = int (X::*)[5]] when the type is an array type. Which is what PR85901 was about. gcc/cp/ChangeLog: PR c++/97406 PR c++/85901 * cxx-pretty-print.c (pp_cxx_type_specifier_seq): Handle OFFSET_TYPE. (cxx_pretty_printer::abstract_declarator): Fix the printing of ')'. (cxx_pretty_printer::direct_abstract_declarator): Handle OFFSET_TYPE. (cxx_pretty_printer::type_id): Likewise. Print the abstract declarator for pointers-to-members. gcc/testsuite/ChangeLog: PR c++/97406 PR c++/85901 * g++.dg/diagnostic/ptrtomem1.C: New test. * g++.dg/diagnostic/ptrtomem2.C: New test.
2020-10-15Daily bump.GCC Administrator1-0/+40