@@ -16401,7 +16401,10 @@ ultimate binding is to an rvalue reference .
1640116401 } /* if */
1640216402 } else if (conv_context & CCO_ALLOW_EXPLICIT_CONV_FUNCTIONS) {
1640316403 /* We've been told specifically to allow explicit conversion
16404- functions. */
16404+ functions (possibly only those that return a reference). */
16405+ if (conv_context & CCO_EXPLICIT_CONV_FUNCTIONS_RETURN_REF) {
16406+ require_reference_return = TRUE;
16407+ } /* if */
1640516408 } else {
1640616409 goto reject_function;
1640716410 } /* if */
@@ -28193,6 +28196,32 @@ will be an lvalue instead of the usual prvalue.
2819328196 in reproducing the source when the cp_gen_be is used. */
2819428197 rmake_lvalue_temp = TRUE;
2819528198 } /* if */
28199+ if (is_direct_init &&
28200+ (clang_version_is(any_version) || gnu_version_is(<90000) ||
28201+ ms_version_is(<1929) ||
28202+ (ms_version_is(any_version) && ms_permissive))) {
28203+ /* Core issue 2267 clarified that the temporary is copy-list-
28204+ initialized even when the reference is direct-list-initialized,
28205+ and so explicit conversion functions cannot be used to initialize
28206+ it. For example:
28207+ struct A { explicit operator int(); } a;
28208+ int &&r{a}; // Error.
28209+ Clang, g++ before version 9, and MSVC in permissive mode (and
28210+ before version 19.29 also in non-permissive mode) accept such
28211+ cases, though. */
28212+ rconv_context |= CCO_ALLOW_EXPLICIT_CONV_FUNCTIONS;
28213+ } else if (is_direct_init && gnu_version_is(>= 140000)) {
28214+ /* g++ 14 and later bind the reference directly to the result of a
28215+ conversion function that returns a reference (a proposed resolution
28216+ of Core issue 1996), and that binding may use an explicit conversion
28217+ function:
28218+ struct B { explicit operator int&&(); };
28219+ int &&r{B{}}; // Okay with g++ 14.
28220+ Approximate that by allowing such conversion functions for the
28221+ initialization of the temporary. */
28222+ rconv_context |= CCO_ALLOW_EXPLICIT_CONV_FUNCTIONS |
28223+ CCO_EXPLICIT_CONV_FUNCTIONS_RETURN_REF;
28224+ } /* if */
2819628225 /* The cost of a reference initialization in overload resolution is the
2819728226 cost of the underlying initialization of the temporary, so pass
2819828227 arg_match down to the next level. See below for class cases. */
@@ -28201,7 +28230,7 @@ will be an lvalue instead of the usual prvalue.
2820128230 /*is_direct_init=*/FALSE,
2820228231 /*check_narrowing=*/TRUE,
2820328232 /*warning_on_narrowing=*/FALSE,
28204- rconv_context | CCO_ALLOW_EXPLICIT_CONV_FUNCTIONS ,
28233+ rconv_context,
2820528234 /*fill_in_dtor=*/TRUE,
2820628235 /*force_temp=*/TRUE,
2820728236 rmake_lvalue_temp,
0 commit comments