@@ -22776,6 +22776,13 @@ member of a union or anonymous union).
2277622776 rout_sym = fundamental_symbol_of(rout_sym);
2277722777 if (symbol_is(rout_sym, sk_member_function)) {
2277822778 a_routine_ptr rp = rout_sym->variant.routine.ptr;
22779+ if (!rp->compiler_generated && !rp->is_defaulted) {
22780+ /* A user-provided constructor is selected, which is not
22781+ necessarily a copy constructor (e.g., a constructor template, if
22782+ no copy constructor is eligible). */
22783+ class_symbol_supp(symbol_for(class_type))
22784+ ->makes_copy_construction_nontrivial = TRUE;
22785+ } /* if */
2277922786 if (!rp->is_constexpr) {
2278022787 /* If this special member has to call a non-constexpr special
2278122788 member, it is itself not constexpr. */
@@ -24771,6 +24778,61 @@ before generating declarations for special members.
2477124778} /* set_move_assign_operator_flags */
2477224779
2477324780
24781+ static a_boolean user_provided_copy_functions_are_masked(
24782+ a_symbol_ptr member_set,
24783+ a_boolean is_move)
24784+ /*
24785+ member_set is the constructor or assignment operator symbol of a class
24786+ (possibly an overloaded function symbol). Return TRUE if member_set includes
24787+ user-provided copy (or, if is_move is TRUE, move) constructors or assignment
24788+ operators, but none of them is eligible (N5046 [special]/6) because each one
24789+ has unsatisfied constraints or is masked by a more constrained member of the
24790+ same kind. Such functions are never selected to copy (or move) a subobject
24791+ of the class, and so they don't make the corresponding special member of an
24792+ enclosing class nontrivial. For example:
24793+ template<typename T> struct B {
24794+ B(B&&);
24795+ B(B&&) requires true = default;
24796+ };
24797+ struct D : B<int> {}; // D's move constructor is trivial.
24798+ */
24799+ {
24800+ a_boolean any_masked = FALSE, any_eligible = FALSE, is_list;
24801+ a_symbol_ptr sym = member_set;
24802+
24803+ if (sym != NULL && symbol_is(sym, sk_overloaded_function)) {
24804+ is_list = TRUE;
24805+ sym = sym->variant.overloaded_function.symbols;
24806+ } else {
24807+ is_list = FALSE;
24808+ } /* if */
24809+ for (; !any_eligible && sym != NULL; sym = is_list ? sym->next : NULL) {
24810+ a_routine_ptr rp;
24811+ a_type_qualifier_set tqs = TQ_NONE;
24812+ a_boolean sym_is_move = FALSE;
24813+ if (!symbol_is(sym, sk_member_function)) continue;
24814+ rp = sym->variant.routine.ptr;
24815+ if (rp->compiler_generated || rp->is_defaulted || rp->is_deleted) continue;
24816+ if (special_kind_is(rp, sfk_constructor)) {
24817+ if (!is_copy_constructor(rp, (a_type_ptr)NULL, &tqs,
24818+ /*include_move_ctors=*/TRUE,
24819+ /*is_declarative_context=*/TRUE)) continue;
24820+ sym_is_move = copy_ctor_is_move_ctor(rp);
24821+ } else if (!routine_is_copy_or_move_assign_operator(rp, &tqs,
24822+ &sym_is_move)) {
24823+ continue;
24824+ } /* if */
24825+ if (sym_is_move != is_move) continue;
24826+ if (is_ineligible(sym) || is_masked_special_member(sym, member_set)) {
24827+ any_masked = TRUE;
24828+ } else {
24829+ any_eligible = TRUE;
24830+ } /* if */
24831+ } /* for */
24832+ return any_masked && !any_eligible;
24833+ } /* user_provided_copy_functions_are_masked */
24834+
24835+
2477424836static void check_defaulted_members(
2477524837 a_type_ptr class_type,
2477624838 a_generated_special_function_descr *gsfd)
@@ -25250,22 +25312,35 @@ The routine body is not generated until it is known to be needed.
2525025312 bitwise copying of the parent class without making the copy functions
2525125313 nontrivial. A class is trivially copyable if it has a trivial destructor,
2525225314 and it is bitwise copyable/assignable, except perhaps for deleted copy
25253- functions. */
25315+ functions. User-provided copy functions that are masked by more
25316+ constrained ones don't make the copy functions of enclosing classes
25317+ nontrivial. */
2525425318 if (cssp->has_user_provided_copy_constructor) {
25255- cssp->makes_copy_construction_nontrivial = TRUE;
25319+ if (!user_provided_copy_functions_are_masked(cssp->constructor,
25320+ /*is_move=*/FALSE)) {
25321+ cssp->makes_copy_construction_nontrivial = TRUE;
25322+ } /* if */
2525625323 cssp->construction_by_bitwise_copy_allowed = FALSE;
2525725324 } /* if */
2525825325 if (cssp->has_user_provided_move_constructor) {
25259- cssp->makes_move_construction_nontrivial = TRUE;
25326+ if (!user_provided_copy_functions_are_masked(cssp->constructor,
25327+ /*is_move=*/TRUE)) {
25328+ cssp->makes_move_construction_nontrivial = TRUE;
25329+ } /* if */
2526025330 cssp->construction_by_bitwise_copy_allowed = FALSE;
2526125331 } /* if */
25262- if (user_provided_copy_assignment_op) {
25332+ if (user_provided_copy_assignment_op &&
25333+ !user_provided_copy_functions_are_masked(cssp->assignment_operator,
25334+ /*is_move=*/FALSE)) {
2526325335 cssp->makes_copy_assignment_nontrivial = TRUE;
2526425336 } /* if */
25265- if (cssp->has_user_provided_move_assign_operator) {
25337+ if (cssp->has_user_provided_move_assign_operator &&
25338+ !user_provided_copy_functions_are_masked(cssp->assignment_operator,
25339+ /*is_move=*/TRUE)) {
2526625340 cssp->makes_move_assignment_nontrivial = TRUE;
2526725341 } /* if */
2526825342 if (cssp->makes_copy_assignment_nontrivial ||
25343+ user_provided_copy_assignment_op ||
2526925344 cssp->has_user_provided_move_assign_operator) {
2527025345 cssp->assignment_by_bitwise_copy_allowed = FALSE;
2527125346 } /* if */
0 commit comments