[cfe-dev] More extensive unused variable checks

Daniel B Mosesson dmosess1 at binghamton.edu
Tue Apr 9 15:14:45 PDT 2013


Is there any work that is being done on making the unused variable
warning more extensive?

for example:

#include<vector>
void test() {
    std::vector<int> a;
    a.push_back(1);
}
int main() {
    test();
    return 0;
}

Is there any work on saying that test() is a function that will never
do anything, and therefore can be optimized out (and throw a warning
that says that `a` is unused?

I was thinking that perhaps there was a to achieve this with
generalized attributes on the containers and their functions to
determine if an operation was a "load" or "store" type of function,
and then objects that only call one of those two types of instructions
would throw a warning (either unused and can be optimized out, or will
cause undefined behavior).

While I would expect this to be rather straightforward when it comes
to containers (assuming that the possibility of optimizing out
individual entries in the container is excluded), it would be also
interesting to see if a similar idea can be applied to other parts of
the STL.

If there is no work that is being done on this already, is this
something that is
1) useful
2) relatively simple



More information about the cfe-dev mailing list