Menu

[regression] missing [constVariableReference] when iterating a std::map

2025-06-09
2025-06-10
  • Leander Schulten

    Given the following code

    std::map<std::sting, std::vector<std::string>> map;
    void test(){
        for(const auto &entry : map){
            auto& names = entry.second;
            for(auto &name : names) {
                std::cout << name << std::endl;
            }
        }
    }
    

    I got

    example_const_ref.cpp:5:19: style: Variable 'name' can be declared as reference to const [constVariableReference]
            for(auto &name : names) {
                      ^
    

    before https://github.com/danmar/cppcheck/commit/6fc4d3624ba47de14f59244ec5fe9e5550f68309
    but with this commit the warning is not reported anymore (which is wrong).

     
  • Oliver Stöneberg

    Thanks.

    Confirmed and filed as https://trac.cppcheck.net/ticket/13925.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.