c++: Fix wrong conversion error with non-viable overload [PR94124]
authorMarek Polacek <polacek@redhat.com>
Tue, 10 Mar 2020 22:55:42 +0000 (18:55 -0400)
committerMarek Polacek <polacek@redhat.com>
Wed, 11 Mar 2020 03:12:41 +0000 (23:12 -0400)
commite11d05c1ed26257493130762a8ae240f1bc06e87
tree637dab153ef59698c03e1513b71568a444ca724a
parent481fcfe6fec156ca2a6baea4b623076e2eefa6a6
c++: Fix wrong conversion error with non-viable overload [PR94124]

This is a bad interaction between sharing a constructor for an array
and stripping its trailing zero-initializers.  Here we reuse a ctor
and then strip its 0s.  This breaks overload resolution in this test:
D can be initialized from {} but not from {0}, so if we truncate the
constructor not to include the zero, the F(D) overload becomes valid
and then we get the ambiguous conversion error.

PR c++/94124 - wrong conversion error with non-viable overload.
* decl.c (reshape_init_array_1): Unshare a constructor if we
stripped trailing zero-initializers.

* g++.dg/cpp0x/initlist-overload1.C: New test.
gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/initlist-overload1.C [new file with mode: 0644]