Open AlexGuteniev opened 4 years ago
Apparently I believed this was by design when I saw it initially reported, but I was busy with <charconv>
and didn't write up a full analysis. Need to check.
Per [sequence.reqmts]/3 the arguments to the various constructor/insert/assign overloads that accept ranges must be "iterators that meet the Cpp17InputIterator
requirements and refer to elements implicitly convertible to value_type
". By violating this requirement, the repro has undefined behavior.
(Note that LWG-3297 wants to strike this requirement, which would render the program well-defined with the behavior we implement.)
Note that LWG-3297 wants to strike this requirement, which would render the program well-defined with the behavior we implement.
I agree that having this case undefined is an issue, classes with explicit constructor are common, so something well defined should be done here.
However, doing explicit conversion inside insert
seems to violate least surprise principle, and defeat the purpose of explicit constructor.
To me, only emplace_*
methods should be allowed to do this, if any at all.
Also got tripped by that issue due to standard libraries behaving differently. Intuitively I think it should not be allowed without explicit cast e.g. through ranges::views::transform
, even if due to iterator interface this form of casting is not the most convenient still.
I agree that having this case undefined is an issue, classes with explicit constructor are common, so something well defined should be done here.
What should happen if is_convertible_v<iter_reference_t<It>, value_type>
is true
but the construction (possibly via Alloc::construct
) is not equivalent to the implicit conversion?
Note that there's uses-allocator construction, and some weird types can make difference between explicit cast and implicit conversion while both are well-formed.
Describe the bug STL allows range-based insertion to vector (and other containers) thru implicit conversion operator
Command-line test case
Expected behavior Should not compile
STL version
Additional context Also tracked by DevCom-275079 and VSO-636498 / AB#636498