[cfe-dev] More extensive unused variable checks

David Blaikie dblaikie at gmail.com
Sun Apr 14 22:17:56 PDT 2013

On Tue, Apr 9, 2013 at 3:14 PM, Daniel B Mosesson
<dmosess1 at binghamton.edu> wrote:
> 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

So far as I know, no. As you say, this would probably require some
attribute scheme to have a reasonable chance of quality. Did you have
some other ideas in mind about how you might overcome this?

- David

More information about the cfe-dev mailing list