Menu

False positive unusedPrivateFunction when using trailing return type

2024-07-23
2024-07-23
  • Stefan Büttner

    Stefan Büttner - 2024-07-23

    Hey there,

    I stumbled over this behavior which seems weird and a false positive:

    #include <string>
    
    class foobar
    {
    public:
        [[nodiscard]] std::string const& foo() const noexcept { return _a; }
        [[nodiscard]] auto bar() const noexcept -> std::string const& { return _a; }
    
    private:
        std::string _a{};
    };
    
    >$ cppcheck --version
    Cppcheck 2.14.0
    $> cppcheck --enable=performance foobar.cpp
    Checking foobar.cpp ...
    foobar.cpp:6:24: performance: Function 'bar()' should return member '_a' by const reference. [returnByReference]
        [[nodiscard]] auto bar() const noexcept -> std::string const& { return _a; }
                           ^
    

    Can someone confirm or am I missing something?

    Cheers,
    Stefan

     
  • Stefan Büttner

    Stefan Büttner - 2024-07-23

    As you can see by the title, I found the another, related thread, wanted to name this one similar but forgot to change the title appropriately 🤦‍♂️
    Maybe you can still do that.

     
  • CHR

    CHR - 2024-07-23

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

     

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.