Menu

Unused functions in namespace not detected

Mad Max
2019-04-09
2019-04-10
  • Mad Max

    Mad Max - 2019-04-09

    Hi,

    If I define an unused function like this, it's properly detected as unused by cppcheck:

    namespace abc {
      void iAmNotUsed() {
      }
    }
    

    But if I define it like this, it's not detected:

    void abc::iAmNotUsed() {
    }
    

    In both cases the function is declared in a header file inside the "abc" namespace. Both are equivalent, so IMO both should work. I'm trying to use cppcheck to detect unused functions in our large code base, but I can't do it because of this problem. Thank you.

     
  • Robert Reif

    Robert Reif - 2019-04-09

    Are you providing namespace abc somehow?

    namespace abc {
      void iAmNotUsed();
    }
    
    void abc::iAmNotUsed() { }
    

    gives:

    ./cppcheck used.cpp --enable=all --inconclusive
    Checking used.cpp ...
    [used.cpp:5]: (style) The function 'iAmNotUsed' is never used.
    

    Are you setting the include paths properly?

     
  • Mad Max

    Mad Max - 2019-04-10

    Indeed, I didn't set the include path. Thank you!

     

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.