Is there any tool / way to detect/remove all unused variables,macros,headers(includes) and functions from c++ code? -
i had customize projects have been written other purpose core functionality same project , works is. there lots of variables, macros,functions etc.. not useful current context , making code uneasy read , unnecessarily big.
so started removing variables macros functions etc.. using "find references" , "show call graph" in netbeans. i'm using netbeans remote development tools c/c++. cumbersome. there tool clean up??
from know there no tool things have mentioned, there 1 helps in cleaning unused include headers: include-what-you-use
"include use" means this: every symbol (type, function variable, or macro) use in foo.cc, either foo.cc or foo.h should #include .h file exports declaration of symbol. include-what-you-use tool program can built clang libraries in order analyze #includes of source files find include-what-you-use violations, , suggest fixes them.
the main goal of include-what-you-use remove superfluous #includes. both figuring out #includes not needed file (for both .cc , .h files), , replacing #includes forward-declares when possible.
one might expect clang static analyzer this, see the availalbe checks not offer such things.
this might time suggest feature request analyzer or create separate tool using libtooling on similar par tools described @ clang tools
in meantime, i'd suggest enable -wall , -wextra compiler flags, trigger following warnings (among others)(see gcc docs below):
- -wunused-function
- -wunused-label
- -wunused-value
- -wunused-variable
- -wunused-parameter
- -wunused-but-set-parameter
if reason don't want that, add -wunused enable above -wunused options combined, without other flags -wall or -wextra adds.
but in order warning unused function parameter, must either specify -wextra -wunused (note -wall implies -wunused), or separately specify -wunused-parameter.
of course, means have cleanup manually
if want pedantic might convert warnings errors adding -pedantic-errors flag
for more details read gcc warnings options documentation.
Comments
Post a Comment