aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
AgeCommit message (Collapse)AuthorFilesLines
32 hoursDaily bump.GCC Administrator1-0/+11
47 hoursc++: -Wdangling-reference and empty class [PR115361]Jason Merrill1-5/+7
We can't have a dangling reference to an empty class unless it's specifically to that class or one of its bases. This was giving a false positive on the _ExtractKey pattern in libstdc++ hashtable.h. This also adjusts the order of arguments to reference_related_p, which is relevant for empty classes (unlike scalars). Several of the classes in the testsuite needed to gain data members to continue to warn. PR c++/115361 gcc/cp/ChangeLog: * call.cc (do_warn_dangling_reference): Check is_empty_class. gcc/testsuite/ChangeLog: * g++.dg/ext/attr-no-dangling6.C * g++.dg/ext/attr-no-dangling7.C * g++.dg/ext/attr-no-dangling8.C * g++.dg/ext/attr-no-dangling9.C * g++.dg/warn/Wdangling-reference1.C * g++.dg/warn/Wdangling-reference2.C * g++.dg/warn/Wdangling-reference3.C: Make classes non-empty. * g++.dg/warn/Wdangling-reference23.C: New test.
47 hoursc++: fix -Wdangling-reference false positive [PR115987]Marek Polacek1-2/+12
This fixes another false positive. When a function is taking a temporary of scalar type that couldn't be bound to the return type of the function, don't warn, such a program would be ill-formed. Thanks to Jonathan for reporting the problem. PR c++/115987 gcc/cp/ChangeLog: * call.cc (do_warn_dangling_reference): Don't consider a temporary with a scalar type that cannot bind to the return type. gcc/testsuite/ChangeLog: * g++.dg/ext/attr-no-dangling6.C: Adjust. * g++.dg/ext/attr-no-dangling7.C: Likewise. * g++.dg/warn/Wdangling-reference22.C: New test.
12 daysDaily bump.GCC Administrator1-0/+17
12 daysc++: decltype(auto) deduction of statement-expression [PR116418]Patrick Palka1-4/+1
r8-7538 for PR84968 made strip_typedefs_expr diagnose STATEMENT_LIST so that we reject statement-expressions in noexcept-specifiers to match our behavior in template arguments (which the parser diagnoses directly). Later r11-7452 made decltype(auto) deduction canonicalize the expression (as an implementation detail) which in turn calls strip_typedefs_expr, and so ever since we inadvertently reject decltype(auto) deduction of a statement-expression. This patch just removes the diagnostic in strip_typedefs_expr and instead treats statement-expressions similar to lambda-expressions. The function doesn't seem like the right place for such a diagnostic and so it seems easier to just accept rather than try to reject them in a suitable place. PR c++/116418 gcc/cp/ChangeLog: * tree.cc (strip_typedefs_expr) <case STATEMENT_LIST>: Replace this error path with ... <case STMT_EXPR>: ... this, returning the original tree. gcc/testsuite/ChangeLog: * g++.dg/eh/pr84968.C: No longer expect an ahead of time diagnostic for the statement-expresssion. Instantiate the template and expect an incomplete type error instead. * g++.dg/ext/stmtexpr26.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com> (cherry picked from commit 12bdcc3d7970860b9d66ed4dea203bde8fd68d4d)
12 daysc++: CWG 2789 and usings [PR116492]Patrick Palka1-0/+8
For GCC 14, narrowly fix this PR by implementing the missing - if they are member functions, both are direct members of the same class, and part of CWG 2789 for constructors only. PR c++/116492 DR 2789 gcc/cp/ChangeLog: * call.cc (cand_parms_match): Return false for constructors that come from different classes. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-inherit-ctor12.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com>
2024-09-18Daily bump.GCC Administrator1-0/+8
2024-09-17c++: crash with anon VAR_DECL [PR116676]Marek Polacek1-0/+1
r12-3495 added maybe_warn_about_constant_value which will crash if it gets a nameless VAR_DECL, which is what happens in this PR. We created this VAR_DECL in cp_parser_decomposition_declaration. PR c++/116676 gcc/cp/ChangeLog: * constexpr.cc (maybe_warn_about_constant_value): Check DECL_NAME. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/constexpr-116676.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com> (cherry picked from commit dfe0d4389a3ce43179563a63046ad3e74d615a08)
2024-09-13Daily bump.GCC Administrator1-0/+29
2024-09-12c++: ICE with TTP [PR96097]Marek Polacek1-0/+2
We crash when dependent_type_p gets a TEMPLATE_TYPE_PARM outside a template. That happens here because in template <template <typename T, typename T::type TT> typename X> void func() {} template <typename U, int I> struct Y {}; void g() { func<Y>(); } when performing overload resolution for func<Y>() we have to check if U matches T and I matches TT. So we wind up in coerce_template_template_parm/PARM_DECL. TREE_TYPE (arg) is int so we try to substitute TT's type, which is T::type. But we have nothing to substitute T with. And we call make_typename_type where ctx is still T, which checks dependent_scope_p and we trip the assert. It should work to always perform the substitution in a template context. If the result still contains template parameters, we cannot say if they match. PR c++/96097 gcc/cp/ChangeLog: * pt.cc (coerce_template_template_parm): Increment processing_template_decl before calling tsubst. gcc/testsuite/ChangeLog: * g++.dg/template/ttp44.C: New test. (cherry picked from commit 25ac2bb57ae400621050a7e0845994336ca83b99)
2024-09-12c++: Disable deprecated/unavailable diagnostics when creating thunks for ↵Jakub Jelinek1-0/+6
methods with such attributes [PR116636] On the following testcase, we emit false positive warnings/errors about using the deprecated or unavailable methods when creating thunks for them, even when nothing (in the testcase so far) actually used those. The following patch temporarily disables that diagnostics when creating the thunks. 2024-09-12 Jakub Jelinek <jakub@redhat.com> PR c++/116636 * method.cc: Include decl.h. (use_thunk): Temporarily change deprecated_state to UNAVAILABLE_DEPRECATED_SUPPRESS. * g++.dg/warn/deprecated-19.C: New test. (cherry picked from commit 4026d89d623e322920b052f7ac0d940ef267dc0f)
2024-09-12c++: Fix get_member_function_from_ptrfunc with -fsanitize=bounds [PR116449]Jakub Jelinek1-3/+16
The following testcase is miscompiled, because get_member_function_from_ptrfunc emits something like (((FUNCTION.__pfn & 1) != 0) ? ptr + FUNCTION.__delta + FUNCTION.__pfn - 1 : FUNCTION.__pfn) (ptr + FUNCTION.__delta, ...) or so, so FUNCTION tree is used there 5 times. There is if (TREE_SIDE_EFFECTS (function)) function = save_expr (function); but in this case function doesn't have side-effects, just nested ARRAY_REFs. Now, if all the FUNCTION trees would be shared, it would work fine, FUNCTION is evaluated in the first operand of COND_EXPR; but unfortunately that isn't the case, both the BIT_AND_EXPR shortening and conversion to bool done for build_conditional_expr actually unshare_expr that first expression, but none of the other 4 are unshared. With -fsanitize=bounds, .UBSAN_BOUNDS calls are added to the ARRAY_REFs and use save_expr to avoid evaluating the argument multiple times, but because that FUNCTION tree is first used in the second argument of COND_EXPR (i.e. conditionally), the SAVE_EXPR initialization is done just there and then the third argument of COND_EXPR just uses the uninitialized temporary and so does the first argument computation as well. The following patch fixes that by doing save_expr even if !TREE_SIDE_EFFECTS, but to avoid doing that too often only if !nonvirtual and if the expression isn't a simple decl. 2024-09-10 Jakub Jelinek <jakub@redhat.com> PR c++/116449 * typeck.cc (get_member_function_from_ptrfunc): Use save_expr on instance_ptr and function even if it doesn't have side-effects, as long as it isn't a decl. * g++.dg/ubsan/pr116449.C: New test. (cherry picked from commit 0008050b9d6046ba4e811a03b406fb5d98707cae)
2024-09-09Daily bump.GCC Administrator1-0/+30
2024-09-08c++: c->B::m access resolved through current inst [PR116320]Patrick Palka1-3/+8
Here when checking the access of (the injected-class-name) B in c->B::m at parse time, we notice its context B (now the type) is a base of the object type C<T>, so we proceed to use C<T> as the effective qualifying type. But this C<T> is the dependent specialization not the primary template type, so it has empty TYPE_BINFO, which leads to a segfault later from perform_or_defer_access_check. The reason the DERIVED_FROM_P (B, C<T>) test guarding this code path works despite C<T> having empty TYPE_BINFO is because of its currently_open_class logic (added in r9-713-gd9338471b91bbe) which replaces a dependent specialization with the primary template type if we're inside it. So the safest fix seems to be to call currently_open_class in the caller as well. PR c++/116320 gcc/cp/ChangeLog: * semantics.cc (check_accessibility_of_qualified_id): Try currently_open_class when using the object type as the effective qualifying type. gcc/testsuite/ChangeLog: * g++.dg/template/access42.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com> (cherry picked from commit 484f139ccd3b631a777802e810a632678b42ffab)
2024-09-08c++: inherited CTAD fixes [PR116276]Patrick Palka3-12/+66
This implements the overlooked inherited vs non-inherited guide tiebreaker from P2582R1. This requires tracking inherited-ness of a guide, for which it seems natural to reuse the lang_decl_fn::context field which for a constructor tracks its inherited-ness. This patch also works around CLASSTYPE_CONSTRUCTORS not reliably returning all inherited constructors (due to some using-decl handling quirks in in push_class_level_binding) by iterating over TYPE_FIELDS instead. This patch also makes us recognize another written form of inherited constructor, 'using Base<T>::Base::Base' whose USING_DECL_SCOPE is a TYPENAME_TYPE. PR c++/116276 gcc/cp/ChangeLog: * call.cc (joust): Implement P2582R1 inherited vs non-inherited guide tiebreaker. * cp-tree.h (lang_decl_fn::context): Document usage in deduction_guide_p FUNCTION_DECLs. (inherited_guide_p): Declare. * pt.cc (inherited_guide_p): Define. (set_inherited_guide_context): Define. (alias_ctad_tweaks): Use set_inherited_guide_context. (inherited_ctad_tweaks): Recognize some inherited constructors whose scope is a TYPENAME_TYPE. (ctor_deduction_guides_for): For C++23 inherited CTAD, iterate over TYPE_FIELDS instead of CLASSTYPE_CONSTRUCTORS to recognize all inherited constructors. gcc/testsuite/ChangeLog: * g++.dg/cpp23/class-deduction-inherited4.C: Remove an xfail. * g++.dg/cpp23/class-deduction-inherited5.C: New test. * g++.dg/cpp23/class-deduction-inherited6.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com> (cherry picked from commit 8cc67b520968ca9a13fd96896522aa66e39a99e2)
2024-09-08Daily bump.GCC Administrator1-0/+7
2024-09-07c++: template depth of lambda in default targ [PR116567]Patrick Palka1-0/+12
For GCC 14, let's narrowly fix this bug by just pruning the result of add_extra_args after the fact to get rid of any unwanted outer levels. PR c++/116567 gcc/cp/ChangeLog: * pt.cc (tsubst_lambda_expr): For a deferred-substitution lambda, trim the augmented template arguments to match the template depth of the lambda. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/lambda-targ7.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com>
2024-09-06Daily bump.GCC Administrator1-0/+9
2024-09-05c++: vtable referring to "unavailable" virtual fn [PR116606]Marek Polacek1-1/+2
mark_vtable_entries already has /* It's OK for the vtable to refer to deprecated virtual functions. */ warning_sentinel w(warn_deprecated_decl); but that doesn't cover __attribute__((unavailable)). We can use the following override to cover both. PR c++/116606 gcc/cp/ChangeLog: * decl2.cc (mark_vtable_entries): Temporarily override deprecated_state to UNAVAILABLE_DEPRECATED_SUPPRESS. Remove a warning_sentinel. gcc/testsuite/ChangeLog: * g++.dg/ext/attr-unavailable-13.C: New test. (cherry picked from commit d9d34f9a91371dea4bab0b54b2d7f762a6cc23e0)
2024-08-20Daily bump.GCC Administrator1-0/+9
2024-08-19c++: fix ICE in convert_nontype_argument [PR116384]Marek Polacek1-0/+2
Here we ICE since r14-8291 in C++11/C++14 modes. Fortunately this is an easy one. The important bit of r14-8291 is this: @@ -20056,9 +20071,12 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl) RETURN (retval); } if (IMPLICIT_CONV_EXPR_NONTYPE_ARG (t)) - /* We'll pass this to convert_nontype_argument again, we don't need - to actually perform any conversion here. */ - RETURN (expr); + { + tree r = convert_nontype_argument (type, expr, complain); + if (r == NULL_TREE) + r = error_mark_node; + RETURN (r); + } which obviously means that instead of returning right away we go to convert_nontype_argument. When type is error_mark_node and we're in C++17, in convert_nontype_argument we go down this path: else if (INTEGRAL_OR_ENUMERATION_TYPE_P (type) || cxx_dialect >= cxx17) { expr = build_converted_constant_expr (type, expr, complain); if (expr == error_mark_node) return (complain & tf_error) ? NULL_TREE : error_mark_node; // ... } but pre-C++17, we take a different route and end up crashing on gcc_unreachable. It would of course also work to check for error_mark_node early in build_converted_constant_expr. PR c++/116384 gcc/cp/ChangeLog: * pt.cc (tsubst_expr) <case IMPLICIT_CONV_EXPR>: Bail if tsubst returns error_mark_node. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/vt-116384.C: New test. (cherry picked from commit 8191f15022b0ea44fcb549449b0458d07ae02e0a)
2024-08-16Daily bump.GCC Administrator1-0/+11
2024-08-15c++/coroutines: fix passing *this to promise type, again [PR116327]Patrick Palka1-2/+6
In r15-2210 we got rid of the unnecessary cast to lvalue reference when passing *this to the promise type ctor, and as a drive-by change we also simplified the code to use cp_build_fold_indirect_ref. But it turns out cp_build_fold_indirect_ref does too much here, namely it has a shortcut for returning current_class_ref if the operand is current_class_ptr. The problem with that shortcut is current_class_ref might have gotten clobbered earlier if it appeared in the function body, since rewrite_param_uses walks and rewrites in-place all local variable uses to their corresponding frame copy. So later cp_build_fold_indirect_ref for *this will instead return the clobbered current_class_ref i.e. *frame_ptr->this, which doesn't make sense here since we're in the ramp function and not the actor function where frame_ptr is in scope. This patch fixes this by using the build_fold_indirect_ref instead of cp_build_fold_indirect_ref. PR c++/116327 PR c++/104981 PR c++/115550 gcc/cp/ChangeLog: * coroutines.cc (morph_fn_to_coro): Use build_fold_indirect_ref instead of cp_build_fold_indirect_ref. gcc/testsuite/ChangeLog: * g++.dg/coroutines/pr104981-preview-this.C: Improve coverage by adding a non-static data member use within the coroutine member function. * g++.dg/coroutines/pr116327-preview-this.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com> (cherry picked from commit 303bed670af962c01b77a4f0c51de97f70e8167e)
2024-08-07Daily bump.GCC Administrator1-0/+20
2024-08-06c++: alias and non-type template parm [PR116223]Jason Merrill1-1/+5
My r14-8291 for PR112632 introduced IMPLICIT_CONV_EXPR_FORCED to express conversions to the type of an alias template parameter. In this example, that broke deduction of X in the call to foo, so let's teach deduction to look through it. PR c++/116223 PR c++/112632 gcc/cp/ChangeLog: * pt.cc (deducible_expression): Also look through IMPLICIT_CONV_EXPR_FORCED. (unify): Likewise. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/nontype-auto25.C: New test. (cherry picked from commit 4add6cd341a779e980e41ed6fb49175fca37496e)
2024-08-06c++: parse error with -std=c++14 -fconcepts [PR116071]Jason Merrill1-3/+7
cp_parser_simple_type_specifier tries a variety of different things that might qualify as a user-defined type: an actual type-name, a constrained auto, a CTAD placeholder. In a context where a type-specifier is optional, this is all tentative. With -std=c++14 -fconcepts, we try type-name and constrained auto in sub-tentative parses, and when we run out of things to try we haven't found anything but also haven't failed the outer tentative parse, so parse_definitely succeeds, discarding the nested-name-specifier. Fixed by failing if we didn't find anything. I said in r14-3203 that we should disable this combination of flags if further problems arise, but this seems like a more general problem that only happened to occur with just this combination of flags. So it lives on. PR c++/116071 gcc/cp/ChangeLog: * parser.cc (cp_parser_simple_type_specifier): Call cp_parser_simulate_error if nothing worked. gcc/testsuite/ChangeLog: * g++.dg/parse/pr116071.C: New test. (cherry picked from commit 8c71830b51e6fd10087ce3f6791de80eb1f10b96)
2024-08-03Daily bump.GCC Administrator1-0/+60
2024-08-01c++: generic lambda in default template argument [PR88313]Patrick Palka1-14/+20
Here we're rejecting the generic lambda inside the default template argument ultimately because auto_is_implicit_function_template_parm_p doesn't get set during parsing of the lambda's parameter list, due to the !processing_template_parmlist restriction. But when parsing a lambda parameter list we should always set that flag regardless of where the lambda appears. This patch makes sure of this via a local lambda_p flag. PR c++/88313 gcc/cp/ChangeLog: * parser.cc (cp_parser_lambda_declarator_opt): Pass lambda_p=true to cp_parser_parameter_declaration_clause. (cp_parser_direct_declarator): Pass lambda_p=false to to cp_parser_parameter_declaration_clause. (cp_parser_parameter_declaration_clause): Add bool lambda_p parameter. Consider lambda_p instead of current_class_type when setting parser->auto_is_implicit_function_template_parm_p. Don't consider processing_template_parmlist. (cp_parser_requirement_parameter_list): Pass lambda_p=false to cp_parser_parameter_declaration_clause. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/lambda-targ6.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com> (cherry picked from commit 72a7ab891ae0061841c4eb641ef6ab7719bf0369)
2024-08-01c++: alias of alias tmpl with dependent attrs [PR115897]Patrick Palka1-22/+29
As a follow-up to r15-2047-g7954bb4fcb6fa8, we also need to consider dependent attributes when recursing into a non-template alias that names a dependent alias template specialization (and so STF_STRIP_DEPENDENT is set), otherwise in the first testcase below we undesirably strip B all the way to T instead of to A<T>. We also need to move the typedef recursion case of strip_typedefs up to get checked before the compound type recursion cases. Otherwise for C below (which ultimately aliases T*) we end up stripping it to T* instead of to A<T*> because the POINTER_TYPE recursion dominates the typedef recursion. It also means we issue an unexpected extra error in the third testcase below. Ideally we would also want to consider dependent attributes on non-template aliases, so that we accept the second testcase below, but making that work correctly would require broader changes to e.g. structural_comptypes. PR c++/115897 gcc/cp/ChangeLog: * tree.cc (strip_typedefs): Move up the typedef recursion case. Never strip a dependent alias template-id that has dependent attributes. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/alias-decl-78.C: New test. * g++.dg/cpp0x/alias-decl-79.C: New test. * g++.dg/cpp0x/alias-decl-pr92206-1a.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com> (cherry picked from commit 9bcad238837e2100978cd839c343c488f72e1d4a)
2024-08-01c++: normalizing ttp constraints [PR115656]Patrick Palka3-6/+7
Here we normalize the constraint same_as<T, bool> for the first time during ttp coercion of B / UU, specifically constraint subsumption checking. During this normalization the set of in-scope template parameters i.e. current_template_parms is empty, which we rely on during normalization of the ttp constraints since we pass in_decl=NULL_TREE to norm_info. And this tricks the satisfaction cache into thinking that the satisfaction value of same_as<T, bool> is independent of its template parameters, and we incorrectly conflate the satisfaction value with T = bool vs T = long and accept the specialization A<long, B>. Since is_compatible_template_arg rewrites the ttp's constraints to be in terms of the argument template's parameters, and since it's the only caller of weakly_subsumes, the latter funcion can instead pass in_decl=tmpl to avoid relying on current_template_parms. This patch implements this, and in turns renames weakly_subsumes to ttp_subsumes to reflect that this predicate is now hardcoded for this one caller. PR c++/115656 gcc/cp/ChangeLog: * constraint.cc (weakly_subsumes): Pass in_decl=tmpl to get_normalized_constraints_from_info. Rename to ... (ttp_subsumes): ... this. * cp-tree.h (weakly_subsumes): Rename to ... (ttp_subsumes): ... this. * pt.cc (is_compatible_template_arg): Adjust after renaming. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-ttp7.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com> (cherry picked from commit 2861eb34e30973cb991a7964af7cfeae014a98b0)
2024-08-01c++: missing SFINAE during alias CTAD [PR115296]Patrick Palka1-1/+1
During the alias CTAD transformation, if substitution failed for some guide we should just silently discard the guide. We currently do discard the guide, but not silently, as in the below testcase which we diagnose forming a too-large array type when transforming the user-defined deduction guides. This patch fixes this by using complain=tf_none instead of tf_warning_or_error throughout alias_ctad_tweaks. PR c++/115296 gcc/cp/ChangeLog: * pt.cc (alias_ctad_tweaks): Use complain=tf_none instead of tf_warning_or_error. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/class-deduction-alias23.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com> (cherry picked from commit f70281222df432a7bec1271904c5ebefd7f2c934)
2024-08-01c++: prev declared hidden tmpl friend inst [PR112288]Patrick Palka1-6/+7
When partially instantiating a previously declared hidden template friend definition (at class template scope) such as slot_allocated in the first testcase below, tsubst_friend_function needs to go through all existing specializations thereof and make them point to the new definition. But when the previous declaration was also at class template scope, old_decl is not the most general template, instead it's the partial instantiation, and since instantiations are relative to the most general template, old_decl's DECL_TEMPLATE_INSTANTIATIONS is empty. So we to consistently use the most general template here. And when adjusting DECL_TI_ARGS to match, only the innermost template arguments should be preserved; the outer ones should correspond to the new definition. Otherwise we fail a checking-only sanity check in instantiate_decl in the first testcase, and in the second/third we end up emitting multiple definitions of the template friend instantiation, resulting in a link failure. PR c++/112288 gcc/cp/ChangeLog: * pt.cc (tsubst_friend_function): When adjusting existing specializations after defining a previously declared template friend, consider the most general template and correct DECL_TI_ARGS adjustment. gcc/testsuite/ChangeLog: * g++.dg/template/friend80.C: New test. * g++.dg/template/friend81.C: New test. * g++.dg/template/friend81a.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com> (cherry picked from commit 30dd420a06ad7d2adf4a672d176caee632f8168a)
2024-08-01Update ChangeLog and version files for releasereleases/gcc-14.2.0Jakub Jelinek1-0/+4
2024-07-30Daily bump.GCC Administrator1-0/+35
2024-07-29c++: wrong error initializing empty class [PR115900]Marek Polacek1-4/+10
In r14-409, we started handling empty bases first in cxx_fold_indirect_ref_1 so that we don't need to recurse and waste time. This caused a bogus "modifying a const object" error. I'm appending my analysis from the PR, but basically, cxx_fold_indirect_ref now returns a different object than before, and we mark the wrong thing as const, but since we're initializing an empty object, we should avoid setting the object constness. ~~ Pre-r14-409: we're evaluating the call to C::C(), which is in the body of B::B(), which is the body of D::D(&d): C::C ((struct C *) this, NON_LVALUE_EXPR <0>) It's a ctor so we get here: 3118 /* Remember the object we are constructing or destructing. */ 3119 tree new_obj = NULL_TREE; 3120 if (DECL_CONSTRUCTOR_P (fun) || DECL_DESTRUCTOR_P (fun)) 3121 { 3122 /* In a cdtor, it should be the first `this' argument. 3123 At this point it has already been evaluated in the call 3124 to cxx_bind_parameters_in_call. */ 3125 new_obj = TREE_VEC_ELT (new_call.bindings, 0); new_obj=(struct C *) &d.D.2656 3126 new_obj = cxx_fold_indirect_ref (ctx, loc, DECL_CONTEXT (fun), new_obj); new_obj=d.D.2656.D.2597 We proceed to evaluate the call, then we get here: 3317 /* At this point, the object's constructor will have run, so 3318 the object is no longer under construction, and its possible 3319 'const' semantics now apply. Make a note of this fact by 3320 marking the CONSTRUCTOR TREE_READONLY. */ 3321 if (new_obj && DECL_CONSTRUCTOR_P (fun)) 3322 cxx_set_object_constness (ctx, new_obj, /*readonly_p=*/true, 3323 non_constant_p, overflow_p); new_obj is still d.D.2656.D.2597, its type is "C", cxx_set_object_constness doesn't set anything as const. This is fine. After r14-409: on line 3125, new_obj is (struct C *) &d.D.2656 as before, but we go to cxx_fold_indirect_ref_1: 5739 if (is_empty_class (type) 5740 && CLASS_TYPE_P (optype) 5741 && lookup_base (optype, type, ba_any, NULL, tf_none, off)) 5742 { 5743 if (empty_base) 5744 *empty_base = true; 5745 return op; type is C, which is an empty class; optype is "const D", and C is a base of D. So we return the VAR_DECL 'd'. Then we get to cxx_set_object_constness with object=d, which is const, so we mark the constructor READONLY. Then we're evaluating A::A() which has ((A*)this)->data = 0; we evaluate the LHS to d.D.2656.a, for which the initializer is {.D.2656={.a={.data=}}} which is TREE_READONLY and 'd' is const, so we think we're modifying a const object and fail the constexpr evaluation. PR c++/115900 gcc/cp/ChangeLog: * constexpr.cc (cxx_eval_call_expression): Set new_obj to NULL_TREE if cxx_fold_indirect_ref set empty_base to true. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/constexpr-init23.C: New test. (cherry picked from commit d890b04197fb0ddba4fbfb32f88e266fa27e02f3)
2024-07-29c++: if consteval and consteval propagation [PR115583]Jason Merrill1-2/+5
During speculative constant folding of an if consteval, we take the false branch, but the true branch is an immediate function context, so we don't want to to cp_fold_immediate it. So we could check IF_STMT_CONSTEVAL_P here. But beyond that, we don't want to do this inside a call, only when first parsing a function. PR c++/115583 gcc/cp/ChangeLog: * constexpr.cc (cxx_eval_conditional_expression): Don't cp_fold_immediate for if consteval. gcc/testsuite/ChangeLog: * g++.dg/cpp23/consteval-if13.C: New test. (cherry picked from commit d5f1948640815a554d106542c2e91e4e117aa3bc)
2024-07-29c++: consteval propagation and templates [PR115986]Jason Merrill1-0/+4
Here the call to e() makes us decide to check d() for escalation at EOF, but while checking it we try to fold_immediate 0_c, and get confused by the template trees. Let's not mess with escalation for function templates. PR c++/115986 gcc/cp/ChangeLog: * cp-gimplify.cc (remember_escalating_expr): Skip function templates. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/consteval-prop21.C: New test. (cherry picked from commit a9e9f772c7488ac0c09dd92f28890bdab939771a)
2024-07-29c++: ICE with concept, local class, and lambda [PR115561]Jason Merrill1-1/+1
Here when we want to synthesize methods for foo()::B maybe_push_to_top_level calls push_function_context, which sets cfun to a dummy value; later finish_call_expr tries to set something in cp_function_chain (i.e. cfun->language), which isn't set. Many places in the compiler check cfun && cp_function_chain to avoid this problem; here we also want to check !cp_unevaluated_operand, like set_flags_from_callee does. PR c++/115561 gcc/cp/ChangeLog: * semantics.cc (finish_call_expr): Check cp_unevaluated_operand. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-lambda21.C: New test. (cherry picked from commit 3129a2ed6a764c0687efaca9eba53dcf12d1d8a0)
2024-07-24Daily bump.GCC Administrator1-0/+21
2024-07-22c++/coroutines: correct passing *this to promise type [PR104981]Patrick Palka1-15/+3
When passing *this to the promise type ctor (or to its operator new) (as per [dcl.fct.def.coroutine]/4), we add an explicit cast to lvalue reference. But this is unnecessary since *this is already always an lvalue. And doing so means we need to call convert_from_reference afterward to lower the reference expression to an implicit dereference, which we're currently neglecting to do and which causes overload resolution to get confused when computing argument conversions. So this patch removes this unneeded reference cast when passing *this to the promise ctor, and removes both the cast and implicit deref when passing *this to operator new, for consistency. While we're here, use cp_build_fold_indirect_ref instead of directly building INDIRECT_REF. PR c++/104981 PR c++/115550 gcc/cp/ChangeLog: * coroutines.cc (morph_fn_to_coro): Remove unneeded calls to convert_to_reference and convert_from_reference when passing *this. Use cp_build_fold_indirect_ref instead of directly building INDIRECT_REF. gcc/testsuite/ChangeLog: * g++.dg/coroutines/pr104981-preview-this.C: New test. * g++.dg/coroutines/pr115550-preview-this.C: New test. Reviewed-by: Iain Sandoe <iain@sandoe.co.uk> Reviewed-by: Jason Merrill <jason@redhat.com> (cherry picked from commit 7c5a9bf1d206fe20cb050200d4a30f11c76b1b19)
2024-07-22c++: xobj fn call without obj [PR115783]Patrick Palka1-1/+1
The code path for rejecting an object-less call to a non-static member function should also consider xobj member functions (so that we correctly reject the below calls with a "cannot call member function without object" diagnostic). PR c++/115783 gcc/cp/ChangeLog: * call.cc (build_new_method_call): Generalize METHOD_TYPE check to DECL_OBJECT_MEMBER_FUNCTION_P. gcc/testsuite/ChangeLog: * g++.dg/cpp23/explicit-obj-diagnostics11.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com> (cherry picked from commit 2ee70c9f83a1033f2897a35bff9e9ffdd03cc651)
2024-07-19Daily bump.GCC Administrator1-0/+16
2024-07-18c++: ICE with __has_unique_object_representations [PR115476]Marek Polacek1-1/+1
Here we started to ICE with r13-25: in check_trait_type, for "X[]" we return true here: if (kind == 1 && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type)) return true; // Array of unknown bound. Don't care about completeness. and then end up crashing in record_has_unique_obj_representations: 4836 if (cur != wi::to_offset (sz)) because sz is null. https://eel.is/c++draft/type.traits#tab:meta.unary.prop-row-47-column-3-sentence-1 says that the preconditions for __has_unique_object_representations are: "T shall be a complete type, cv void, or an array of unknown bound" and that "For an array type T, the same result as has_unique_object_representations_v<remove_all_extents_t<T>>" so T[] should be treated as T. So we should use kind==2 for the trait. PR c++/115476 gcc/cp/ChangeLog: * semantics.cc (finish_trait_expr) <case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS>: Move below to call check_trait_type with kind==2. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/has-unique-obj-representations4.C: New test. (cherry picked from commit fc382a373e6824bb998007d1dcb0805b0cf4b8e8)
2024-07-18c++/modules: Conditionally start timer during lazy load [PR115165]Nathaniel Shead1-4/+4
While lazy loading, instantiation of pendings can sometimes recursively perform name lookup and begin further lazy loading. When using the '-ftime-report' functionality this causes ICEs as we could start an already-running timer for the importing. This patch fixes the issue by using the 'timevar_cond*' API instead to support such recursive calls. PR c++/115165 gcc/cp/ChangeLog: * module.cc (lazy_load_binding): Use 'timevar_cond*' APIs. (lazy_load_pendings): Likewise. gcc/testsuite/ChangeLog: * g++.dg/modules/timevar-1_a.H: New test. * g++.dg/modules/timevar-1_b.C: New test. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
2024-07-18Daily bump.GCC Administrator1-0/+50
2024-07-17c++: constrained partial spec type context [PR111890]Patrick Palka1-0/+1
maybe_new_partial_specialization wasn't propagating TYPE_CONTEXT when creating a new class type corresponding to a constrained partial spec, which do_friend relies on via template_class_depth to distinguish a template friend from a non-template friend, and so in the below testcase we were incorrectly instantiating the non-template operator+ as if it were a template leading to an ICE. PR c++/111890 gcc/cp/ChangeLog: * pt.cc (maybe_new_partial_specialization): Propagate TYPE_CONTEXT to the newly created partial specialization. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-partial-spec15.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com> (cherry picked from commit 247335823f420eb1dd56f4bf32ac78d441f5ccc2)
2024-07-17c++: alias template with dependent attributes [PR115897]Patrick Palka1-0/+10
Here we're prematurely stripping the dependent alias template-id A<T> to its defining-type-id T when used as a template argument, which in turn causes us to essentially ignore A's vector_size attribute in the outer template-id. This has always been a problem for class template-ids it seems, and after r14-2170 variable template-ids are affected as well. This patch marks alias templates that have a dependent attribute as complex (as with e.g. constrained alias templates) so that we don't look through them prematurely. PR c++/115897 gcc/cp/ChangeLog: * pt.cc (complex_alias_template_p): Return true for an alias template with attributes. (get_underlying_template): Don't look through an alias template with attributes. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/alias-decl-77.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com> (cherry picked from commit 7954bb4fcb6fa80f6bb840133314885011821188)
2024-07-17c++: bad 'this' conversion for nullary memfn [PR106760]Patrick Palka1-1/+2
Here we notice the 'this' conversion for the call f<void>() is bad, so we correctly defer deduction for the template candidate, but we end up never adding it to 'bad_cands' since missing_conversion_p for it returns false (its only argument is 'this' which has already been determined to be bad). This is not a huge deal, but it causes us to longer accept the call with -fpermissive in release builds, and a tree check ICE in checking builds. So if we have a non-strictly viable template candidate that has not been instantiated, then we need to add it to 'bad_cands' even if no argument conversion is missing. PR c++/106760 gcc/cp/ChangeLog: * call.cc (add_candidates): Relax test for adding a candidate to 'bad_cands' to also accept an uninstantiated template candidate that has no missing conversions. gcc/testsuite/ChangeLog: * g++.dg/ext/conv3.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com> (cherry picked from commit 50073ffae0a9b8feb9b36fdafdebd9885f6d7dc8)
2024-07-17c++: Fix ICE on constexpr placement new [PR115754]Jakub Jelinek1-1/+4
C++26 is making in P2747R2 paper placement new constexpr. While working on a patch for that, I've noticed we ICE starting with GCC 14 on the following testcase. The problem is that e.g. for the void * to sometype * casts checks, we really assume the casts have their operand constant evaluated as prvalue, but on the testcase the cast itself is evaluated with vc_discard and that means op can end up e.g. a VAR_DECL which the later code doesn't like and asserts on. If the result type is void, we don't really need the cast operand for anything, so can use vc_discard for the recursive call, VIEW_CONVERT_EXPR can appear on the lhs, so we need to honor the lval but otherwise the patch uses vc_prvalue. I'd like to get this patch in before the rest of P2747R2 implementation, so that it can be backported to 14.2 later on. 2024-07-02 Jakub Jelinek <jakub@redhat.com> Jason Merrill <jason@redhat.com> PR c++/115754 * constexpr.cc (cxx_eval_constant_expression) <case CONVERT_EXPR>: For conversions to void, pass vc_discard to the recursive call and otherwise for tcode other than VIEW_CONVERT_EXPR pass vc_prvalue. * g++.dg/cpp26/pr115754.C: New test. (cherry picked from commit 1250540a98e0a1dfa4d7834672d88d8543ea70b1)
2024-07-17c++/modules: Propagate BINDING_VECTOR_*_DUPS_P on realloc [PR99242]Nathaniel Shead1-0/+4
When importing modules, when a binding vector for a name runs out of slots it gets reallocated with a larger size, and existing bindings are copied across. However, the flags to indicate whether deduping needs to occur did not: this causes ICEs, as it allows a duplicate binding to be added which then violates assumptions later on. PR c++/99242 gcc/cp/ChangeLog: * name-lookup.cc (append_imported_binding_slot): Propagate dups flags. gcc/testsuite/ChangeLog: * g++.dg/modules/pr99242_a.H: New test. * g++.dg/modules/pr99242_b.H: New test. * g++.dg/modules/pr99242_c.H: New test. * g++.dg/modules/pr99242_d.C: New test. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com> (cherry picked from commit 1aa0f1627857c3e2d90982bdb07ca78ca10b26f3)