This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/77495] New: optional<T> assignment from {} acts weirdly
- From: "eric at efcs dot ca" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 06 Sep 2016 03:13:42 +0000
- Subject: [Bug libstdc++/77495] New: optional<T> assignment from {} acts weirdly
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77495
Bug ID: 77495
Summary: optional<T> assignment from {} acts weirdly
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: eric at efcs dot ca
Target Milestone: ---
Assignment to optional<T> from {} acts differently depending on if 'T' can be
constructed from {} without a used defined conversion. If so then then
operator=(U&&) is selected. Otherwise operator=(optional&&) is selected after
converting {} to optional<T>.
Reproducer:
#include <optional>
#include <cassert>
using namespace std;
struct T { T() = default; };
int main() {
optional<int> oi(in_place);
oi = {}; // converts {} to int because conversion isn't user defined.
assert(oi.has_value() == true);
optional<T> ot(in_place);
ot = {}; // converts {} to optional<T> then calls operator=(optional&&)
assert(ot.has_value() == false);
}