[cfe-dev] -Wunused-* where macros declare multiple things

Matt Beaumont-Gay matthewbg at google.com
Mon Nov 5 16:54:40 PST 2012


On Mon, Nov 5, 2012 at 4:46 PM, David Blaikie <dblaikie at gmail.com> wrote:
> While evaluating the viability of Clang's -Wunused-* warnings
> (specifically -Wunused-variable, -Wunused-function, and
> -Wunused-member-function*) we've run in to some fairly noisy but
> common idioms involving macros.
>
> Most obviously about 30% of -Wunused-member-function warnings came
> from uses of GMock. When defining a mocking member, GMock's macros
> define two member functions (one being, commonly, the function
> overriding the function to mock) and a member variable. In a
> reasonable number of cases the second member function (the one used to
> set expectations) is not called.
>
> While not being deeply familiar with gmock, I believe this is a
> reasonably valid use case & would cause the test to fail should that
> member function ever be called (essentially an implicit expectation of
> "never call").
>
> (I've seen a smaller number of cases of -Wunused-function/variable due
> to non-gmock but similar macros that define multiple things some of
> which are used/important)
>
> In the interests of making this warning viable for use in such a
> codebase, I'm considering a few of options:
>
> 1) ignore any -Wunused-* when the thing being ignored is written inside a macro

+1. I was going to write just such a patch for -Wunused-value; macros
are the only significant source of false positives I've seen for this
warning.

-Matt



More information about the cfe-dev mailing list