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

Daniel Jasper djasper at google.com
Thu Jan 12 10:19:17 PST 2012


Hi,

comments inline.

On Wed, Jan 11, 2012 at 9:02 PM, Matthieu Monrocq <
matthieu.monrocq at gmail.com> wrote:

>
>
> Le 11 janvier 2012 10:11, Daniel Jasper <djasper at google.com> a écrit :
>
> 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.
>>
>> An initializer does not count as "use", if:
>> - the member is a primitive type
>> - the member is a pointer
>> - the initializer does not take any arguments
>>
>> Kind regards,
>> Daniel
>>
>>
> Hello Daniel,
>
> it sounds like a fairly useful warning :)
>
> I only have two comments regarding the patch itself:
>
> > is it necessary to actually have UnusedPrivateFields and
> (Not)FullyDefinedCXXRecords as members of Sema ?  They could be passed (by
> reference) to IsRecordFullyDefinedInTranslationUnit which could then be
> marked `const` (unless I missed something)
>

I will change that, probably according to Chandler's suggestion (make it
static helper function).


> > there is no test case
>

Sorry, I forgot to include that in the patch (there actually is a test). I
will include it in the next version.

Cheers,
Daniel


>
> Nice patch.
>
> -- Matthieu
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120112/7e0bbc1e/attachment.html>


More information about the cfe-commits mailing list