]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: wrong error due to std::initializer_list opt [PR116476]
authorMarek Polacek <polacek@redhat.com>
Wed, 28 Aug 2024 19:45:49 +0000 (15:45 -0400)
committerMarek Polacek <polacek@redhat.com>
Wed, 28 Aug 2024 22:45:54 +0000 (18:45 -0400)
commit9f79c7ddff5f1b004803931406ad17eaba095fff
treed0b1fed04d4679645a4f39e719b609cdd764c410
parentb8ef805e4d850971b9926fd81b4f0612ddffaf82
c++: wrong error due to std::initializer_list opt [PR116476]

Here maybe_init_list_as_array gets elttype=field, init={NON_LVALUE_EXPR <2>}
and it tries to convert the init's element type (int) to field
using implicit_conversion, which works, so overall maybe_init_list_as_array
is successful.

But it constifies init_elttype so we end up with "const int".  Later,
when we actually perform the conversion and invoke field::field(T&&),
we end up with this error:

  error: binding reference of type 'int&&' to 'const int' discards qualifiers

So I think maybe_init_list_as_array should try to perform the conversion,
like it does below with fc.

PR c++/116476

gcc/cp/ChangeLog:

* call.cc (maybe_init_list_as_array): Try convert_like and see if it
worked.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/initlist-opt2.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/call.cc
gcc/testsuite/g++.dg/cpp0x/initlist-opt2.C [new file with mode: 0644]