Skip to content

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

Closed
@ecorm

Description

@ecorm

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang-tidyconfirmedVerified by a second partyenhancementImproving things as opposed to bug fixing, e.g. new or missing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions