LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 47497 - vector (iterator,iterator) constructor doesn't deduce second arg
Summary: vector (iterator,iterator) constructor doesn't deduce second arg
Status: CONFIRMED
Alias: None
Product: libc++
Classification: Unclassified
Component: All Bugs (show other bugs)
Version: unspecified
Hardware: PC All
: P enhancement
Assignee: Kamlesh Kumar
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-09-11 11:04 PDT by Logan R. Smith
Modified: 2020-10-02 03:47 PDT (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Logan R. Smith 2020-09-11 11:04:19 PDT
The following code is rejected by libc++ because the second iterator argument to vector(iterator, iterator) is not deduced (https://godbolt.org/z/q8f9Y7):

#include <iterator>
#include <iostream>
#include <vector>

int main() {
    std::vector<int> v({}, std::istream_iterator<int>{});
}

The the following code, however, is accepted (https://godbolt.org/z/nM4Yh4):

#include <iterator>
#include <iostream>
#include <vector>

int main() {
    std::vector<int> v;
    v.assign({}, std::istream_iterator<int>{});
}

I believe this to be a conformance bug.

I stumbled on this in my own code when I noticed that a typo in the following code was being accepted:

std::vector<int> v(other.cbegin(), other.end()); // note .end(), not .cend()

Since the second argument is not deduced, and the first argument is a const iterator, the second argument is implicitly converted to a const iterator. This is a symptom of the same issue, though I think this particular case could arguably be considered a conforming extension.
Comment 1 Logan R. Smith 2020-09-11 13:06:48 PDT
Rereading what I wrote, I think I was unclear, so I'd like to clarify. I believe the constructor call being rejected is the conformance bug. My mention of the .assign() call was just to show that similar arguments work when passed to a different entity. It is correct that the .assign() call is accepted as written.
Comment 2 Marshall Clow (home) 2020-09-21 08:18:22 PDT
The following code compiles w/o error:
    std::vector<int> v(std::istream_iterator<int>{}, {});