public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/99417] New: [C++17] std::variant assignment fails to compile
@ 2021-03-05 17:12 arthur.j.odwyer at gmail dot com
2023-05-16 10:08 ` [Bug libstdc++/99417] " redi at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: arthur.j.odwyer at gmail dot com @ 2021-03-05 17:12 UTC (permalink / raw)
To: gcc-bugs
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug libstdc++/99417] [C++17] std::variant assignment fails to compile
2021-03-05 17:12 [Bug libstdc++/99417] New: [C++17] std::variant assignment fails to compile arthur.j.odwyer at gmail dot com
@ 2023-05-16 10:08 ` redi at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2023-05-16 10:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99417
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|UNCONFIRMED |RESOLVED
Version|unknown |11.0
Target Milestone|--- |12.3
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I don't think this was a bug, at least not when you reported this. It was the
required behaviour prior to https://wg21.link/lwg3585
In the C++17 and C++20 standards variant<C>::operator=(const Original&) is
specified as:
(13.1) — If *this holds a Tj, assigns std::forward<T>(t) to the value contained
in *this.
(13.2) — Otherwise, if is_nothrow_constructible_v<Tj, T> ||
!is_nothrow_move_constructible_v<Tj> is true, equivalent to
emplace<j>(std::forward<T>(t)).
(13.3) — Otherwise, equivalent to operator=(variant(std::forward<T>(t))).
The second bullet is why the 'noexcept' on the move ctor matters, and it means
that we use the third bullet, but that won't compile because variant<C> is not
move assignable, because C is not move assignable.
So libc++ and MSVC were non-conforming in accepting this.
LWG 3585 changed the third bullet so that move assignment isn't needed. That
was implemented for libstdc++ by r13-5661-g1395415fdc2d60 and
r12-9450-ga5a03ea09ddf09.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-05-16 10:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-05 17:12 [Bug libstdc++/99417] New: [C++17] std::variant assignment fails to compile arthur.j.odwyer at gmail dot com
2023-05-16 10:08 ` [Bug libstdc++/99417] " redi at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).