[cfe-dev] [Patch] Diagnose unused declaration
Neil Booth
neil at daikokuya.co.uk
Sat Jan 3 16:59:04 PST 2009
Ted Kremenek wrote:-
>
> On Jan 3, 2009, at 11:14 AM, EdB wrote:
>
> >> Looks good. There seems to be a whitespace issue in
> >> ActOnEndOfTranslationUnit.
> >
> > Pleased find attached a new version:
> > It fixed some crash.
> > Unused warning is no longer actived by default. You should enable it
> > with -Wunused_declaration
>
> I'm not certain that the approach here will work. Since an
> IdentifierInfo is not unique to a declaration using a bit in
> IdentifierInfo to perform this check will be ineffective in many
> cases. For example:
>
> void f() {
> int x = ...
> x++;
> }
>
> void g() {
> int x; // no warning will be issued
> }
>
> The other thing that bothers me about this is putting this bit in
> IdentifierInfo in the first place. It seems like a very invasive
> thing to do for a simple check like this, especially one that isn't
> always used. Generally we like to keep such information "on the side"
> unless there is a good reason not to. Why not use a DenseSet to keep
> track (on the side) of what declarations are used? You can then do
> this on a declaration based (i.e., for a particular NamedDecl) rather
> than using IdentifierInfo's in this conflated way.
Further, in standard C90
int z; sizeof z;
z is generally not considered "used". C99 adds more complexity.
In C++ the rules are vastly more complicated.
Neil.
More information about the cfe-dev
mailing list