[cfe-dev] [Patch] Diagnose unused declaration
Ted Kremenek
kremenek at apple.com
Sat Jan 3 11:41:14 PST 2009
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.
More information about the cfe-dev
mailing list