[Bug libstdc++/77288] Std::experimental::optional::operator= implementation is broken in gcc 6.1

2017-03-01 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77288

Jonathan Wakely  changed:

   What|Removed |Added

 CC||krisk0.2017.02.27@protonmai
   ||l.com

--- Comment #14 from Jonathan Wakely  ---
*** Bug 79743 has been marked as a duplicate of this bug. ***

[Bug libstdc++/77288] Std::experimental::optional::operator= implementation is broken in gcc 6.1

2016-10-24 Thread ville at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77288

--- Comment #12 from ville at gcc dot gnu.org ---
Author: ville
Date: Mon Oct 24 12:52:31 2016
New Revision: 241477

URL: https://gcc.gnu.org/viewcvs?rev=241477=gcc=rev
Log:
Backport from mainline:

2016-10-24  Ville Voutilainen  

Cross-port the latest resolution of LWG2756 and some
bug-fixes to experimental::optional.
PR libstdc++/77288
PR libstdc++/77727
* include/experimental/optional (_Optional_base):
Remove constructors that take a _Tp.
(__is_optional_impl, __is_optional): Remove.
(__converts_from_optional): New.
(optional(_Up&&)): Fix constraints, call base with in_place.
(optional(const optional<_Up>&)): Fix constraints, use emplace.
(optional(optional<_Up>&&)): Likewise.
(operator=(_Up&&)): Fix constraints.
(operator=(const optional<_Up>&)): Likewise.
(operator=(optional<_Up>&&)): Likewise.
(emplace(_Args&&...)): Constrain.
(emplace(initializer_list<_Up>, _Args&&...)): Likewise.
* testsuite/experimental/optional/77288.cc: New.
* testsuite/experimental/optional/assignment/5.cc: Adjust.
* testsuite/experimental/optional/cons/77727.cc: New.
* testsuite/experimental/optional/cons/value.cc: Adjust.

Added:
branches/gcc-6-branch/libstdc++-v3/testsuite/experimental/optional/77288.cc
   
branches/gcc-6-branch/libstdc++-v3/testsuite/experimental/optional/cons/77727.cc
  - copied, changed from r241461,
branches/gcc-6-branch/libstdc++-v3/testsuite/experimental/optional/assignment/5.cc
Modified:
branches/gcc-6-branch/libstdc++-v3/ChangeLog
branches/gcc-6-branch/libstdc++-v3/include/experimental/optional
   
branches/gcc-6-branch/libstdc++-v3/testsuite/experimental/optional/assignment/5.cc
   
branches/gcc-6-branch/libstdc++-v3/testsuite/experimental/optional/cons/value.cc

[Bug libstdc++/77288] Std::experimental::optional::operator= implementation is broken in gcc 6.1

2016-10-24 Thread ville.voutilainen at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77288

Ville Voutilainen  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #13 from Ville Voutilainen  ---
Fixed.

[Bug libstdc++/77288] Std::experimental::optional::operator= implementation is broken in gcc 6.1

2016-10-24 Thread ville at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77288

--- Comment #11 from ville at gcc dot gnu.org ---
Author: ville
Date: Mon Oct 24 12:46:44 2016
New Revision: 241476

URL: https://gcc.gnu.org/viewcvs?rev=241476=gcc=rev
Log:
Cross-port the latest resolution of LWG2756 and some
bug-fixes to experimental::optional.
PR libstdc++/77288
PR libstdc++/77727
* include/experimental/optional (_Optional_base):
Remove constructors that take a _Tp.
(__is_optional_impl, __is_optional): Remove.
(__converts_from_optional): New.
(optional(_Up&&)): Fix constraints, call base with in_place.
(optional(const optional<_Up>&)): Fix constraints, use emplace.
(optional(optional<_Up>&&)): Likewise.
(operator=(_Up&&)): Fix constraints.
(operator=(const optional<_Up>&)): Likewise.
(operator=(optional<_Up>&&)): Likewise.
(emplace(_Args&&...)): Constrain.
(emplace(initializer_list<_Up>, _Args&&...)): Likewise.
* testsuite/experimental/optional/77288.cc: New.
* testsuite/experimental/optional/assignment/5.cc: Adjust.
* testsuite/experimental/optional/cons/77727.cc: New.
* testsuite/experimental/optional/cons/value.cc: Adjust.

Added:
trunk/libstdc++-v3/testsuite/experimental/optional/77288.cc
trunk/libstdc++-v3/testsuite/experimental/optional/cons/77727.cc
  - copied, changed from r241475,
trunk/libstdc++-v3/testsuite/experimental/optional/assignment/5.cc
Modified:
trunk/libstdc++-v3/ChangeLog
trunk/libstdc++-v3/include/experimental/optional
trunk/libstdc++-v3/testsuite/experimental/optional/assignment/5.cc
trunk/libstdc++-v3/testsuite/experimental/optional/cons/value.cc

[Bug libstdc++/77288] Std::experimental::optional::operator= implementation is broken in gcc 6.1

2016-09-21 Thread ville.voutilainen at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77288

--- Comment #10 from Ville Voutilainen  ---
And yes, I plan to port this fix to experimental::optional on trunk and then
backport that.

[Bug libstdc++/77288] Std::experimental::optional::operator= implementation is broken in gcc 6.1

2016-09-21 Thread ville.voutilainen at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77288

--- Comment #9 from Ville Voutilainen  ---
Fixed on trunk so far.

[Bug libstdc++/77288] Std::experimental::optional::operator= implementation is broken in gcc 6.1

2016-09-21 Thread ville at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77288

--- Comment #8 from ville at gcc dot gnu.org ---
Author: ville
Date: Wed Sep 21 17:37:17 2016
New Revision: 240324

URL: https://gcc.gnu.org/viewcvs?rev=240324=gcc=rev
Log:
PR libstdc++/77288
* include/std/optional (__is_optional_impl, __is_optional): Remove.
(__converts_from_optional, __assigns_from_optional): New.
(optional(_Up&&)): Use is_same instead of __is_optional.
(optional(const optional<_Up>&)): Constrain with
__converts_from_optional.
(optional(optional<_Up>&&)): Likewise.
(operator=(_Up&&)): Use is_same instead of __is_optional, check
is_same and is_scalar.
(operator=(const optional<_Up>&)): Constrain with
__converts_from_optional and __assigns_from_optional.
(operator=(optional<_Up>&&)): Likewise.
* testsuite/20_util/optional/77288.cc: New.
* testsuite/20_util/optional/cons/value.cc: Adjust.

Added:
trunk/libstdc++-v3/testsuite/20_util/optional/77288.cc
Modified:
trunk/libstdc++-v3/ChangeLog
trunk/libstdc++-v3/include/std/optional
trunk/libstdc++-v3/testsuite/20_util/optional/cons/value.cc

[Bug libstdc++/77288] Std::experimental::optional::operator= implementation is broken in gcc 6.1

2016-08-23 Thread ville.voutilainen at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77288

--- Comment #7 from Ville Voutilainen  ---
See https://gcc.gnu.org/ml/gcc-patches/2016-08/msg01634.html for what the
aforementioned superior approach looks like.

[Bug libstdc++/77288] Std::experimental::optional::operator= implementation is broken in gcc 6.1

2016-08-21 Thread ville.voutilainen at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77288

--- Comment #6 from Ville Voutilainen  ---
There's a superior fix that retains conversions but doesn't cause this
regression. Stay tuned.

[Bug libstdc++/77288] Std::experimental::optional::operator= implementation is broken in gcc 6.1

2016-08-18 Thread ville.voutilainen at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77288

--- Comment #5 from Ville Voutilainen  ---
Ah. That would indeed mean that every converting assignment introduces
a temporary. Design-wise I'd rather have it so that optional doesn't convert
at all in the assignment. :)

[Bug libstdc++/77288] Std::experimental::optional::operator= implementation is broken in gcc 6.1

2016-08-18 Thread dawid_jurek at vp dot pl
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 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 
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 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

[Bug libstdc++/77288] Std::experimental::optional::operator= implementation is broken in gcc 6.1

2016-08-18 Thread ville.voutilainen at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77288

--- Comment #3 from Ville Voutilainen  ---
>Now behaviour is the same as in gcc 5.1 - operator=(_Up&& __u) is chosen in 2 
>situations:
>1. _Up is NOT optional
>2. _Up is optional AND _Up is same as _Tp modulo cv-qualifiers, references etc.

How do you expect converting assignments to work if that signature
sfinaes away if decay<_Up> is not _Tp? As in, code like

optional os;
os = "meow";

[Bug libstdc++/77288] Std::experimental::optional::operator= implementation is broken in gcc 6.1

2016-08-18 Thread ville.voutilainen at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77288

Ville Voutilainen  changed:

   What|Removed |Added

 Status|UNCONFIRMED |ASSIGNED
   Last reconfirmed||2016-08-18
 CC||ville.voutilainen at gmail dot 
com
   Assignee|unassigned at gcc dot gnu.org  |ville.voutilainen at 
gmail dot com
 Ever confirmed|0   |1

--- Comment #2 from Ville Voutilainen  ---
Mine.

[Bug libstdc++/77288] Std::experimental::optional::operator= implementation is broken in gcc 6.1

2016-08-18 Thread dawid_jurek at vp dot pl
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77288

--- Comment #1 from dawid_jurek at vp dot pl ---
Created attachment 39471
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=39471=edit
Fix bug in operator=