aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/call.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2019-09-16 00:34:18 -0400
committerJason Merrill <jason@gcc.gnu.org>2019-09-16 00:34:18 -0400
commita4d034d714f5799d3038aaf85347923686c7db64 (patch)
tree74df2a5ace26eaa90aa1fa2b11c5367181549389 /gcc/cp/call.c
parentc4438114d6133f4266be57b8678c49badbe60145 (diff)
downloadgcc-a4d034d714f5799d3038aaf85347923686c7db64.zip
gcc-a4d034d714f5799d3038aaf85347923686c7db64.tar.gz
gcc-a4d034d714f5799d3038aaf85347923686c7db64.tar.bz2
Fix conversions for built-in operator overloading candidates.
While working on C++20 operator<=>, I noticed that build_new_op_1 was doing too much conversion when a built-in candidate was selected; the standard says it should only perform user-defined conversions, and then leave the normal operator semantics to handle any standard conversions. This is important for operator<=> because a comparison of two different unscoped enums is ill-formed; if we promote the enums to int here, cp_build_binary_op never gets to see the original operand types, so we can't give the error. * call.c (build_new_op_1): Don't apply any standard conversions to the operands of a built-in operator. Don't suppress conversions in cp_build_unary_op. * typeck.c (cp_build_unary_op): Do integral promotions for enums. From-SVN: r275744
Diffstat (limited to 'gcc/cp/call.c')
-rw-r--r--gcc/cp/call.c51
1 files changed, 25 insertions, 26 deletions
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index c3045d9..457fa66 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -6139,41 +6139,40 @@ build_new_op_1 (const op_location_t &loc, enum tree_code code, int flags,
break;
}
- /* We need to strip any leading REF_BIND so that bitfields
- don't cause errors. This should not remove any important
- conversions, because builtins don't apply to class
- objects directly. */
+ /* "If a built-in candidate is selected by overload resolution, the
+ operands of class type are converted to the types of the
+ corresponding parameters of the selected operation function,
+ except that the second standard conversion sequence of a
+ user-defined conversion sequence (12.3.3.1.2) is not applied." */
conv = cand->convs[0];
- if (conv->kind == ck_ref_bind)
- conv = next_conversion (conv);
- arg1 = convert_like (conv, arg1, complain);
+ if (conv->user_conv_p)
+ {
+ while (conv->kind != ck_user)
+ conv = next_conversion (conv);
+ arg1 = convert_like (conv, arg1, complain);
+ }
if (arg2)
{
conv = cand->convs[1];
- if (conv->kind == ck_ref_bind)
- conv = next_conversion (conv);
- else
- arg2 = decay_conversion (arg2, complain);
-
- /* We need to call warn_logical_operator before
- converting arg2 to a boolean_type, but after
- decaying an enumerator to its value. */
- if (complain & tf_warning)
- warn_logical_operator (loc, code, boolean_type_node,
- code_orig_arg1, arg1,
- code_orig_arg2, arg2);
-
- arg2 = convert_like (conv, arg2, complain);
+ if (conv->user_conv_p)
+ {
+ while (conv->kind != ck_user)
+ conv = next_conversion (conv);
+ arg2 = convert_like (conv, arg2, complain);
+ }
}
+
if (arg3)
{
conv = cand->convs[2];
- if (conv->kind == ck_ref_bind)
- conv = next_conversion (conv);
- convert_like (conv, arg3, complain);
+ if (conv->user_conv_p)
+ {
+ while (conv->kind != ck_user)
+ conv = next_conversion (conv);
+ arg3 = convert_like (conv, arg3, complain);
+ }
}
-
}
}
@@ -6241,7 +6240,7 @@ build_new_op_1 (const op_location_t &loc, enum tree_code code, int flags,
case REALPART_EXPR:
case IMAGPART_EXPR:
case ABS_EXPR:
- return cp_build_unary_op (code, arg1, candidates != 0, complain);
+ return cp_build_unary_op (code, arg1, false, complain);
case ARRAY_REF:
return cp_build_array_ref (input_location, arg1, arg2, complain);