Menu

false positive constParameterReference

2024-05-15
2024-05-15
  • Rob Deckers

    Rob Deckers - 2024-05-15

    I am getting a false-positive constParameterReference in my constructor where I also have a lambda function which uses a non-const function.

    Someclass.hpp: style: Parameter 'dh' can be declared as reference to const [constParameterReference]
    explicit SomeClass(Handler& dh)

    Simplified code:

        // constructor
        explicit SomeClass(Handler& dh)
            : logTimer_{std::chrono::milliseconds{5000U}}
            , dialogHndlr_{dh}
            , cb_{[this](const std::string& input) {
                dialogHndlr_.Dowork(); 
                return true;
            }}
        {
        }
    
        Timer logTimer_;
    
        // Dialog handler
        Handler& dialogHndlr_;
        Handler::CallbackType cb_;
    

    Dowork- function changes dialogHndlr_, so it's non-const.

    When I remove the logtimer, the false-positive is gone.

     
  • CHR

    CHR - 2024-05-15

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

     

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.