Menu

Possible new check

2016-08-29
2016-08-31
  • AnotherUser

    AnotherUser - 2016-08-29

    Dear Cppcheck team,

    The following code was pointed out as an error using another checker
    tool, as the class member is shadowed in the member function.

    This may be of interest as a --inconclusive error, perhaps excluding
    const members or member functions:

    ====
    class A
    {
    private:
    int a;
    public:
    A() { a=0;}
    void set(int);
    };

    void A::set(int a)
    {
    a=1;
    }
    ====

    Neither gcc nor Cppcheck 1.74 does not flag this error, as far as I can see.

    $ cppcheck --version
    Cppcheck 1.74
    $ g++ --version | head -n 1
    g++ (Debian 5.4.0-6) 5.4.0 20160609
    $ g++ test.cpp -Wall -o test -c
    $cppcheck --inconclusive test.cpp
    Checking test.cpp...

    Thanks.

     
  • raynebc

    raynebc - 2016-08-30

    The shadowing compiler warning can be enabled with "-Wshadow"

     
  • Daniel Marjamäki

    Thanks!

    There is this ticket about detecting shadow variables:
    http://trac.cppcheck.net/ticket/1384

     

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.