[llvm-bugs] [Bug 47497] New: vector (iterator, iterator) constructor doesn't deduce second arg

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Sep 11 11:04:19 PDT 2020


            Bug ID: 47497
           Summary: vector (iterator,iterator) constructor doesn't deduce
                    second arg
           Product: libc++
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: logan.r.smith0 at gmail.com
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com

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.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200911/1c8a018d/attachment.html>

More information about the llvm-bugs mailing list