aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
AgeCommit message (Collapse)AuthorFilesLines
2020-10-14c++: Diagnose bogus variadic lambda. [PR97358]Jason Merrill1-5/+12
If the lambda has a capture pack, it cannot be used unexpanded within the body of the lambda. If you want to expand the pack across multiple lambdas, don't capture the whole pack. gcc/cp/ChangeLog: PR c++/97358 * pt.c (check_for_bare_parameter_packs): Diagnose use of capture pack. gcc/testsuite/ChangeLog: PR c++/97358 * g++.dg/cpp0x/lambda/lambda-variadic11.C: New test.
2020-10-14c++: DECL_FRIEND_P cleanupNathan Sidwell8-176/+98
DECL_FRIEND_P's meaning has changed over time. It now (almost) means the the friend function decl has not been met via an explicit decl. This completes that transition, renaming it to DECL_UNIQUE_FRIEND_P, so one doesn't think it is the sole indicator of friendliness (plenty of friends do not have the flag set). This allows reduction in the complexity of managing the field -- all in duplicate_decls now. gcc/cp/ * cp-tree.h (struct lang_decl_fn): Adjust context comment. (DECL_FRIEND_P): Replace with ... (DECL_UNIQUE_FRIEND_P): ... this. Only for FUNCTION_DECLs. (DECL_FRIEND_CONTEXT): Adjust. * class.c (add_implicitly_declared_members): Detect friendly spaceship from context. * constraint.cc (remove_constraints): Use a checking assert. (maybe_substitute_reqs_for): Use DECL_UNIQUE_FRIEND_P. * decl.c (check_no_redeclaration_friend_default_args): DECL_UNIQUE_FRIEND_P is signficant, not hiddenness. (duplicate_decls): Adjust DECL_UNIQUE_FRIEND_P clearing. (redeclaration_error_message): Use DECL_UNIQUE_FRIEND_P. (start_preparsed_function): Correct in-class friend processing. Refactor some initializers. (grokmethod): Directly check friend decl-spec. * decl2.c (grokfield): Check DECL_UNIQUE_FRIEND_P. * friend.c (do_friend): Set DECL_UNIQUE_FRIEND_P first, remove extraneous conditions. Don't re set it afterwards. * name-lookup.c (lookup_elaborated_type_1): Simplify revealing code. (do_pushtag): Likewise. * pt.c (optimize_specialization_lookup_p): Check DECL_UNIQUE_FRIEND_P. (push_template_decl): Likewise. Drop unneeded friend setting. (type_dependent_expression_p): Check DECL_UNIQUE_FRIEND_P. libcc1/ * libcp1plugin.cc (plugin_add_friend): Set DECL_UNIQUE_FRIEND_P.
2020-10-14c++: Instantiation with local extern [PR97395]Nathan Sidwell1-7/+15
It turns out that pushdecl_with_scope has somewhat strange behaviour, which probably made more sense way back. Unfortunately making it somewhat saner turned into a rathole. Instead use a push_nested_namespace around pushing the alias -- this is similar to some of the friend handling we already have. gcc/cp/ * name-lookup.c (push_local_extern_decl_alias): Push into alias's namespace and use pushdecl. (do_pushdecl_with_scope): Clarify behaviour. gcc/testsuite/ * g++.dg/lookup/extern-redecl2.C: New.
2020-10-13Daily bump.GCC Administrator1-0/+13
2020-10-12PR c++/97201 - ICE in -Warray-bounds writing to result of operator new(0)Martin Sebor1-2/+5
gcc/cp/ChangeLog: PR c++/97201 * error.c (dump_type_suffix): Handle both the C and C++ forms of zero-length arrays. libstdc++-v3/ChangeLog: PR c++/97201 * libsupc++/new (operator new): Add attribute alloc_size and malloc. gcc/testsuite/ChangeLog: PR c++/97201 * g++.dg/warn/Wplacement-new-size-8.C: Adjust expected message. * g++.dg/warn/Warray-bounds-10.C: New test. * g++.dg/warn/Warray-bounds-11.C: New test. * g++.dg/warn/Warray-bounds-12.C: New test. * g++.dg/warn/Warray-bounds-13.C: New test.
2020-10-12Correct handling of indices into arrays with elements larger than 1 (PR ↵Martin Sebor1-249/+83
c++/96511) Resolves: PR c++/96511 - Incorrect -Wplacement-new on POINTER_PLUS into an array with 4-byte elements PR middle-end/96384 - bogus -Wstringop-overflow= storing into multidimensional array with index in range gcc/ChangeLog: PR c++/96511 PR middle-end/96384 * builtins.c (get_range): Return full range of type when neither value nor its range is available. Fail for ranges inverted due to the signedness of offsets. (compute_objsize): Handle more special array members. Handle POINTER_PLUS_EXPR and VIEW_CONVERT_EXPR that come up in front end code. (access_ref::offset_bounded): Define new member function. * builtins.h (access_ref::eval): New data member. (access_ref::offset_bounded): New member function. (access_ref::offset_zero): New member function. (compute_objsize): Declare a new overload. * gimple-array-bounds.cc (array_bounds_checker::check_array_ref): Use enum special_array_member. * tree.c (component_ref_size): Use special_array_member. * tree.h (special_array_member): Define a new type. (component_ref_size): Change signature. gcc/cp/ChangeLog: PR c++/96511 PR middle-end/96384 * init.c (warn_placement_new_too_small): Call builtin_objsize instead of duplicating what it does. gcc/testsuite/ChangeLog: PR c++/96511 PR middle-end/96384 * g++.dg/init/strlen.C: Add expected warning. * g++.dg/warn/Wplacement-new-size-1.C: Relax warnings. * g++.dg/warn/Wplacement-new-size-2.C: Same. * g++.dg/warn/Wplacement-new-size-6.C: Same. * gcc.dg/Warray-bounds-58.c: Adjust * gcc.dg/Wstringop-overflow-37.c: Same. * g++.dg/warn/Wplacement-new-size-7.C: New test.
2020-10-09Daily bump.GCC Administrator1-0/+24
2020-10-08c++: Fix member alias template in C++17 and up. [PR96805]Jason Merrill1-2/+7
Here we're trying to push into a<T>::c<N> in order to instantiate t<N>, but were building a TYPENAME_TYPE for it because a<T> isn't open yet. Don't do that when we know we're trying to enter the scope. gcc/cp/ChangeLog: PR c++/96805 PR c++/96199 * pt.c (tsubst_aggr_type): Don't build a TYPENAME_TYPE when entering_scope. (tsubst_template_decl): Use tsubst_aggr_type. gcc/testsuite/ChangeLog: PR c++/96805 * g++.dg/cpp0x/alias-decl-pr96805.C: New test.
2020-10-08c++: ICE in dependent_type_p with constrained auto [PR97052]Patrick Palka2-0/+4
This patch fixes an "unguarded" call to coerce_template_parms in build_standard_check: processing_template_decl could be zero if we get here during processing of the first 'auto' parameter of an abbreviated function template, or if we're processing the type constraint of a non-templated variable. In the testcase below, this leads to an ICE when coerce_template_parms instantiates C's dependent default template argument. gcc/cp/ChangeLog: PR c++/97052 * constraint.cc (build_type_constraint): Temporarily increment processing_template_decl before calling build_concept_check. * pt.c (make_constrained_placeholder_type): Likewise. gcc/testsuite/ChangeLog: PR c++/97052 * g++.dg/cpp2a/concepts-defarg2.C: New test.
2020-10-08c++: Set the constraints of a class type sooner [PR96229]Patrick Palka2-7/+8
In the testcase below, during processing (at parse time) of Y's base class X<Y>, convert_template_argument calls is_compatible_template_arg to check if the template argument Y is no more constrained than the parameter P. But at this point we haven't yet set Y's constraints, so get_normalized_constraints_from_decl yields NULL_TREE as the normal form and caches this result into the normalized_map. We set Y's constraints later in cp_parser_class_specifier_1 but the stale normal form in the normalized_map remains. This ultimately causes us to miss the constraint failure for Y<Z> because according to the cached normal form, Y is not constrained. This patch fixes this issue by moving up the call to associate_classtype_constraints so that we set constraints before we start processing a class's bases. gcc/cp/ChangeLog: PR c++/96229 * parser.c (cp_parser_class_specifier_1): Move call to associate_classtype_constraints from here to ... (cp_parser_class_head): ... here. * pt.c (is_compatible_template_arg): Correct documentation to say "argument is _no_ more constrained than the parameter". gcc/testsuite/ChangeLog: PR c++/96229 * g++.dg/cpp2a/concepts-class2.C: New test.
2020-10-08Daily bump.GCC Administrator1-0/+46
2020-10-07c++: Fix P0846 (ADL and function templates) in template [PR97010]Marek Polacek1-9/+28
To quickly recap, P0846 says that a name is also considered to refer to a template if it is an unqualified-id followed by a < and name lookup finds either one or more functions or finds nothing. In a template, when parsing a function call that has type-dependent arguments, we can't perform ADL right away so we set KOENIG_LOOKUP_P in the call to remember to do it when instantiating the call (tsubst_copy_and_build/CALL_EXPR). When the called function is a function template, we represent the call with a TEMPLATE_ID_EXPR; usually the operand is an OVERLOAD. In the P0846 case though, the operand can be an IDENTIFIER_NODE, when name lookup found nothing when parsing the template name. But we weren't handling this correctly in tsubst_copy_and_build. First we need to pass the FUNCTION_P argument from <case TEMPLATE_ID_EXPR> to <case IDENTIFIER_NODE>, otherwise we give a bogus error. And then in <case CALL_EXPR> we need to perform ADL. The rest of the changes is to give better errors when ADL didn't find anything. gcc/cp/ChangeLog: PR c++/97010 * pt.c (tsubst_copy_and_build) <case TEMPLATE_ID_EXPR>: Call tsubst_copy_and_build explicitly instead of using the RECUR macro. Handle a TEMPLATE_ID_EXPR with an IDENTIFIER_NODE as its operand. <case CALL_EXPR>: Perform ADL for a TEMPLATE_ID_EXPR with an IDENTIFIER_NODE as its operand. gcc/testsuite/ChangeLog: PR c++/97010 * g++.dg/cpp2a/fn-template21.C: New test. * g++.dg/cpp2a/fn-template22.C: New test.
2020-10-07c++: Distinguish alignof and __alignof__ in cp_tree_equal [PR97273]Patrick Palka1-0/+2
cp_tree_equal currently considers alignof the same as __alignof__, but these operators are semantically different ever since r8-7957. In the testcase below, this causes the second static_assert to fail on targets where alignof(double) != __alignof__(double) because the specialization table (which uses cp_tree_equal as its equality predicate) conflates the two dependent specializations integral_constant<__alignof__(T)> and integral_constant<alignof(T)>. This patch makes cp_tree_equal distinguish between these two operators by inspecting the ALIGNOF_EXPR_STD_P flag. gcc/cp/ChangeLog: PR c++/88115 PR libstdc++/97273 * tree.c (cp_tree_equal) <case ALIGNOF_EXPR>: Return false if ALIGNOF_EXPR_STD_P differ. gcc/testsuite/ChangeLog: PR c++/88115 PR libstdc++/97273 * g++.dg/template/alignof3.C: New test.
2020-10-07c++: block-scope externs get an alias [PR95677,PR31775,PR95677]Nathan Sidwell8-145/+130
This patch improves block-scope extern handling by always injecting a hidden copy into the enclosing namespace (or using a match already there). This hidden copy will be revealed if the user explicitly declares it later. We can get from the DECL_LOCAL_DECL_P local extern to the alias via DECL_LOCAL_DECL_ALIAS. This fixes several bugs and removes the kludgy per-function extern_decl_map. We only do this pushing for non-dependent local externs -- dependent ones will be pushed during instantiation. User code that expected to be able to handle incompatible local externs in different block-scopes will no longer work. That code is ill-formed. (always was, despite what 31775 claimed). I had to adjust a number of testcases that fell into this. I tried using DECL_VALUE_EXPR, but that didn't work out. Due to constexpr requirements we have to do the replacement very late (it happens in the gimplifier). Consider: extern int l[]; // #1 constexpr bool foo () { extern int l[3]; // this does not complete the type of decl #1 constexpr int *p = &l[2]; // ok return !p; } This requirement, coupled with our use of the common folding machinery makes pr97306 hard to fix, as we end up with an expression containing the two different decls for 'l', and only the c++ FE knows how to reconcile those. I punted on this. gcc/cp/ * cp-tree.h (struct language_function): Delete extern_decl_map. (DECL_LOCAL_DECL_ALIAS): New. * name-lookup.h (is_local_extern): Delete. * name-lookup.c (set_local_extern_decl_linkage): Replace with ... (push_local_extern_decl): ... this new function. (do_pushdecl): Call new function after pushing new decl. Unhide hidden non-functions. (is_local_extern): Delete. * decl.c (layout_var_decl): Do not allow VLA local externs. * decl2.c (mark_used): Also mark DECL_LOCAL_DECL_ALIAS. Drop old local-extern treatment. * parser.c (cp_parser_oacc_declare): Deal with local extern aliases. * pt.c (tsubst_expr): Adjust local extern instantiation. * cp-gimplify.c (cp_genericize_r): Remap DECL_LOCAL_DECLs. gcc/testsuite/ * g++.dg/cpp0x/lambda/lambda-sfinae1.C: Avoid ill-formed local extern * g++.dg/init/pr42844.C: Add expected error. * g++.dg/lookup/extern-redecl1.C: Likewise. * g++.dg/lookup/koenig15.C: Avoid ill-formed. * g++.dg/lto/pr95677.C: New. * g++.dg/other/nested-extern-1.C: Correct expected behabviour. * g++.dg/other/nested-extern-2.C: Likewise. * g++.dg/other/nested-extern.cc: Split ... * g++.dg/other/nested-extern-1.cc: ... here ... * g++.dg/other/nested-extern-2.cc: ... here. * g++.dg/template/scope5.C: Avoid ill-formed * g++.old-deja/g++.law/missed-error2.C: Allow extension. * g++.old-deja/g++.pt/crash3.C: Add expected error.
2020-10-07c++: Rename DECL_BUILTIN_P to DECL_UNDECLARED_BUILTIN_PNathan Sidwell3-5/+6
I realized I'd misnamed DECL_BUILTIN_P, it's only true of compiler builtins unless and until the user declares them -- at that point they're real decls, and will have a location in the user's source. (BUILT_IN_FN and friends still work though). This renames them so future-me is not confused as to why the predicate becomes false. gcc/cp/ * cp-tree.h (DECL_BUILTIN_P): Rename to ... (DECL_UNDECLARED_BUILTIN_P): ... here. * decl.c (duplicate_decls): Adjust. * name-lookup.c (anticipated_builtin_p): Adjust. (do_nonmember_using_decl): Likewise. libcc1/ * libcp1plugin.cc (supplement_binding): Rename DECL_BUILTIN_P.
2020-10-07c++: Adding exception specs can changed dependentnessNathan Sidwell1-0/+3
Making an exception variant can cause a non-dependent function type to become dependent (since c++17 eh-specs are part of the type). The same is (possibly?) true for adding a late return type. Fixed thusly. My upcoming local extern-decl changes have a test case that covers this (which was how I found it). gcc/cp/ * tree.c (build_cp_fntype_variant): Clear TYPE_DEPENDENT_P_VALID if necessary.
2020-10-07Daily bump.GCC Administrator1-0/+7
2020-10-06c++: typename in out-of-class member function definitions [PR97297]Marek Polacek1-2/+8
I was notified that our P0634R3 (Down with typename) implementation has a flaw: when we have an out-of-class member function definition, we still required 'typename' for its parameters. For example here: template <typename T> struct S { int simple(T::type); }; template <typename T> int S<T>::simple(/* typename */T::type) { return 0; } the 'typename' isn't necessary per [temp.res]/5.2.4. We have a qualified name here ("S<T>::simple") so we know it's already been declared so we can look it up to see if it's a function template or a variable template. In this case, the P0634R3 code in cp_parser_direct_declarator wasn't looking into uninstantiated templates and didn't find the member function 'simple' -- cp_parser_lookup_name returned a SCOPE_REF which means that the qualifying scope was dependent. With this fix, we find the BASELINK for 'simple', don't clear CP_PARSER_FLAGS_TYPENAME_OPTIONAL from the flags, and the typename is implicitly assumed. gcc/cp/ChangeLog: PR c++/97297 * parser.c (cp_parser_direct_declarator): When checking if a name is a function template declaration for the P0634R3 case, look in uninstantiated templates too. gcc/testsuite/ChangeLog: PR c++/97297 * g++.dg/cpp2a/typename18.C: New test.
2020-10-06Daily bump.GCC Administrator1-0/+17
2020-10-05c++: Fix typo in NON_UNION_CLASS_TYPE_P.Marek Polacek1-1/+1
gcc/cp/ChangeLog: * cp-tree.h (NON_UNION_CLASS_TYPE_P): Fix typo in a comment.
2020-10-05support TARGET_MEM_REF in C/C++ error pretty-printing [PR97197]Jakub Jelinek1-0/+58
> See my comment above for Martins attempts to improve things. I don't > really want to try decide what to do with those late diagnostic IL > printing but my commit was blamed for showing target-mem-ref unsupported. > > I don't have much time to spend to think what to best print and what not, > but yes, printing only the MEM_REF part is certainly imprecise. Here is an updated version of the patch that prints TARGET_MEM_REF the way it should be printed - as C representation of what it actually means. Of course it would be better to have the original expressions, but with the late diagnostics we no longer have them. 2020-10-05 Richard Biener <rguenther@suse.de> Jakub Jelinek <jakub@redhat.com> PR c++/97197 gcc/cp/ * error.c (dump_expr): Handle TARGET_MEM_REF. gcc/c-family/ * c-pretty-print.c: Include langhooks.h. (c_pretty_printer::postfix_expression): Handle TARGET_MEM_REF as expression. (c_pretty_printer::expression): Handle TARGET_MEM_REF as unary_expression. (c_pretty_printer::unary_expression): Handle TARGET_MEM_REF.
2020-10-05c++: Make spell corrections consistentNathan Sidwell1-23/+93
My change to namespace-scope spell corrections ignored the issue that different targets might have different builtins, and therefore perturb iteration order. This fixes it by using an intermediate array of identifier, which we sort before considering. gcc/cp/ * name-lookup.c (maybe_add_fuzzy_decl): New. (maybe_add_fuzzy_binding): New. (consider_binding_level): Use intermediate sortable vector for namespace bindings. gcc/testsuite/ * c-c++-common/spellcheck-reserved.c: Restore diagnostic.
2020-10-03Daily bump.GCC Administrator1-0/+65
2020-10-02c++: Fix printing of C++20 template parameter object [PR97014]Marek Polacek1-0/+2
No one is interested in the mangled name of the C++20 template parameter object for a class NTTP. So instead of printing required for the satisfaction of ‘positive<T::ratio>’ [with T = X<::_ZTAXtl5ratioLin1ELi2EEE>] let's print required for the satisfaction of ‘positive<T::ratio>’ [with T = X<{-1, 2}>] I don't think adding a test is necessary for this. gcc/cp/ChangeLog: PR c++/97014 * cxx-pretty-print.c (pp_cxx_template_argument_list): If the argument is template_parm_object_p, print its DECL_INITIAL.
2020-10-02c++: Kill DECL_ANTICIPATEDNathan Sidwell4-82/+21
Here's the patch to remove DECL_ANTICIPATED, and with it hiddenness is managed entirely in the symbol table. Sadly I couldn't get rid of the actual field without more investigation -- it's repurposed for OMP_PRIVATIZED_MEMBER. It looks like a the VAR-related flags in lang_decl_base are not completely orthogonal, so perhaps some can be turned into an enumeration or something. But that's more than I want to do right now. DECL_FRIEND_P Is still slightly suspect as it appears to mean more than just in-class definition. However, I'm leaving that for now. gcc/cp/ * cp-tree.h (lang_decl_base): anticipated_p is not used for anticipatedness. (DECL_ANTICIPATED): Delete. * decl.c (duplicate_decls): Delete DECL_ANTICIPATED_management, use was_hidden. (cxx_builtin_function): Drop DECL_ANTICIPATED setting. (xref_tag_1): Drop DECL_ANTICIPATED assert. * name-lookup.c (name_lookup::adl_class_only): Drop DECL_ANTICIPATED check. (name_lookup::search_adl): Always dedup. (anticipated_builtin_p): Reimplement. (do_pushdecl): Drop DECL_ANTICIPATED asserts & update. (lookup_elaborated_type_1): Drop DECL_ANTICIPATED update. (do_pushtag): Drop DECL_ANTICIPATED setting. * pt.c (push_template_decl): Likewise. (tsubst_friend_class): Likewise. libcc1/ * libcp1plugin.cc (libcp1plugin.cc): Drop DECL_ANTICIPATED test.
2020-10-02c++: Hash table iteration for namespace-member spelling suggestionsNathan Sidwell1-42/+84
For 'no such binding' errors, we iterate over binding levels to find a close match. At the namespace level we were using DECL_ANTICIPATED to skip undeclared builtins. But (a) there are other unnameable things there and (b) decl-anticipated is about to go away. This changes the namespace scanning to iterate over the hash table, and look at non-hidden bindings. This does mean we look at fewer strings (hurrarh), but the order we meet them is somewhat 'random'. Our distance measure is not very fine grained, and a couple of testcases change their suggestion. I notice for the c/c++ common one, we now match the output of the C compiler. For the other one we think 'int' and 'int64_t' have the same distance from 'int64', and now meet the former first. That's a little unfortunate. If it's too problematic I suppose we could sort the strings via an intermediate array before measuring distance. gcc/cp/ * name-lookup.c (consider_decl): New, broken out of ... (consider_binding_level): ... here. Iterate the hash table for namespace bindings. gcc/testsuite/ * c-c++-common/spellcheck-reserved.c: Adjust diagnostic. * g++.dg/spellcheck-typenames.C: Adjust diagnostic.
2020-10-02c++: cleanup ctor_omit_inherited_parms [PR97268]Nathan Sidwell3-134/+162
ctor_omit_inherited_parms was being somewhat abused. What I'd missed is that it checks for a base-dtor name, before proceeding with the check. But we ended up passing it that during cloning before we'd completed the cloning. It was also using DECL_ORIGIN to get to the in-charge ctor, but we sometimes zap DECL_ABSTRACT_ORIGIN, and it ends up processing the incoming function -- which happens to work. so, this breaks out a predicate that expects to get the incharge ctor, and will tell you whether its base ctor will need to omit the parms. We call that directly during cloning. Then the original fn is essentially just a wrapper, but uses DECL_CLONED_FUNCTION to get to the in-charge ctor. That uncovered abuse in add_method, which was happily passing TEMPLATE_DECLs to it. Let's not do that. add_method itself contained a loop mostly containing an 'if (nomatch) continue' idiom, except for a final 'if (match) {...}' check, which itself contained instances of the former idiom. I refactored that to use the former idiom throughout. In doing that I found a place where we'd issue an error, but then not actually reject the new member. gcc/cp/ * cp-tree.h (base_ctor_omit_inherited_parms): Declare. * class.c (add_method): Refactor main loop, only pass fns to ctor_omit_inherited_parms. (build_cdtor_clones): Rename bool parms. (clone_cdtor): Call base_ctor_omit_inherited_parms. * method.c (base_ctor_omit_inherited_parms): New, broken out of ... (ctor_omit_inherited_parms): ... here, call it with DECL_CLONED_FUNCTION. gcc/testsuite/ * g++.dg/inherit/pr97268.C: New.
2020-10-02c++: Simplify __FUNCTION__ creationNathan Sidwell2-54/+32
I had reason to wander into cp_make_fname, and noticed it's the only caller of cp_fname_init. Folding it in makes the code simpler. gcc/cp/ * cp-tree.h (cp_fname_init): Delete declaration. * decl.c (cp_fname_init): Merge into only caller ... (cp_make_fname): ... here & refactor.
2020-10-02c++: Set CALL_FROM_NEW_OR_DELETE_P on more calls.Jason Merrill2-19/+24
We were failing to set the flag on a delete call in a new expression, in a deleting destructor, and in a coroutine. Fixed by setting it in the function that builds the call. 2020-10-02 Jason Merril <jason@redhat.com> gcc/cp/ChangeLog: * call.c (build_operator_new_call): Set CALL_FROM_NEW_OR_DELETE_P. (build_op_delete_call): Likewise. * init.c (build_new_1, build_vec_delete_1, build_delete): Not here. (build_delete): gcc/ChangeLog: * gimple.h (gimple_call_operator_delete_p): Rename from gimple_call_replaceable_operator_delete_p. * gimple.c (gimple_call_operator_delete_p): Likewise. * tree.h (DECL_IS_REPLACEABLE_OPERATOR_DELETE_P): Remove. * tree-ssa-dce.c (mark_all_reaching_defs_necessary_1): Adjust. (propagate_necessity): Likewise. (eliminate_unnecessary_stmts): Likewise. * tree-ssa-structalias.c (find_func_aliases_for_call): Likewise. gcc/testsuite/ChangeLog: * g++.dg/pr94314.C: new/delete no longer omitted.
2020-10-02c++: Move CALL_FROM_NEW_OR_DELETE_P to tree.hJason Merrill5-9/+11
As discussed with richi, we should be able to use TREE_PROTECTED for this flag, since CALL_FROM_THUNK_P will never be set on a call to an operator new or delete. 2020-10-01 Jason Merril <jason@redhat.com> gcc/cp/ChangeLog: * lambda.c (call_from_lambda_thunk_p): New. * cp-gimplify.c (cp_genericize_r): Use it. * pt.c (tsubst_copy_and_build): Use it. * typeck.c (check_return_expr): Use it. * cp-tree.h: Declare it. (CALL_FROM_NEW_OR_DELETE_P): Move to gcc/tree.h. gcc/ChangeLog: * tree.h (CALL_FROM_NEW_OR_DELETE_P): Move from cp-tree.h. * tree-core.h: Document new usage of protected_flag.
2020-10-02Daily bump.GCC Administrator1-0/+39
2020-10-01c++: Kill DECL_HIDDEN_PNathan Sidwell2-22/+3
There are only a couple of asserts remaining using this macro, and nothing using TYPE_HIDDEN_P. Killed thusly. gcc/cp/ * cp-tree.h (DECL_ANTICIPATED): Adjust comment. (DECL_HIDDEN_P, TYPE_HIDDEN_P): Delete. * tree.c (ovl_insert): Delete DECL_HIDDEN_P assert. (ovl_skip_hidden): Likewise.
2020-10-01c++: pushdecl_top_level must set contextNathan Sidwell3-1/+6
I discovered pushdecl_top_level was not setting the decl's context, and we ended up with namespace-scope decls with NULL context. That broke modules. Then I discovered a couple of places where we set the context to a FUNCTION_DECL, which is also wrong. AFAICT the literals in question belong in global scope, as they're comdatable entities. But create_temporary would use current_scope for the context before we pushed it into namespace scope. This patch asserts the context is NULL and then sets it to the frobbed global_namespace. gcc/cp/ * name-lookup.c (pushdecl_top_level): Assert incoming context is null, add global_namespace context. (pushdecl_top_level_and_finish): Likewise. * pt.c (get_template_parm_object): Clear decl context before pushing. * semantics.c (finish_compound_literal): Likewise.
2020-10-01c++: Refactor lookup_and_check_tagNathan Sidwell1-57/+59
It turns out I'd already found lookup_and_check_tag's control flow confusing, and had refactored it on the modules branch. For instance, it continually checks 'if (decl &&$ condition)' before finally getting to 'else if (!decl)'. why not just check !decl first and be done? Well, it is done thusly. gcc/cp/ * decl.c (lookup_and_check_tag): Refactor.
2020-10-01c++: Fix up default initialization with consteval default ctor [PR96994]Jakub Jelinek1-0/+2
> > The following testcase is miscompiled (in particular the a and i > > initialization). The problem is that build_special_member_call due to > > the immediate constructors (but not evaluated in constant expression mode) > > doesn't create a CALL_EXPR, but returns a TARGET_EXPR with CONSTRUCTOR > > as the initializer for it, > > That seems like the bug; at the end of build_over_call, after you > > > call = cxx_constant_value (call, obj_arg); > > You need to build an INIT_EXPR if obj_arg isn't a dummy. That works. obj_arg is NULL if it is a dummy from the earlier code. 2020-10-01 Jakub Jelinek <jakub@redhat.com> PR c++/96994 * call.c (build_over_call): If obj_arg is non-NULL, return INIT_EXPR setting obj_arg to call. * g++.dg/cpp2a/consteval18.C: New test.
2020-10-01c++: Handle std::construct_at on automatic vars during constant evaluation ↵Jakub Jelinek1-1/+2
[PR97195] As mentioned in the PR, we only support due to a bug in constant expressions std::construct_at on non-automatic variables, because we VERIFY_CONSTANT the second argument of placement new, which fails verification if it is an address of an automatic variable. The following patch fixes it by not performing that verification, the placement new evaluation later on will verify it after it is dereferenced. 2020-10-01 Jakub Jelinek <jakub@redhat.com> PR c++/97195 * constexpr.c (cxx_eval_call_expression): Don't VERIFY_CONSTANT the second argument. * g++.dg/cpp2a/constexpr-new14.C: New test.
2020-09-30c++: CTAD and explicit deduction guides for copy-list-init [PR90210]Marek Polacek1-11/+38
This PR points out that we accept template<typename T> struct tuple { tuple(T); }; // #1 template<typename T> explicit tuple(T t) -> tuple<T>; // #2 tuple t = { 1 }; despite the 'explicit' deduction guide in a copy-list-initialization context. That's because in deduction_guides_for we first find the user-defined deduction guide (#2), and then ctor_deduction_guides_for creates artificial deduction guides: one from the tuple(T) constructor and a copy guide. So we end up with these three guides: (1) template<class T> tuple(T) -> tuple<T> [DECL_NONCONVERTING_P] (2) template<class T> tuple(tuple<T>) -> tuple<T> (3) template<class T> tuple(T) -> tuple<T> Then, in do_class_deduction, we prune this set, and get rid of (1). Then overload resolution selects (3) and we succeed. But [over.match.list]p1 says "In copy-list-initialization, if an explicit constructor is chosen, the initialization is ill-formed." It also goes on to say that this differs from other situations where only converting constructors are considered for copy-initialization. Therefore for list-initialization we consider explicit constructors and complain if one is chosen. E.g. convert_like_internal/ck_user can give an error. So my logic runs that we should not prune the deduction_guides_for guides in a copy-list-initialization context, and only complain if we actually choose an explicit deduction guide. This matches clang++/EDG/msvc++. gcc/cp/ChangeLog: PR c++/90210 * pt.c (do_class_deduction): Don't prune explicit deduction guides in copy-list-initialization. In copy-list-initialization, if an explicit deduction guide was selected, give an error. gcc/testsuite/ChangeLog: PR c++/90210 * g++.dg/cpp1z/class-deduction73.C: New test.
2020-10-01Daily bump.GCC Administrator1-0/+13
2020-09-30c++: Kill DECL_HIDDEN_FRIEND_PNathan Sidwell5-47/+36
Now hiddenness is managed by name-lookup, we no longer need DECL_HIDDEN_FRIEND_P. This removes it. Mainly by deleting its bookkeeping, but there are a couple of uses 1) two name lookups look at it to see if they found a hidden thing. In one we have the OVERLOAD, so can record OVL_HIDDEN_P. In the other we're repeating a lookup that failed, but asking for hidden things -- so if that succeeds we know the thing was hidden. (FWIW CWG recently discussed whether template specializations and instantiations should see such hidden templates anyway, there is compiler divergence.) 2) We had a confusing setting of KOENIG_P when building a non-dependent call. We don't repeat that lookup at instantiation time anyway. gcc/cp/ * cp-tree.h (struct lang_decl_fn): Remove hidden_friend_p. (DECL_HIDDEN_FRIEND_P): Delete. * call.c (add_function_candidate): Drop assert about anticipated decl. (build_new_op_1): Drop koenig lookup flagging for hidden friend. * decl.c (duplicate_decls): Drop HIDDEN_FRIEND_P updating. * name-lookup.c (do_pushdecl): Likewise. (set_decl_namespace): Discover hiddenness from OVL_HIDDEN_P. * pt.c (check_explicit_specialization): Record found_hidden explicitly.
2020-09-30Daily bump.GCC Administrator1-0/+52
2020-09-29c++: Implement -Wrange-loop-construct [PR94695]Marek Polacek3-4/+87
This new warning can be used to prevent expensive copies inside range-based for-loops, for instance: struct S { char arr[128]; }; void fn () { S arr[5]; for (const auto x : arr) { } } where auto deduces to S and then we copy the big S in every iteration. Using "const auto &x" would not incur such a copy. With this patch the compiler will warn: q.C:4:19: warning: loop variable 'x' creates a copy from type 'const S' [-Wrange-loop-construct] 4 | for (const auto x : arr) { } | ^ q.C:4:19: note: use reference type 'const S&' to prevent copying 4 | for (const auto x : arr) { } | ^ | & As per Clang, this warning is suppressed for trivially copyable types whose size does not exceed 64B. The tricky part of the patch was how to figure out if using a reference would have prevented a copy. To that point, I'm using the new function called ref_conv_binds_directly_p. This warning is enabled by -Wall. Further warnings of similar nature should follow soon. gcc/c-family/ChangeLog: PR c++/94695 * c.opt (Wrange-loop-construct): New option. gcc/cp/ChangeLog: PR c++/94695 * call.c (ref_conv_binds_directly_p): New function. * cp-tree.h (ref_conv_binds_directly_p): Declare. * parser.c (warn_for_range_copy): New function. (cp_convert_range_for): Call it. gcc/ChangeLog: PR c++/94695 * doc/invoke.texi: Document -Wrange-loop-construct. gcc/testsuite/ChangeLog: PR c++/94695 * g++.dg/warn/Wrange-loop-construct.C: New test.
2020-09-29c++: Hiddenness is a property of the symbol tableNathan Sidwell5-136/+213
This patch moves the handling of decl-hiddenness entirely into the name lookup machinery, where it belongs. We need a few new flags, because pressing the existing OVL_HIDDEN_P into play for non-function decls doesn't work well. For a local binding we only need one marker, as there cannot be both a hidden implicit typedef and a hidden function. That's not true for namespace-scope, where they could both be hidden. The name-lookup machinery maintains the existing decl_hidden and co flags, and asserts have been sprinkled around to make sure they are consistent. The next series of patches will remove those old markers. (we'll need to keep one, as there are some special restrictions on redeclaring friend functions with in-class definitions or default args.) gcc/cp/ * cp-tree.h (ovl_insert): Change final parm to hidden-or-using indicator. * name-lookup.h (HIDDEN_TYPE_BINDING_P): New. (struct cxx_binding): Add type_is_hidden flag. * tree.c (ovl_insert): Change using_p parm to using_or_hidden, adjust. (ovl_skip_hidden): Assert we never see a naked hidden decl. * decl.c (xref_tag_1): Delete unhiding friend from here (moved to lookup_elaborated_type_1). * name-lookup.c (STAT_TYPE_HIDDEN_P, STAT_DECL_HIDDEN_P): New. (name_lookup::search_namespace_only): Check new hidden markers. (cxx_binding_make): Clear HIDDEN_TYPE_BINDING_P. (update_binding): Update new hidden markers. (lookup_name_1): Check HIDDEN_TYPE_BINDING_P and simplify friend ignoring. (lookup_elaborated_type_1): Use new hidden markers. Reveal the decl here.
2020-09-29c++: Name lookup simplificationsNathan Sidwell2-77/+98
Here are a few cleanups, prior to landing the hidden decl changes. 1) Clear cxx_binding flags in the allocator, not at each user of the allocator. 2) Refactor update_binding. The logic was getting too convoluted. 3) Set friendliness and anticipatedness before pushing a template decl (not after). gcc/cp/ * name-lookup.c (create_local_binding): Do not clear INHERITED_VALUE_BINDING_P here. (name_lookup::process_binding): Move done hidden-decl triage to ... (name_lookup::search_namespace_only): ... here, its only caller. (cxx_binding_make): Clear flags here. (push_binding): Not here. (pop_local_binding): RAII. (update_binding): Refactor. (do_pushdecl): Assert we're never revealing a local binding. (do_pushdecl_with_scope): Directly call do_pushdecl. (get_class_binding): Do not clear LOCAL_BINDING_P here. * pt.c (push_template_decl): Set friend & anticipated before pushing.
2020-09-29c++: Identifier type value should not update bindingNathan Sidwell1-28/+22
This simplification removes some unneeded behaviour in set_identifier_type_value_with_scope, which was updating the namespace binding. And causing update_binding to have to deal with meeting two implicit typedefs. But the typedef is already there, and there's no other way to have two such typedef's collide (we'll already have dealt with that in lookup_elaborated_type). So, let's kill this crufty code. gcc/cp/ * name-lookup.c (update_binding): We never meet two implicit typedefs. (do_pushdecl): Adjust set_identifier_type_value_with_scope calls. (set_identifier_type_value_with_scope): Do not update binding in the namespace-case. Assert it is already there.
2020-09-26Daily bump.GCC Administrator1-0/+66
2020-09-25c++: Adjust pushdecl/duplicate_decls APINathan Sidwell6-62/+81
The decl pushing APIs and duplicate_decls take an 'is_friend' parm, when what they actually mean is 'hide this from name lookup'. That conflation has gotten more anachronistic as time moved on. We now have anticipated builtins, and I plan to have injected extern decls soon. So this patch is mainly a renaming excercise. is_friend -> hiding. duplicate_decls gets an additional 'was_hidden' parm. As I've already said, hiddenness is a property of the symbol table, not the decl. Builtins are now pushed requesting hiding, and pushdecl asserts that we don't attempt to push a thing that should be hidden without asking for it to be hidden. This is the final piece of groundwork to get rid of a bunch of 'this is hidden' markers on decls and move the hiding management entirely into name lookup. gcc/cp/ * cp-tree.h (duplicate_decls): Replace 'is_friend' with 'hiding' and add 'was_hidden'. * name-lookup.h (pushdecl_namespace_level): Replace 'is_friend' with 'hiding'. (pushdecl): Likewise. (pushdecl_top_level): Drop is_friend parm. * decl.c (check_no_redeclaration_friend_default_args): Rename parm olddelc_hidden_p. (duplicate_decls): Replace 'is_friend' with 'hiding' and 'was_hidden'. Do minimal adjustments in body. (cxx_builtin_function): Pass 'hiding' to pushdecl. * friend.c (do_friend): Pass 'hiding' to pushdecl. * name-lookup.c (supplement_binding_1): Drop defaulted arg to duplicate_decls. (update_binding): Replace 'is_friend' with 'hiding'. Drop defaulted arg to duplicate_decls. (do_pushdecl): Replace 'is_friend' with 'hiding'. Assert no surprise hidhing. Adjust duplicate_decls calls to inform of old decl's hiddennes. (pushdecl): Replace 'is_friend' with 'hiding'. (set_identifier_type_value_with_scope): Adjust update_binding call. (do_pushdecl_with_scope): Replace 'is_friend' with 'hiding'. (pushdecl_outermost_localscope): Drop default arg to do_pushdecl_with_scope. (pushdecl_namespace_level): Replace 'is_friend' with 'hiding'. (pushdecl_top_level): Drop is_friend parm. * pt.c (register_specialization): Comment duplicate_decls call args. (push_template_decl): Commont pushdecl_namespace_level. (tsubst_friend_function, tsubst_friend_class): Likewise.
2020-09-25c++: Replace tag_scope with TAG_howNathan Sidwell5-94/+82
I always found tag_scope confusing, as it is not a scope, but a direction of how to lookup or insert an elaborated type tag. This replaces it with a enum class TAG_how. I also add a new value, HIDDEN_FRIEND, to distinguish the two cases of innermost-non-class insertion that we currently conflate. Also renamed 'lookup_type_scope' to 'lookup_elaborated_type', because again, we're not providing a scope to lookup in. gcc/cp/ * name-lookup.h (enum tag_scope): Replace with ... (enum class TAG_how): ... this. Add HIDDEN_FRIEND value. (lookup_type_scope): Replace with ... (lookup_elaborated_type): ... this. (pushtag): Use TAG_how, not tag_scope. * cp-tree.h (xref_tag): Parameter is TAG_how, not tag_scope. * decl.c (lookup_and_check_tag): Likewise. Adjust. (xref_tag_1, xref_tag): Likewise. adjust. (start_enum): Adjust lookup_and_check_tag call. * name-lookup.c (lookup_type_scope_1): Rename to ... (lookup_elaborated_type_1) ... here. Use TAG_how, not tag_scope. (lookup_type_scope): Rename to ... (lookup_elaborated_type): ... here. Use TAG_how, not tag_scope. (do_pushtag): Use TAG_how, not tag_scope. Adjust. (pushtag): Likewise. * parser.c (cp_parser_elaborated_type_specifier): Adjust. (cp_parser_class_head): Likewise. gcc/objcp/ * objcp-decl.c (objcp_start_struct): Use TAG_how not tag_scope. (objcp_xref_tag): Likewise.
2020-09-25c++: DECL_BUILTIN_P for builtinsNathan Sidwell5-28/+32
We currently detect builtin decls via DECL_ARTIFICIAL && !DECL_HIDDEN_FUNCTION_P, which, besides being clunky, is a problem as hiddenness is a property of the symbol table -- not the decl being hidden. This adds DECL_BUILTIN_P, which just looks at the SOURCE_LOCATION -- we have a magic one for builtins. One of the consequential changes is to make function-scope omp udrs have function context (needed because otherwise duplicate-decls thinks the types don't match at the point we check). This is also morally better, because that's what they are -- nested functions, stop lying. (That's actually my plan for all DECL_LOCAL_DECL_P decls, as they are distinct decls to the namespace-scope decl they alias.) gcc/cp/ * cp-tree.h (DECL_BUILTIN_P): New. * decl.c (duplicate_decls): Use it. Do not treat omp-udr as a builtin. * name-lookup.c (anticipated_builtin): Use it. (set_decl_context_in_fn): Function-scope OMP UDRs have function context. (do_nonmember_using_decl): Use DECL_BUILTIN_P. * parser.c (cp_parser_omp_declare_reduction): Function-scope OMP UDRs have function context. Assert we never find a valid duplicate. * pt.c (tsubst_expr): Function-scope OMP UDRs have function context. libcc1/ * libcp1plugin.cc (supplement_binding): Use DECL_BULTIN_P.
2020-09-25Daily bump.GCC Administrator1-0/+40
2020-09-24c++: Cleanup some decl pushing apisNathan Sidwell11-47/+41
In cleaning up local decl handling, here's an initial patch that takes advantage of C++'s default args for the is_friend parm of pushdecl, duplicate_decls and push_template_decl_real and the scope & tpl_header parms of xref_tag. Then many of the calls simply not mention these. I also rename push_template_decl_real to push_template_decl, deleting the original forwarding function. This'll make my later patches changing their types less intrusive. There are 2 functional changes: 1) push_template_decl requires is_friend to be correct, it doesn't go checking for a friend function (an assert is added). 2) debug_overload prints out Hidden and Using markers for the overload set. gcc/cp/ * cp-tree.h (duplicate_decls): Default is_friend to false. (xref_tag): Default tag_scope & tpl_header_p to ts_current & false. (push_template_decl_real): Default is_friend to false. Rename to ... (push_template_decl): ... here. Delete original decl. * name-lookup.h (pushdecl_namespace_level): Default is_friend to false. (pushtag): Default tag_scope to ts_current. * coroutines.cc (morph_fn_to_coro): Drop default args to xref_tag. * decl.c (start_decl): Drop default args to duplicate_decls. (start_enum): Drop default arg to pushtag & xref_tag. (start_preparsed_function): Pass DECL_FRIEND_P to push_template_decl. (grokmethod): Likewise. * friend.c (do_friend): Rename push_template_decl_real calls. * lambda.c (begin_lamnbda_type): Drop default args to xref_tag. (vla_capture_type): Likewise. * name-lookup.c (maybe_process_template_type_declaration): Rename push_template_decl_real call. (pushdecl_top_level_and_finish): Drop default arg to pushdecl_namespace_level. * pt.c (push_template_decl_real): Assert no surprising friend functions. Rename to ... (push_template_decl): ... here. Delete original function. (lookup_template_class_1): Drop default args from pushtag. (instantiate_class_template_1): Likewise. * ptree.c (debug_overload): Print hidden and using markers. * rtti.c (init_rtti_processing): Drop refault args from xref_tag. (build_dynamic_cast_1, tinfo_base_init): Likewise. * semantics.c (begin_class_definition): Drop default args to pushtag. gcc/objcp/ * objcp-decl.c (objcp_start_struct): Drop default args to xref_tag. (objcp_xref_tag): Likewise. libcc1/ * libcp1plugin.cc (supplement_binding): Drop default args to duplicate_decls. (safe_pushtag): Drop scope parm. Drop default args to pushtag. (safe_pushdecl_maybe_friend): Rename to ... (safe_pushdecl): ... here. Drop is_friend parm. Drop default args to pushdecl. (plugin_build_decl): Adjust safe_pushdecl & safe_pushtag calls. (plugin_build_constant): Adjust safe_pushdecl call.