New issue
Advanced search Search tips

Issue 812621 link

Starred by 1 user

Issue metadata

Status: Unconfirmed
Owner: ----
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

Clang plugin should allow auto to deduce std::array iterators

Project Member Reported by jdoerrie@chromium.org, Feb 15 2018

Issue description

The chromium-style plugin currently makes it impossible to use auto to deduce std::array iterators. std::array<T, N>::iterator is implementation defined, and clang implements this as T*. 

This results in the chromium-style plugin complaining about usages such as

std::array<int, 3> arr = {1, 2, 3};
auto found = std::find(arr.begin(), arr.end(), 3);

since it demands auto* when a raw pointer is deduced [1]. However, simply changing the example to

std::array<int, 3> arr = {1, 2, 3};
auto* found = std::find(arr.begin(), arr.end(), 3);

does not work either, since std::array<T, N>::iterator is not a pointer on all platforms. For example in Debug builds it can happen that this is a fully fledged class with built in bound checks. Hence the snippet above does not compile [2].

Currently the only way is to not use auto and use the fully qualified type instead [3]:

std::array<int, 3> arr = {1, 2, 3};
std::array<int, 3>::iterator found = std::find(arr.begin(), arr.end(), 3);

This seems suboptimal and ideally we should modify the chromium-style plugin to allow

std::array<int, 3> arr = {1, 2, 3};
auto found = std::find(arr.begin(), arr.end(), 3);

since this works with all other STL containers as well (except std::initializer_list, but std::initializer_list<T>::iterator is guaranteed to be const T*, so we could use auto* here).

[1] https://crrev.com/c/921521
[2] https://crrev.com/c/921522
[3] https://crrev.com/c/921229
 

Comment 1 by sdy@chromium.org, Mar 12 2018

Labels: -OS-Mac
[Mac triage]
Components: -Internals

Sign in to add a comment