https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99417
Bug ID: 99417
Summary: [C++17] std::variant assignment fails to compile
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: arthur.j.odwyer at gmail dot com
Target Milestone: ---
// https://godbolt.org/z/b3P6Ta
#include <variant>
struct Original {};
struct C {
C(const Original&);
C(C&&) noexcept;
C& operator=(const Original&);
~C();
};
void testc(std::variant<C>& vc, const Original& original) {
vc = original;
}
In file included from <source>:1:/include/c++/11.0.1/variant:1445:3:
error: call to deleted member function 'operator='
operator=(variant(std::forward<_Tp>(__rhs)));
^~~~~~~~~
<source>:13:8: note: in instantiation of function template specialization
'std::variant<C>::operator=<const Original &>' requested here
vc = original;
^
/include/c++/11.0.1/variant:1368:16: note: candidate function has been
implicitly deleted
variant& operator=(const variant&) = default;
^
/include/c++/11.0.1/variant:1431:2: note: candidate template ignored:
requirement '__not_self<std::variant<C> &&>' was not satisfied [with _Tp =
std::variant<C>]
operator=(_Tp&& __rhs)
^
1 error generated.
Removing the keyword `noexcept` from the move-constructor makes this compile.
It compiles fine (with or without `noexcept`) on libc++ and MSVC STL.