Menu

constParameterCallback false positive when parameter is already a const iterator

2021-09-22
2021-09-23
  • Steve Albright

    Steve Albright - 2021-09-22

    This one might be debatable but when the parameter type is already a const iterator does it make sense to also want it to be const?

    style: constParameter - Parameter 'it' can be declared with const

    #include <list>
    
    void constParameterCallbackFalsePositiveExample(std::list<long>::const_iterator& it)
    {
       if(*it)
       {
       }
    }
    
     
  • Daniel Marjamäki

    imho this is a true positive. This code is also compilable and will change the iterator:

    #include <list>
    std::list<long> globalList;
    void f(std::list<long>::const_iterator& it)
    {
        it = globalList.cend();
    }
    
     

    Last edit: Daniel Marjamäki 2021-09-23
  • Steve Albright

    Steve Albright - 2021-09-23

    OK, I can go along with that explanation, thanks.

     

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.