How to get g++ to warn on unused member variables

前端 未结 3 586
傲寒
傲寒 2021-02-12 23:34

g++ generates warnings for unused local variables. Is it possible to have g++ warn for unused class member variables and/or global variables?

class Obj {
 public         


        
3条回答
  •  孤独总比滥情好
    2021-02-12 23:58

    Clang's -Wunused-private-field enables the warning you're asking for. On your code base, it shows:

    $ clang -Wunused-private-field /tmp/nic.cpp  
    /tmp/nic.cpp:10:22: warning: private field 'num2' is not used [-Wunused-private-field]
                 int num2;
                     ^
    1 warning generated.
    

提交回复
热议问题