Menu

False positive: functionStatic, template member function

2020-11-12
2020-11-12
  • Andreas Grob

    Andreas Grob - 2020-11-12
    struct A {
        int a = 1;
        void test() { f(0, 0); }
        template <typename T> void f(int x, T y) { a = 2; }
    };
    
    int main() {
        A a;
        a.f<int>(0, 0);
    }
    

    With 324e267:

    $ cppcheck --debug-normal --enable=style --inconclusive test.cpp 
    Checking test.cpp ...
    
    
    ##file test.cpp
    1: struct A {
    2: int a ; a = 1 ;
    3: void test ( ) { f (@7 0 , 0 ) ; }
    4: void f<int> ( int x , int y ) ;
    5: } ;
    6:
    7: int main ( ) {
    8: A a@4 ;
    9: a@4 .@8 f<int> (@9 0 , 0 ) ;
    10: } void A :: f<int> ( int x , int y ) { a@1 = 2 ; }
    
    
    
    ##Value flow
    Line 2
      1 always 1
    Line 3
      0 always 0
      0 always 0
    Line 9
      0 always 0
      0 always 0
    Line 4
      2 always 2
    test.cpp:3:10: performance:inconclusive: Technically the member function 'A::test' can be static (but you may consider moving to unnamed namespace). [functionStatic]
        void test() { f(0, 0); }
             ^
    
     
  • Daniel Marjamäki

     

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.