[Bug c++/71446] Incorrect overload resolution when using designated initializers
jakub at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Feb 28 16:06:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71446
--- Comment #11 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
So like (untested):
--- gcc/call.c.jj 2019-02-28 08:14:58.251562934 +0100
+++ gcc/call.c 2019-02-28 17:04:49.697357298 +0100
@@ -819,7 +819,7 @@ build_list_conv (tree type, tree ctor, i
conversion **subconvs = alloc_conversions (len);
conversion *t;
unsigned i;
- tree val;
+ tree val, idx;
/* Within a list-initialization we can have more user-defined
conversions. */
@@ -833,8 +833,12 @@ build_list_conv (tree type, tree ctor, i
|| VOID_TYPE_P (elttype))
return NULL;
- FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), i, val)
+ FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), i, idx, val)
{
+ /* If there are any designators, ck_list is not valid. */
+ if (idx != NULL_TREE)
+ return NULL;
+
conversion *sub
= implicit_conversion (elttype, TREE_TYPE (val), val,
false, flags, complain);
@@ -1030,7 +1034,7 @@ build_complex_conv (tree type, tree ctor
unsigned HOST_WIDE_INT len = CONSTRUCTOR_NELTS (ctor);
tree elttype = TREE_TYPE (type);
unsigned i;
- tree val;
+ tree idx, val;
bool bad = false;
bool user = false;
enum conversion_rank rank = cr_exact;
@@ -1040,8 +1044,12 @@ build_complex_conv (tree type, tree ctor
flags = LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING;
- FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), i, val)
+ FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), i, idx, val)
{
+ /* If there are any designators, complex conv is not valid. */
+ if (idx != NULL_TREE)
+ return NULL;
+
conversion *sub
= implicit_conversion (elttype, TREE_TYPE (val), val,
false, flags, complain);
@@ -1896,7 +1904,7 @@ implicit_conversion (tree to, tree from,
if (nelts == 0)
elt = build_value_init (to, tf_none);
- else if (nelts == 1)
+ else if (nelts == 1 && CONTRUCTOR_ELT (expr, 0)->index == NULL_TREE)
elt = CONSTRUCTOR_ELT (expr, 0)->value;
else
elt = error_mark_node;
More information about the Gcc-bugs
mailing list