Detector for unused variables
Jonathan M Davis
jmdavisProg at gmx.com
Wed Aug 1 08:57:19 PDT 2012
On Wednesday, August 01, 2012 17:07:31 Timon Gehr wrote:
> On 08/01/2012 12:38 PM, bearophile wrote:
> > Regan Heath:
> >> Indeed. IIRC Walter's rationale on things like this has always been
> >> that they belong in 3rd party tools.
> >
> > Walter is not always right.
> >
> >> It's why the DMD front end is available for use, so people can create
> >> tools like this, syntax highlighters, re-formatters, dependency tree
> >> diagrams, or... you name it.
> >
> > Detecting unused variables is a core feature,
>
> No. This mustn't be part of the language.
>
> http://d.puremagic.com/issues/show_bug.cgi?id=7989
>
> > it belongs in the
> > compiler, like compile-time array bound tests and other errors currently
> > detected by DMD. This allows everyone to use it with minimum work, so
> > everyone enjoys it, and it requires less work to be implemented because
> > the compiler already does lot of analysis.
>
> It is not an error. Making things that are not errors illegal is prone
> to introduce bugs into code using __traits(compiles).
>
> This can be a warning at best.
And you can't have anything be a warning if it's not something that should
always be fixed, because it's never good practice to leave warnings in your
code (especially since if you do, it becomes difficult to see the ones that
actually matter). The fact that D has -w makes it that much critical that a
warning be _guaranteed_ to be something that should be fixed.
And unused variables have too many valid use cases in D: template constraints,
generic code, RAII, etc. You can't make them either an error, and if you can't
make them an error, you can't make them a warning. The only real difference
between an error and a warning as far as dmd goes is if it's something that
must _always_ be fixed before your code can compile. It's not something that
should be left in your source code in either case, and given how many people
compile with -w, there's often effectively zero difference between warnings and
errors when using dmd.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list