[Bug libstdc++/77495] New: optional<T> assignment from {} acts weirdly
eric at efcs dot ca
gcc-bugzilla@gcc.gnu.org
Tue Sep 6 03:13:00 GMT 2016
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);
}
More information about the Gcc-bugs
mailing list