Menu ▾ ▴

FP: constVariableReference when using a vector of reference_wrapper items

3 days ago
3 days ago
  • Dan Workman

    Dan Workman - 3 days ago

    Found in cppcheck 2.22

    Running
    cppcheck --enable=style --std=c++17 --template=gcc repro.cpp

    on

    #include <functional>
    #include <vector>
    
    struct Item {};
    
    void example()
    {
        Item value;
        auto& ref = value;
        std::vector<std::reference_wrapper<Item>> refs{ref};
    }
    

    gives
    Variable 'ref' can be declared as reference to const [constVariableReference]

     
  • CHR

    CHR - 3 days ago

    Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15103

     

Log in to post a comment.