Menu

false positive on local variable when template specialization used

2019-11-11
2019-11-13
  • Jyrki Kolho

    Jyrki Kolho - 2019-11-11

    Looks like a false positive on the return statement of the global function:

    class Foo {
        template <unsigned int i>
        bool bar()
        {
            return true;
        }
    };
    
    template <>
    bool Foo::bar<9>()
    {
        return true;
    }
    
    int global()
    {
        int bar = 1;     // Reusing the name of the template function
        return bar;
    }
    

    false_positive.cpp:18:12: error: Uninitialized variable: bar < 9 > [uninitvar]
    return bar;
    ^

     
  • versat

    versat - 2019-11-13

    I am absolutely no template expert, but I agree that this looks like a false positive.
    g++ accepts the code without complaints. The debug output of Cppcheck looks a bit strange.
    I will create a ticket for that.

     
  • versat

    versat - 2019-11-13

    I have created a ticket: https://trac.cppcheck.net/ticket/9467
    Thank you for your report!

     

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.