llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.25k stars 11.67k forks source link

[clang-tidy] readability-qualified-auto and std::array iterators #63461

Open ecorm opened 1 year ago

ecorm commented 1 year ago

readability-qualified-auto suggests const auto* when initializing an auto variable with a std::array iterator value that happens to be implemented as a raw pointer.

The suggested change is not portable, as the standard only requires that a contiguous_iterator be returned, which does not necessarily have to be a raw pointer.

Example:

#include <array>

int main()
{
    std::array<int, 3> array = {{0, 1, 2}};
    auto iter = array.cbegin();
    return *iter;
}

Clang-Tidy output:

[<source>:6:5: warning: 'auto iter' can be declared as 'const auto *iter' [readability-qualified-auto]]

Godbolt demo: https://godbolt.org/z/Taraa7zxK

llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-tidy

PiotrZSL commented 1 year ago

Yes, would be good to ignore iterators. Or even better have configurable list of ignored types.