https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109937
Bug ID: 109937
Summary: Spurious ambiguous overload error when class with
explicit template ctor is assigned to from an
braced-init-list initializing an aggregate
Product: gcc
Version: 13.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: enolan at alumni dot cmu.edu
Target Milestone: ---
This example should invoke dummy's operator=(foo&&), but GCC 13 instead
erroneously complains that it is ambiguous whether it should instead select
dummy's automatically generated move assignment operator, which it cannot do
because dummy's ctor is explicit.
Compiler explorer link: https://godbolt.org/z/MsjsK1dav
Minimal reproduction:
struct foo {
int x;
};
struct dummy {
template<typename U>
explicit dummy(U&&);
dummy() = default;
dummy& operator=(foo&&);
};
int main() {
dummy bar;
bar = {1};
}
> The exact version of GCC
gcc version 13.1.1 20230511 (Red Hat 13.1.1-2) (GCC)
> The system type
Fedora release 38 (Thirty Eight)
> the options given when GCC was configured/built
Configured with: ../configure --enable-bootstrap
--enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,m2,lto --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared
--enable-threads=posix --enable-checking=release --enable-multilib
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-gnu-unique-object --enable-linker-build-id
--with-gcc-major-version-only --enable-libstdcxx-backtrace
--with-libstdcxx-zoneinfo=/usr/share/zoneinfo --with-linker-hash-style=gnu
--enable-plugin --enable-initfini-array
--with-isl=/builddir/build/BUILD/gcc-13.1.1-20230511/obj-x86_64-redhat-linux/isl-install
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-offload-defaulted --enable-gnu-indirect-function --enable-cet
--with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
--with-build-config=bootstrap-lto --enable-link-serialization=1
> the complete command line that triggers the bug
g++ poc.cpp
> the compiler output
poc.cpp: In function 'int main()':
poc.cpp:14:13: error: ambiguous overload for 'operator=' (operand types are
'dummy' and '<brace-enclosed initializer list>')
14 | bar = {1};
| ^
poc.cpp:9:12: note: candidate: 'dummy& dummy::operator=(foo&&)'
9 | dummy& operator=(foo&&);
| ^~~~~~~~
poc.cpp:5:8: note: candidate: 'constexpr dummy& dummy::operator=(const dummy&)'
5 | struct dummy {
| ^~~~~
poc.cpp:5:8: note: candidate: 'constexpr dummy& dummy::operator=(dummy&&)'