I am particularly interested in learning about LLVM 4.1, but will also be interested in the behavior of other compilers.
According to the GCC documentation (which LLVM supports, at least in part), the unused attribute has the following behavior:
This attribute, attached to a variable, means that the variable is meant to be possibly unused. GCC will not produce a warning for this variable.
If the compiler can warn you about unused parameters and variables, then, apparently, it already knows which parameters and variables are not used, unless you say so (especially since the unused attribute only indicates that the variable may not used). Therefore, does the unused attribute allow the compiler to perform any additional optimizations, or is its purpose simply to allow more readable code? Also, if the unused attribute really allows the compiler to perform additional optimizations, what happens if you really use the parameter or variable specified as unused ? LLVM (in Xcode) did not seem to complain about this case, although it is possible that I did not compile at the right level of optimization or with the correct warnings turned on.
source share