Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vector (iterator,iterator) constructor doesn't deduce second arg #46841

Closed
kepler-5 opened this issue Sep 11, 2020 · 4 comments
Closed

vector (iterator,iterator) constructor doesn't deduce second arg #46841

kepler-5 opened this issue Sep 11, 2020 · 4 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla confirmed Verified by a second party libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@kepler-5
Copy link
Contributor

kepler-5 commented Sep 11, 2020

Bugzilla Link 47497
Version unspecified
OS All
CC @kamleshbhalui,@mclow

Extended Description

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 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.

@kepler-5
Copy link
Contributor Author

assigned to @kamleshbhalui

@kepler-5
Copy link
Contributor Author

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.

@mclow
Copy link
Contributor

mclow commented Sep 21, 2020

The following code compiles w/o error:
std::vector v(std::istream_iterator{}, {});

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@llvmbot llvmbot added the confirmed Verified by a second party label Jan 26, 2022
@ldionne
Copy link
Member

ldionne commented Sep 8, 2023

There was a review open here to fix this: https://reviews.llvm.org/D88727

However, this seems to have been fixed somewhere between Clang 15 and Clang 16: https://godbolt.org/z/5EWWconno. I'll make sure we have tests for this and I'll close.

@ldionne ldionne closed this as completed Sep 8, 2023
ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this issue Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla confirmed Verified by a second party libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

No branches or pull requests

4 participants