This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/77288] Std::experimental::optional::operator= implementation is broken in gcc 6.1
- From: "dawid_jurek at vp dot pl" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 18 Aug 2016 16:51:36 +0000
- Subject: [Bug libstdc++/77288] Std::experimental::optional::operator= implementation is broken in gcc 6.1
- Authentication-results: sourceware.org; auth=none
- Auto-submitted: auto-generated
- References: <bug-77288-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77288
--- Comment #4 from dawid_jurek at vp dot pl ---
After applying my patch code snippet you provided compile, run and works as
expected. To be more precise I'm talking about such snippet:
std::experimental::optional<std::string> os;
os = "meow";
assert(bool(os) && *os == "meow");
You are right that operator=(_Up&& __u) won't be choose here as overload
candidate.
Anyway there is converting constructor:
template <typename _Up, .. >
constexpr optional(_Up&& __t)
and generated move constructor:
optional<_Tp>::optional(optional<_Tp>::optional<_Tp>&& )
Let's see what happen when flow achieve expression: os = "meow"
1. Call optional::optional<_Tp>::optional(_Up&& __t) where _Tp = std::string,
_Up = char const (&) [13]
for r-value "meow" and create temporary optional<std::string> containing
"meow".
2. Call generated
optional::optional<_Tp>::optional(optional<_Tp>::optional<_Tp>&& ) where _Tp =
std::string
and just transfer ownership from temporary optional to os.
3. Now os is engaged, os contains "meow" and assertion is happy.
Regards,
Dawid