Menu

False positive: [functionConst] returned non-const reference

2020-07-15
2020-07-17
  • Andreas Grob

    Andreas Grob - 2020-07-15
    struct A {
        int x = 1;
        auto get() -> int & { return x; }
    };
    
    int main() {
        A a;
        int &x = a.get();
        ++x;
    }
    

    cppcheck: commit 62702a6
    built with: make MATCHCOMPILER=yes FILESDIR=/usr/share/cppcheck HAVE_RULES=yes

    $ cppcheck --enable=all --inconclusive main.cpp
    Checking main.cpp ...
    main.cpp:3:10: style:inconclusive: Technically the member function 'A::get' can be const. [functionConst]
        auto get() -> int & { return x; }
             ^
    
     
  • Daniel Marjamäki

    Thanks! I have created ticket https://trac.cppcheck.net/ticket/9814

     

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.