llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.84k stars 11.47k forks source link

Add a checker to detected unmodified variables #17264

Open llvmbot opened 11 years ago

llvmbot commented 11 years ago
Bugzilla Link 16890
Version unspecified
OS MacOS X
Reporter LLVM Bugzilla Contributor
CC @belkadan

Extended Description

I think if it would be nice if the following reported some kind of error:

int foo() { int i = 0;

 return i;

}

where a variable is never modified (to me, this indicates that some code that modified the variable is missing). If the variable is really not supposed to change, the user can declare it as "const" (or use a #define).

belkadan commented 11 years ago

That's mostly what I meant. It's a checker whose usefulness is strongly dependent on the conventions and style guidelines of a particular codebase. I'll add it to the potential checkers list.

llvmbot commented 11 years ago

I'm not sure what you mean by a "style checker".

This is a check that many people might not want and so should be disabled by default, but I think it would be valuable to have as an option.

belkadan commented 11 years ago

This is /definitely/ a style checker, since in LLVM at least we often use temporary variables just to break up large expressions. Marking local variable const could certainly be considered good practice, but it's not something people do often, especially not for pointers.

llvmbot commented 11 years ago

assigned to @tkremenek