Repository navigation
<vector>: Iterator range constructor does not enforce implicit conversion requirement #107
Description
Activity
- changed the title
[-]<vector>: Iterator range constructor violates implicit conversion requirement[/-][+]<vector>: Iterator range constructor does not enforce implicit conversion requirement[/+]on Sep 17, 2019 CaseyCarter commented
on Sep 17, 2019 ContributorMore actionsThe vast majority of requirements that "
foobe implicitly convertible tobar" in the C++ Standard are defects since the library almost never performs implicit conversions; this occurrence is no exception to the rule. The sequence container requirements useiandjin three different places:-
The range constructors
X(i, j)andX u(i, j)you mention, which require that the container's value type isCpp17EmplaceConstructibleinto the container (implicit conversion is neither necessary nor sufficient) [Aside: The semantic requirements are insufficient to support the "Constructs a sequence container equal to the range[i, j)" effect - the implicit conversion requirement doesn't help here.] -
The range insert overload
a.insert(p, i, j)which also requiresCpp17EmplaceConstructible(again, implicit conversion is neither necessary nor sufficient) -
The range assign overload
a.assign(i, j)which requires bothCpp17EmplaceConstructibleas above and that it can assign the result of dereferencing an iterator directly to the container's value type (again, implicit conversion wouldn't be useful here).
The proper fix here isn't to enforce the unnecessary requirement, it's to strike it from the C++ Standard.
-
- addedLWG issue neededA wording defect that should be submitted to LWG as a new issueA wording defect that should be submitted to LWG as a new issue
on Sep 17, 2019 CaseyCarter commented
on Sep 17, 2019 ContributorMore actionsI've submitted a request to open an LWG issue to correct this wording defect, I'll followup here with the issue number when one is assigned.
Reacted by Stephan T. Lavavej and Michael Schellenberger Costamiscco commented
on Sep 18, 2019 ContributorAuthorMore actionsYeah I thought so too, as all mayor Libraries do the same. Nevertheless strange that it is -still- in the standard
miscco commented
on Sep 18, 2019 ContributorAuthorMore actionsWhat is strange is that the range constructor has no the requirement on
Cpp17EmplaceConstructible. In contrast see vector.cons, where the sized constructors have anRequiresclause of eitherCpp17DefaultInsertableorCpp17CopyInsertableMaybe one should add
§9 Requires: value_type shall be Cpp17EmplaceConstructible from *first.
CaseyCarter commented
on Sep 18, 2019 ContributorMore actionsWhat is strange is that the range constructor has no the requirement on
Cpp17EmplaceConstructible.The requirement is present for those constructors, it's over in the sequence container requirements table.
miscco commented
on Sep 18, 2019 ContributorAuthorMore actionsGrml, why is the Requires clause mentioned explicitely again for
vector(n, t)but notvector(i, j)?I am generally against repeating oneself in a specification but that seems like a valid exception.
CaseyCarter commented
on Sep 23, 2019 ContributorMore actionsI've submitted a request to open an LWG issue to correct this wording defect, I'll followup here with the issue number when one is assigned.
This is now LWG 3297. Thanks for the report!
- addedfixedSomething works now, yay!Something works now, yay!LWG issue neededA wording defect that should be submitted to LWG as a new issueA wording defect that should be submitted to LWG as a new issueand removedLWG issue neededA wording defect that should be submitted to LWG as a new issueA wording defect that should be submitted to LWG as a new issuefixedSomething works now, yay!Something works now, yay!
on Sep 24, 2019 - addedresolvedSuccessfully resolved without a commitSuccessfully resolved without a commitand removed
on Oct 2, 2019 there should be a diagnostic about the missing conversion
Ignoring the fact this requirement is bogus anyway, the library is under no obligation to diagnose such mistakes by users. Failing to meet that requirement results in undefined behaviour, and compiling it without complaint is a valid implementation.
Describe the bug
The standard states in the requirements for the constructors of 26.2.3 Sequence containers [sequence.reqmts] §3
Importantly it requires that the elements behind input iterators
iandjare implicitly convertible tovalue_type. However, it seems that this requirement is ignored. See the following minimal example:Expected behavior
Similar to the equivalent code snippet
there should be a diagnostic about the missing conversion
Additional context
The culprit seem to be _Range_construct_or_tidy that utilizes
emplace_back.I believe that calling
push_backinstead would enforce the implicit conversion requirement