aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
AgeCommit message (Collapse)AuthorFilesLines
2023-04-26c++: unique friend shenanigans [PR69836]Jason Merrill1-0/+6
Normally we re-instantiate a function declaration when we start to instantiate the body in case of multiple declarations. In this wacky testcase, this causes a problem because the type of the w_counter parameter depends on its declaration not being in scope yet, so the name lookup only finds the previous declaration. This isn't a problem for member functions, since they aren't subject to argument-dependent lookup. So let's just skip the regeneration for hidden friends. PR c++/69836 gcc/cp/ChangeLog: * pt.cc (regenerate_decl_from_template): Skip unique friends. gcc/testsuite/ChangeLog: * g++.dg/template/friend76.C: New test.
2023-04-26c++: micro-optimize most_specialized_partial_specPatrick Palka1-26/+19
This introduces an early exit test to most_specialized_partial_spec for templates which have no partial specializations, saving some unnecessary work during class template instantiation in the common case. In passing, modernize the code a bit. gcc/cp/ChangeLog: * pt.cc (most_specialized_partial_spec): Exit early when DECL_TEMPLATE_SPECIALIZATIONS is empty. Move local variable declarations closer to their first use. Remove redundant flag_concepts test. Remove redundant forward declaration.
2023-04-26Daily bump.GCC Administrator1-0/+12
2023-04-25c++: value dependence of by-ref lambda capture [PR108975]Patrick Palka1-3/+4
We are still ICEing on the generic lambda version of the testcase from this PR, even after r13-6743-g6f90de97634d6f, due to the by-ref capture of the constant local variable 'dim' being considered value-dependent when regenerating the lambda (at which point processing_template_decl is set since the lambda is generic), which prevents us from constant folding its uses. Later during prune_lambda_captures we end up not thoroughly walking the body of the lambda and overlook the (non-folded) uses of 'dim' within the array bound and using-decls. We could fix this by making prune_lambda_captures walk the body of the lambda more thoroughly so that it finds these uses of 'dim', but ideally we should be able to constant fold all uses of 'dim' ahead of time and prune the implicit capture after all. To that end this patch makes value_dependent_expression_p return false for such by-ref captures of constant local variables, allowing their uses to get constant folded ahead of time. It seems we just need to disable the predicate's conservative early exit for reference variables (added by r5-5022-g51d72abe5ea04e) when DECL_HAS_VALUE_EXPR_P. This effectively makes us treat by-value and by-ref captures more consistently when it comes to value dependence. PR c++/108975 gcc/cp/ChangeLog: * pt.cc (value_dependent_expression_p) <case VAR_DECL>: Suppress conservative early exit for reference variables when DECL_HAS_VALUE_EXPR_P. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/lambda/lambda-const11a.C: New test.
2023-04-25'omp scan' struct block seq update for OpenMP 5.xTobias Burnus1-3/+21
While OpenMP 5.0 required a single structured block before and after the 'omp scan' directive, OpenMP 5.1 changed this to a 'structured block sequence, denoting 2 or more executable statements in OpenMP 5.1 (whoops!) and zero or more in OpenMP 5.2. This commit updates C/C++ to accept zero statements (but till requires the '{' ... '}' for the final-loop-body) and updates Fortran to accept zero or more than one statements. If there is no preceeding or succeeding executable statement, a warning is shown. gcc/c/ChangeLog: * c-parser.cc (c_parser_omp_scan_loop_body): Handle zero exec statements before/after 'omp scan'. gcc/cp/ChangeLog: * parser.cc (cp_parser_omp_scan_loop_body): Handle zero exec statements before/after 'omp scan'. gcc/fortran/ChangeLog: * openmp.cc (gfc_resolve_omp_do_blocks): Handle zero or more than one exec statements before/after 'omp scan'. * trans-openmp.cc (gfc_trans_omp_do): Likewise. libgomp/ChangeLog: * testsuite/libgomp.c-c++-common/scan-1.c: New test. * testsuite/libgomp.c/scan-23.c: New test. * testsuite/libgomp.fortran/scan-2.f90: New test. gcc/testsuite/ChangeLog: * g++.dg/gomp/attrs-7.C: Update dg-error/dg-warning. * gfortran.dg/gomp/loop-2.f90: Likewise. * gfortran.dg/gomp/reduction5.f90: Likewise. * gfortran.dg/gomp/reduction6.f90: Likewise. * gfortran.dg/gomp/scan-1.f90: Likewise. * gfortran.dg/gomp/taskloop-2.f90: Likewise. * c-c++-common/gomp/scan-6.c: New test. * gfortran.dg/gomp/scan-8.f90: New test.
2023-04-25Daily bump.GCC Administrator1-0/+5
2023-04-24c++, tree: declare some basic functions inlinePatrick Palka2-25/+25
The functions strip_array_types, is_typedef_decl, typedef_variant_p and cp_expr_location are used throughout the C++ front end including in some fairly hot parts (e.g. in the tsubst routines and cp_walk_subtree) and they're small enough that the overhead of calling them out-of-line is relatively significant. So this patch moves their definitions into the appropriate headers to enable inlining them. gcc/cp/ChangeLog: * cp-tree.h (cp_expr_location): Define here. * tree.cc (cp_expr_location): Don't define here. gcc/ChangeLog: * tree.cc (strip_array_types): Don't define here. (is_typedef_decl): Don't define here. (typedef_variant_p): Don't define here. * tree.h (strip_array_types): Define here. (is_typedef_decl): Define here. (typedef_variant_p): Define here.
2023-04-22Daily bump.GCC Administrator1-0/+13
2023-04-21c++: fix 'unsigned typedef-name' extension [PR108099]Jason Merrill1-10/+8
In the comments for PR108099 Jakub provided some testcases that demonstrated that even before the regression noted in the patch we were getting the semantics of this extension wrong: in the unsigned case we weren't producing the corresponding standard unsigned type but another distinct one of the same size, and in the signed case we were just dropping it on the floor and not actually returning a signed type at all. The former issue is fixed by using c_common_signed_or_unsigned_type instead of unsigned_type_for, and the latter issue by adding a (signed_p && typedef_decl) case. This patch introduces a failure on std/ranges/iota/max_size_type.cc due to the latter issue, since the testcase expects 'signed rep_t' to do something sensible, and previously we didn't. Now that we do, it exposes a bug in the __max_diff_type::operator>>= handling of sign extension: when we evaluate -1000 >> 2 in __max_diff_type we keep the MSB set, but leave the second-most-significant bit cleared. PR c++/108099 gcc/cp/ChangeLog: * decl.cc (grokdeclarator): Don't clear typedef_decl after 'unsigned typedef' pedwarn. Use c_common_signed_or_unsigned_type. Also handle 'signed typedef'. gcc/testsuite/ChangeLog: * g++.dg/ext/int128-8.C: Remove xfailed dg-bogus markers. * g++.dg/ext/unsigned-typedef2.C: New test. * g++.dg/ext/unsigned-typedef3.C: New test.
2023-04-21c++, tree: optimize walk_tree_1 and cp_walk_subtreesPatrick Palka1-66/+68
These functions currently repeatedly dereference tp during the subtree walks, dereferences which the compiler can't CSE because it can't guarantee that the subtree walking doesn't modify *tp. But we already implicitly require that TREE_CODE (*tp) remains the same throughout the subtree walks, so it doesn't seem to be a huge leap to strengthen that to requiring *tp remains the same. So this patch manually CSEs the dereferences of *tp. This means that a callback function can no longer replace *tp with another tree (of the same TREE_CODE) when walking one of its subtrees, but that doesn't sound like a useful capability anyway. gcc/cp/ChangeLog: * tree.cc (cp_walk_subtrees): Avoid repeatedly dereferencing tp. <case DECLTYPE_TYPE>: Use cp_unevaluated and WALK_SUBTREE. <case ALIGNOF_EXPR etc>: Likewise. gcc/ChangeLog: * tree.cc (walk_tree_1): Avoid repeatedly dereferencing tp and type_p.
2023-04-21Daily bump.GCC Administrator1-0/+37
2023-04-20c++: simplify TEMPLATE_TYPE_PARM level loweringPatrick Palka1-21/+16
1. Don't bother recursing when level lowering a cv-qualified type template parameter. 2. Get rid of the recursive loop breaker when level lowering a constrained auto, and enable the TEMPLATE_PARM_DESCENDANTS cache in this case too. This should be safe to do so now that we no longer substitute constraints on an auto. gcc/cp/ChangeLog: * pt.cc (tsubst) <case TEMPLATE_TYPE_PARM>: Don't recurse when level lowering a cv-qualified type template parameter. Remove recursive loop breaker in the level lowering case for constrained autos. Use the TEMPLATE_PARM_DESCENDANTS cache in this case as well.
2023-04-20c++: use TREE_VEC for trailing args of variadic built-in traitsPatrick Palka6-28/+43
This patch makes us use TREE_VEC instead of TREE_LIST to represent the trailing arguments of a variadic built-in trait. These built-ins are typically passed a simple pack expansion as the second argument, e.g. __is_constructible(T, Ts...) and the main benefit of this representation change is that substituting into this argument list is now basically free since tsubst_template_args makes sure we reuse the TREE_VEC of the corresponding ARGUMENT_PACK when expanding such a pack expansion. In the previous TREE_LIST representation we would need need to convert the expanded pack expansion into a TREE_LIST (via tsubst_tree_list). Note that an empty set of trailing arguments is now represented as an empty TREE_VEC instead of NULL_TREE, so now TRAIT_TYPE/EXPR_TYPE2 will be empty only for unary traits. gcc/cp/ChangeLog: * constraint.cc (diagnose_trait_expr): Convert a TREE_VEC of arguments into a TREE_LIST for sake of pretty printing. * cxx-pretty-print.cc (pp_cxx_trait): Handle TREE_VEC instead of TREE_LIST of trailing variadic trait arguments. * method.cc (constructible_expr): Likewise. (is_xible_helper): Likewise. * parser.cc (cp_parser_trait): Represent trailing variadic trait arguments as a TREE_VEC instead of TREE_LIST. * pt.cc (value_dependent_expression_p): Handle TREE_VEC instead of TREE_LIST of trailing variadic trait arguments. * semantics.cc (finish_type_pack_element): Likewise. (check_trait_type): Likewise.
2023-04-20c++: make strip_typedefs generalize strip_typedefs_exprPatrick Palka1-59/+25
Currently if we have a TREE_VEC of types that we want to strip of typedefs, we unintuitively need to call strip_typedefs_expr instead of strip_typedefs since only strip_typedefs_expr handles TREE_VEC, and it also dispatches to strip_typedefs when given a type. But this seems backwards: arguably strip_typedefs_expr should be the more specialized function, which strip_typedefs dispatches to (and thus generalizes). So this patch makes strip_typedefs subsume strip_typedefs_expr rather than vice versa, which allows for some simplifications. gcc/cp/ChangeLog: * tree.cc (strip_typedefs): Move TREE_LIST handling to strip_typedefs_expr. Dispatch to strip_typedefs_expr for non-type 't'. <case TYPENAME_TYPE>: Remove manual dispatching to strip_typedefs_expr. <case TRAIT_TYPE>: Likewise. (strip_typedefs_expr): Replaces calls to strip_typedefs_expr with strip_typedefs throughout. Don't dispatch to strip_typedefs for type 't'. <case TREE_LIST>: Replace this with the better version from strip_typedefs.
2023-04-20Daily bump.GCC Administrator1-0/+33
2023-04-19c++: Define built-in for std::tuple_element [PR100157]Patrick Palka8-20/+107
This adds a new built-in to replace the recursive class template instantiations done by traits such as std::tuple_element and std::variant_alternative. The purpose is to select the Nth type from a list of types, e.g. __type_pack_element<1, char, int, float> is int. We implement it as a special kind of TRAIT_TYPE. For a pathological example tuple_element_t<1000, tuple<2000 types...>> the compilation time is reduced by more than 90% and the memory used by the compiler is reduced by 97%. In realistic examples the gains will be much smaller, but still relevant. Unlike the other built-in traits, __type_pack_element uses template-id syntax instead of call syntax and is SFINAE-enabled, matching Clang's implementation. And like the other built-in traits, it's not mangleable so we can't use it directly in function signatures. N.B. Clang seems to implement __type_pack_element as a first-class template that can e.g. be used as a template-template argument. For simplicity we implement it in a more ad-hoc way. Co-authored-by: Jonathan Wakely <jwakely@redhat.com> PR c++/100157 gcc/cp/ChangeLog: * cp-trait.def (TYPE_PACK_ELEMENT): Define. * cp-tree.h (finish_trait_type): Add complain parameter. * cxx-pretty-print.cc (pp_cxx_trait): Handle CPTK_TYPE_PACK_ELEMENT. * parser.cc (cp_parser_constant_expression): Document default arguments. (cp_parser_trait): Handle CPTK_TYPE_PACK_ELEMENT. Pass tf_warning_or_error to finish_trait_type. * pt.cc (tsubst) <case TRAIT_TYPE>: Handle non-type first argument. Pass complain to finish_trait_type. * semantics.cc (finish_type_pack_element): Define. (finish_trait_type): Add complain parameter. Handle CPTK_TYPE_PACK_ELEMENT. * tree.cc (strip_typedefs): Handle non-type first argument. Pass tf_warning_or_error to finish_trait_type. * typeck.cc (structural_comptypes) <case TRAIT_TYPE>: Use cp_tree_equal instead of same_type_p for the first argument. libstdc++-v3/ChangeLog: * include/bits/utility.h (_Nth_type): Conditionally define in terms of __type_pack_element if available. * testsuite/20_util/tuple/element_access/get_neg.cc: Prune additional errors from the new built-in. gcc/testsuite/ChangeLog: * g++.dg/ext/type_pack_element1.C: New test. * g++.dg/ext/type_pack_element2.C: New test. * g++.dg/ext/type_pack_element3.C: New test.
2023-04-19c++: bad ggc_free in try_class_unification [PR109556]Patrick Palka1-5/+0
Aside from correcting how try_class_unification copies multi-dimensional 'targs', r13-377-g3e948d645bc908 also made it ggc_free this copy as an optimization. But this is wrong since the call to unify within might've captured the args in persistent memory such as the satisfaction cache (as part of constrained auto deduction). PR c++/109556 gcc/cp/ChangeLog: * pt.cc (try_class_unification): Don't ggc_free the copy of 'targs'. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-placeholder13.C: New test.
2023-04-19c++: fix 'unsigned __int128_t' semantics [PR108099]Jason Merrill1-2/+4
My earlier patch for 108099 made us accept this non-standard pattern but messed up the semantics, so that e.g. unsigned __int128_t was not a 128-bit type. PR c++/108099 gcc/cp/ChangeLog: * decl.cc (grokdeclarator): Keep typedef_decl for __int128_t. gcc/testsuite/ChangeLog: * g++.dg/ext/int128-8.C: New test.
2023-04-18Daily bump.GCC Administrator1-0/+7
2023-04-17c++: bound ttp level lowering [PR109531]Patrick Palka1-19/+20
Here when level lowering the bound ttp TT<typename T::type> via the substitution T=C, we're neglecting to canonicalize (and thereby strip of simple typedefs) the substituted template arguments {A<int>} before determining the new canonical type via hash table lookup. This leads to a hash mismatch ICE for the two equivalent types TT<int> and TT<A<int>> since iterative_hash_template_arg assumes type arguments are already canonicalized. We can fix this by canonicalizing or coercing the substituted arguments directly, but seeing as creation and ordinary substitution of bound ttps both go through lookup_template_class, which in turn performs the desired coercion/canonicalization, it seems preferable to make this code path go through lookup_template_class as well. PR c++/109531 gcc/cp/ChangeLog: * pt.cc (tsubst) <case BOUND_TEMPLATE_TEMPLATE_PARM>: In the level-lowering case just use lookup_template_class to rebuild the bound ttp. gcc/testsuite/ChangeLog: * g++.dg/template/canon-type-20.C: New test. * g++.dg/template/ttp36.C: New test.
2023-04-16Daily bump.GCC Administrator1-0/+6
2023-04-15c++: constexpr aggregate destruction [PR109357]Jason Merrill1-4/+11
We were assuming that the result of evaluation of TARGET_EXPR_INITIAL would always be the new value of the temporary, but that's not necessarily true when the initializer is complex (i.e. target_expr_needs_replace). In that case evaluating the initializer initializes the temporary as a side-effect. PR c++/109357 gcc/cp/ChangeLog: * constexpr.cc (cxx_eval_constant_expression) [TARGET_EXPR]: Check for complex initializer. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/constexpr-dtor15.C: New test.
2023-04-14Daily bump.GCC Administrator1-0/+20
2023-04-13c++: 'typename T::X' vs 'struct T::X' lookup [PR109420]Patrick Palka2-2/+19
r13-6098-g46711ff8e60d64 made make_typename_type no longer ignore non-types during the lookup, unless the TYPENAME_TYPE in question was followed by the :: scope resolution operator. But there is another exception to this rule: we need to ignore non-types during the lookup also if the TYPENAME_TYPE was named with a tag other than 'typename', such as 'struct' or 'enum', since in that case we're dealing with an elaborated-type-specifier and so [basic.lookup.elab] applies. This patch implements this additional exception. PR c++/109420 gcc/cp/ChangeLog: * decl.cc (make_typename_type): Also ignore non-types during the lookup if tag_type corresponds to an elaborated-type-specifier. * pt.cc (tsubst) <case TYPENAME_TYPE>: Pass class_type or enum_type as tag_type to make_typename_type accordingly instead of always passing typename_type. gcc/testsuite/ChangeLog: * g++.dg/template/typename27.C: New test.
2023-04-13c++: make trait of incomplete type a permerror [PR109277]Jason Merrill2-5/+6
An incomplete type argument to several traits is specified to be undefined behavior in the library; since it's a compile-time property, we diagnose it. But apparently some code was relying on the previous behavior of not diagnosing. So let's make it a permerror. The assert in cxx_incomplete_type_diagnostic didn't like that, and I don't see the point of having the assert, so let's just remove it. PR c++/109277 gcc/cp/ChangeLog: * semantics.cc (check_trait_type): Handle incomplete type directly. * typeck2.cc (cxx_incomplete_type_diagnostic): Remove assert. gcc/testsuite/ChangeLog: * g++.dg/ext/is_convertible5.C: New test.
2023-04-13c++: make cxx_incomplete_type_diagnostic return boolJason Merrill2-20/+22
Like other diagnostic functions that might be silenced by options, it should return whether or not it actually emitted a diagnostic. gcc/cp/ChangeLog: * typeck2.cc (cxx_incomplete_type_diagnostic): Return bool. * cp-tree.h (cxx_incomplete_type_diagnostic): Adjust.
2023-04-13Daily bump.GCC Administrator1-0/+8
2023-04-12c++: Fix Solaris bootstraps across midnightJakub Jelinek1-6/+15
When working on the PR109040 fix, I wanted to test it on some WORD_REGISTER_OPERATIONS target and tried sparc-solaris on GCC Farm. My bootstrap failed in comparison failure on cp/module.o, because Solaris date doesn't support the -r option and one stage's cp/module.o was built before midnight and next stage's cp/module.o after midnight, so they had different -DMODULE_VERSION= value. Now, I think the advice (don't bootstrap at midnight) is something we shouldn't have, so the following patch stores the module version (still generated through the same way, date -r cp/module.cc if it works, otherwise just date) into a temporary file, makes sure that temporary file is updated when cp/module.cc source is updated and when date -r doesn't work copies file from previous stage if it is newer than cp/module.cc. 2023-04-12 Jakub Jelinek <jakub@redhat.com> * Make-lang.in (s-cp-module-version): New target. (cp/module.o): Depend on it. (MODULE_VERSION): Remove variable. (CFLAGS-cp/module.o): For -DMODULE_VERSION= argument just cat s-cp-module-version.
2023-04-10Daily bump.GCC Administrator1-0/+5
2023-04-09c++, coroutines: Fix block nests when the function has no top-level bind.Iain Sandoe1-0/+4
When the function contains no local vars and also no nested scopes, there is no top-level bind expression. Because the rewritten coroutine body will require both local vars and contain nested scopes, we add a bind expression to such functions. When this was done the necessary scope blocks were omitted which leads to disconnected function content. Fixed by adding a new block to the added bind expression. Signed-off-by: Iain Sandoe <iain@sandoe.co.uk> gcc/cp/ChangeLog: * coroutines.cc (coro_rewrite_function_body): Ensure that added bind expressions have scope blocks.
2023-04-05Daily bump.GCC Administrator1-0/+5
2023-04-03c++: friend template matching [PR107484]Jason Merrill1-0/+5
Here friend matching tries to find a matching non-template friend and fails, so we mark the friend as a template specialization to be determined later. Then cplus_decl_attributes tries again to find a matching function and gets confused by DECL_TEMPLATE_INSTANTIATION without DECL_TEMPLATE_INFO. But it doesn't make sense for find_last_decl to be trying to match anything with DECL_USE_TEMPLATE set; those are matched elsewhere. PR c++/107484 gcc/cp/ChangeLog: * decl2.cc (find_last_decl): Return early if DECL_USE_TEMPLATE. gcc/testsuite/ChangeLog: * g++.dg/lookup/friend25.C: New test.
2023-04-04Daily bump.GCC Administrator1-0/+6
2023-04-03c++: ICE with loopy var tmpl auto deduction [PR109300]Patrick Palka1-1/+14
Now that we resolve non-dependent variable template-ids ahead of time, cp_finish_decl needs to handle a new invalid situation: we can end up trying to instantiate a variable template with deduced type before we fully parsed its initializer. PR c++/109300 gcc/cp/ChangeLog: * decl.cc (cp_finish_decl): Diagnose ordinary auto deduction with no initializer, instead of asserting. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/var-templ79.C: New test.
2023-04-02Daily bump.GCC Administrator1-0/+31
2023-04-01c++: NTTP constraint depending on outer parms [PR109160]Patrick Palka2-11/+24
Here we're crashing during satisfaction for the NTTP 'C<B> auto V' ultimately because convert_template_argument / unify don't pass all outer template arguments to do_auto_deduction, and during satisfaction we need to know all arguments. While these callers do pass some outer arguments, they are only sufficient to properly substitute the (level-lowered) 'auto' and are not necessarily the entire set. Fortunately it seems these callers have access to the full set of outer arguments via convert_template_argument's 'in_decl' parameter and unify's 'tparms' parameter. So this patch adds a new parameter to do_auto_deduction, used only during adc_unify deduction, through which these callers can pass the enclosing (partially instantiated) template and from which do_auto_deduction can obtain _all_ outer template arguments for sake of satisfaction. This patch also ensures that the 'in_decl' argument passed to coerce_template_parms is always a TEMPLATE_DECL, which in turn allows us to pass it as-is to do_auto_deduction; the only coerce_template_parms caller that needed adjustment was tsubst_decl it seems. PR c++/109160 gcc/cp/ChangeLog: * cp-tree.h (do_auto_deduction): Add defaulted tmpl parameter. * pt.cc (convert_template_argument): Pass 'in_decl' as 'tmpl' to do_auto_deduction. (tsubst_decl) <case VAR_/TYPE_DECL>: Pass 'tmpl' instead of 't' as 'in_decl' to coerce_template_parms. (unify) <case TEMPLATE_PARM_INDEX>: Pass TPARMS_PRIMARY_TEMPLATE as 'tmpl' to do_auto_deduction. (do_auto_deduction): Document default arguments. Rename local variable 'tmpl' to 'ctmpl'. Use 'tmpl' to obtain a full set of template arguments for satisfaction in the adc_unify case. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-placeholder12.C: New test.
2023-04-01c++: improve "NTTP argument considered unused" fix [PR53164, PR105848]Patrick Palka1-18/+68
r13-995-g733a792a2b2e16 worked around the problem of (pointer to) function NTTP arguments not always getting marked as odr-used, by redundantly calling mark_used on the substituted ADDR_EXPR callee of a CALL_EXPR. That is just a narrow workaround however, since it assumes the function is later called, but the use as a template argument alone should constitute an odr-use of the function (since template arguments are an evaluated context, and we're really passing its address); we shouldn't need to subsequently call or otherwise use the function NTTP argument. This patch fixes this in a more general way by walking the template arguments of each specialization that's about to be instantiated and redundantly calling mark_used on all entities used within. As before, the call to mark_used as it worst a no-op, but it compensates for the situation where the specialization was first formed in a template context in which mark_used is inhibited. Another approach would be to call mark_used whenever we substitute a TEMPLATE_PARM_INDEX, but that would result in many more redundant calls to mark_used compared to this approach. And as the second testcase below illustrates, we also need to walk C++20 class NTTP arguments which can be large and thus expensive to walk repeatedly. The change to invalid_tparm_referent_p is needed to avoid incorrectly rejecting class NTTP arguments containing function pointers as in the testcase. (The third testcase is unrelated to this fix, but it helped rule out an earlier approach I was considering and it seems we don't have existing test coverage for this situation.) PR c++/53164 PR c++/105848 gcc/cp/ChangeLog: * pt.cc (invalid_tparm_referent_p): Accept ADDR_EXPR of FUNCTION_DECL. (instantiate_class_template): Call mark_template_arguments_used. (tsubst_copy_and_build) <case CALL_EXPR>: Revert r13-995 change. (mark_template_arguments_used): Define. (instantiate_body): Call mark_template_arguments_used. gcc/testsuite/ChangeLog: * g++.dg/template/fn-ptr3a.C: New test. * g++.dg/template/fn-ptr3b.C: New test. * g++.dg/template/fn-ptr4.C: New test.
2023-04-01c++,coroutines: Stabilize names of promoted slot vars [PR101118].Iain Sandoe1-1/+1
When we need to 'promote' a value (i.e. store it in the coroutine frame) it is given a frame entry name. This was based on the DECL_UID for slot vars. However, when LTO is used, the names from multiple TUs become visible at the same time, and the DECL_UIDs usually differ between units. This leads to a "ODR mismatch" warning for the frame type. The fix here is to use the current promoted temporaries count to produce the name, this is stable between TUs and computed per coroutine. Signed-off-by: Iain Sandoe <iain@sandoe.co.uk> PR c++/101118 gcc/cp/ChangeLog: * coroutines.cc (flatten_await_stmt): Use the current count of promoted temporaries to build a unique name for the frame entries.
2023-03-31Daily bump.GCC Administrator1-0/+36
2023-03-30c++: anonymous union member reference [PR105452]Jason Merrill4-3/+28
While parsing the anonymous union, we don't yet know that it's an anonymous union, so we build the reference to 'v' in the static_assert relative to the union type. But at instantiation time we know it's an anonymous union, so we need to avoid trying to check access for 'v' in the union again; the simplest approach seemed to be to make accessible_p step out to the containing class. While looking at this I also noticed that we were having trouble with DMI in an anonymous union referring to members of the containing class; there we just need to give current_class_ptr the right type. PR c++/105452 gcc/cp/ChangeLog: * search.cc (type_context_for_name_lookup): New. (accessible_p): Handle anonymous union. * init.cc (maybe_instantiate_nsdmi_init): Use type_context_for_name_lookup. * parser.cc (cp_parser_class_specifier): Likewise. * cp-tree.h (type_context_for_name_lookup): Declare. gcc/testsuite/ChangeLog: * g++.dg/lookup/anon8.C: New test.
2023-03-30c++: generic lambda and function ptr conv [PR105221]Jason Merrill1-3/+30
We weren't properly considering the function pointer conversions in deduction between FUNCTION_TYPE; we just hardcoded the UNIFY_ALLOW_MORE_CV_QUAL semantics, which are backwards when deducing for a template conversion function like the one in a generic lambda. And when I started checking the ALLOW flags, I needed to make sure they stay set to avoid breaking trailing13.C. PR c++/105221 gcc/cp/ChangeLog: * pt.cc (unify) [FUNCTION_TYPE]: Handle function pointer conversions. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/noexcept-type27.C: New test.
2023-03-30c++: Fix up ICE in build_min_non_dep_op_overload [PR109319]Jakub Jelinek1-5/+26
The following testcase ICEs, because grok_array_decl during processing_template_decl handling of a non-dependent subscript emits a -Wcomma-subscript pedwarn, we decide to pass to the single index argument the index expressions as if it was wrapped with () around it, but then when preparing it for later instantiation we don't actually take that into account and ICE on a mismatch of number of index arguments (the overload expects a single index, testcase has two index expressions in this case). For non-dependent subscript which are builtin subscripts we also emit the same pedwarn and don't ICE, but emit the same pedwarn again whenever we instantiate it, which is also IMHO undesirable, it is enough to warn once during parsing the template. The following patch fixes it by turning even the original index expressions (those which didn't go through make_args_non_dependent) into a single index using comma expression(s). 2023-03-30 Jakub Jelinek <jakub@redhat.com> PR c++/109319 * decl2.cc (grok_array_decl): After emitting a pedwarn for -Wcomma-subscript, if processing_template_decl set orig_index_exp to compound expr from orig_index_exp_list. * g++.dg/cpp23/subscript14.C: New test.
2023-03-30c++: lambda mangling alias issues [PR107897]Jason Merrill1-5/+14
In 107897, by the time we are looking at the mangling clash, the alias has already been removed from the symbol table by analyze_functions, so we can't look at n->cpp_implicit_alias. So just assume that it's an alias if it's internal. In 108887 the problem is that removing the mangling alias from the symbol table confuses analyze_functions, because it ended up as first_analyzed somehow, so it becomes a dangling pointer. So instead we call reset() to neutralize the alias. To make this work for variables, I needed to move reset() from cgraph_node to symtab_node. PR c++/107897 PR c++/108887 gcc/ChangeLog: * cgraph.h: Move reset() from cgraph_node to symtab_node. * cgraphunit.cc (symtab_node::reset): Adjust. Also call remove_from_same_comdat_group. gcc/cp/ChangeLog: * decl2.cc (record_mangling): Use symtab_node::reset. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-lambda3.C: Use -flto if supported. * g++.dg/cpp0x/lambda/lambda-mangle7.C: New test.
2023-03-30c++: Avoid informs without a warning [PR109278]Jakub Jelinek1-8/+12
On the following testcase we emit notes in maybe_inform_about_fndecl_for_bogus_argument_init despite no warning/error being printed before it. This is for the extended floating point type conversions where pedwarn is used, and complained is used there for 2 different purposes, one is whether an unspecific error should be emitted if we haven't complained otherwise, and one whether maybe_inform_about_fndecl_for_bogus_argument_init should be called. For the 2 pedwarns, currently it sets complained to true regardless of whether pedwarn succeeded, which results in the undesirable notes printed with -w. If complained is initialized to result of pedwarn, we would emit an error later on. So, the following patch makes complained a tristate, the additional error isn't printed if complained != 0, and maybe_inform_about_fndecl_for_bogus_argument_init is called only if complained == 1, so if pedwarn returns false, we can use complained = -1 to tell later code not to emit an error and not to call maybe_inform_about_fndecl_for_bogus_argument_init. 2023-03-30 Jakub Jelinek <jakub@redhat.com> PR c++/109278 * call.cc (convert_like_internal): If pedwarn for extended float type conversions doesn't report anything, avoid calling maybe_inform_about_fndecl_for_bogus_argument_init. * g++.dg/cpp23/ext-floating15.C: New test.
2023-03-30Daily bump.GCC Administrator1-0/+7
2023-03-28c++: alias ctad refinements [PR109321]Jason Merrill1-14/+48
The two hunks fix missing handling demonstrated by the two testcases: first, if we omit one alias template parm but include another, we need to rewrite the deduced template args to reflect the new position of the included parm. Second, if we can't deduce any template args for a parameter pack, it is deduced to an empty pack. PR c++/109321 PR c++/109320 gcc/cp/ChangeLog: * pt.cc (alias_ctad_tweaks): Rewrite deduced args. (type_targs_deducible_from): Handle null pack deduction. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/class-deduction-alias16.C: New test. * g++.dg/cpp2a/class-deduction-alias17.C: New test.
2023-03-29Daily bump.GCC Administrator1-0/+13
2023-03-28Don't emit -Wxor-used-as-pow on macro expansions [PR107002]David Malcolm1-0/+1
PR c/107002 reports an assertion failure from deep inside the diagnostic_shows_locus when attempting to print fix-it hints relating to -Wxor-used-as-pow. The case involves macro expansions with -ftrack-macro-expansion=0. It doesn't seem to make much sense to emit this warning for macro expansions, so this patch updates the warning not to (which seems to also be clang's behavior). The patch also adds some bulletproofing to diagnostic-show-locus.cc to be more robust against such invalid fix-it hints. Doing so fixes the ICE. gcc/c-family/ChangeLog: PR c/107002 * c-common.h (check_for_xor_used_as_pow): Add "rhs_loc" param. * c-warn.cc (check_for_xor_used_as_pow): Add "rhs_loc" param. Reject cases where involving macro expansions. gcc/c/ChangeLog: PR c/107002 * c-typeck.cc (parser_build_binary_op): Update for new param of check_for_xor_used_as_pow. gcc/cp/ChangeLog: PR c/107002 * parser.cc (cp_parser_binary_expression): Update for new param of check_for_xor_used_as_pow. gcc/ChangeLog: PR c/107002 * diagnostic-show-locus.cc (column_range::column_range): Factor out assertion conditional into... (column_range::valid_p): ...this new function. (line_corrections::add_hint): Don't attempt to consolidate hints if it would lead to invalid column_range instances. gcc/testsuite/ChangeLog: PR c/107002 * c-c++-common/Wxor-used-as-pow-1.c: Add macro test. * c-c++-common/Wxor-used-as-pow-pr107002-0.c: New test. * c-c++-common/Wxor-used-as-pow-pr107002-1.c: New test. * c-c++-common/Wxor-used-as-pow-pr107002-2.c: New test. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2023-03-28c++: Allow translations of check_postcondition_result messages [PR109309]Jakub Jelinek1-11/+10
As mentioned in the PR, constructing a message from two parts by concatenating them prevents translations, unless one of the parts is a keyword which should be never translated. The following patch fixes that. 2023-03-28 Jakub Jelinek <jakub@redhat.com> PR c++/109309 * contracts.cc: Include intl.h. (check_postcondition_result): Don't form diagnostics from two halves of an English message to allow translations.
2023-03-25Daily bump.GCC Administrator1-0/+11