[cfe-commits] Clang change to detect and warn about unused private members

Nico Weber thakis at chromium.org
Wed Jan 11 13:49:15 PST 2012

Hi Daniel,

On Wed, Jan 11, 2012 at 1:11 AM, Daniel Jasper <djasper at google.com> wrote:
> Hi,
> the attached change is designed to detect and warn about private unused
> members of C++ classes. It checks whether a class is fully defined in the
> current translation unit, i.e. all methods are either defined or pure
> virtual and all friends are defined. Otherwise, the private member could be
> used by a function defined in another translation unit.

that's a cool warning! Here are a few cases where it flags false
positives (it finds tons of true positives too, but those are boring
:-) ).

It flags |stackArray| in ICU's cmemory.h. This is declared for storage
and accessed through pointer aliasing, probably not much that can be
done about this:

In flags StaticResource::instance_ in v8's utils.h:
This is supposed to be accessed through the class below, Access, which
is a friend of utils.h. Do you check if any friends use private

In chromium itself, it flags ShadowingAtExitManager member variables.
This is basically a RAII class which only exists to call a protected
superclass constructor, and which only exists if UNIT_TESTS is
defined: http://codesearch.google.com/codesearch#OAMlx_jo-ck/src/base/at_exit.h&l=71
So maybe the "constructor without arguments" heuristic could be
tweaked to exclude constructors that call superclass constructors with
(Here's another RAII class whose constructor takes 0 arguments:

(This is not an exhaustive list, just the things I found after a quick look.)


More information about the cfe-commits mailing list