www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Detector for unused variables

reply "Namespace" <rswhite4 googlemail.com> writes:
I wrote a short programm which detect and list unused variables.
I'm sure it isn't perfect but it passed most of my test cases, 
but I think at the moment it isn't good enough to present it in 
announce. Maybe some of you have interest to help me. IMO 
something like this should be integrated into the D compiler.

Comments, suggestions and critism are desirable.

Code: http://dpaste.dzfl.pl/c5f1d2ba
Some of my testcases: http://dpaste.dzfl.pl/f74da85e
Jul 30 2012
next sibling parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Namespace:
 I wrote a short programm which detect and list unused variables.
I suggest to attach both code and testcases to: http://d.puremagic.com/issues/show_bug.cgi?id=3960 Even if your code will never be used, it shows Walter&Andrei that there is interest in having this warning, and test cases are useful for other implementations too. Bye, bearophile
Jul 30 2012
next sibling parent reply "Namespace" <rswhite4 googlemail.com> writes:
On Monday, 30 July 2012 at 16:47:32 UTC, bearophile wrote:
 Namespace:
 I wrote a short programm which detect and list unused 
 variables.
I suggest to attach both code and testcases to: http://d.puremagic.com/issues/show_bug.cgi?id=3960 Even if your code will never be used, it shows Walter&Andrei that there is interest in having this warning, and test cases are useful for other implementations too. Bye, bearophile
I think my english isn't good enough to make a persuasive comment there, but i will try it this evening. I will simply copy my post above. Andrej Mitrovic: Maybe automatically if you use -w or -wi.
Jul 30 2012
parent "bearophile" <bearophileHUGS lycos.com> writes:
Namespace:

 I think my english isn't good enough to make a persuasive 
 comment there, but i will try it this evening. I will simply 
 copy my post above.
Your English skills seems enough, but in the end what's important is to show that some people care to have for this warning. Walter is usually right, but once in a while he's wrong, and some stubbornness is needed to show it :) Bye, bearophile
Jul 30 2012
prev sibling parent reply "Namespace" <rswhite4 googlemail.com> writes:
 I suggest to attach both code and testcases to:
 http://d.puremagic.com/issues/show_bug.cgi?id=3960
Done.
Jul 30 2012
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Namespace:

 I suggest to attach both code and testcases to:
 http://d.puremagic.com/issues/show_bug.cgi?id=3960
Done.
I see no attachments :-( Only ephemeral links. Bye, bearophile
Jul 30 2012
parent reply "Namespace" <rswhite4 googlemail.com> writes:
On Monday, 30 July 2012 at 17:39:31 UTC, bearophile wrote:
 Namespace:

 I suggest to attach both code and testcases to:
 http://d.puremagic.com/issues/show_bug.cgi?id=3960
Done.
I see no attachments :-( Only ephemeral links. Bye, bearophile
Sorry, but i can upload only one file. I will upload my unused_vars.d immediately. Jonathan M Davis: Walter hates so much things, nearly all what the community wishes for: not null types, warnings for unused variables, warnings for unused imports and so on. It does not only count what he wants but what is useful, IMO.
Jul 30 2012
parent reply "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On Monday, July 30, 2012 20:39:02 Namespace wrote:
 Jonathan M Davis:
 Walter hates so much things, nearly all what the community wishes
 for: not null types, warnings for unused variables, warnings for
 unused imports and so on.
 It does not only count what he wants but what is useful, IMO.
Plenty of the community agrees with him too, much as there may be some vocal folks who don't. Regardless, because he's the gatekeeper of the reference compiler, he has to be convinced if you want a feature added to either the language or the compiler. He's generally quite reasonable, but he also has a high bar for feature changes. - Jonathan M Davis
Jul 30 2012
parent reply "Namespace" <rswhite4 googlemail.com> writes:
 Plenty of the community agrees with him too, much as there may 
 be some vocal
 folks who don't. Regardless, because he's the gatekeeper of the 
 reference
 compiler, he has to be convinced if you want a feature added to 
 either the
 language or the compiler. He's generally quite reasonable, but 
 he also
 has a high bar for feature changes.

 - Jonathan M Davis
That's right. But the majority of programming languages has this feature, but D does not. This feature is undeniable effective, so IMO there is no reason which stands against a warning for unused variables. Or can you tell me some personal reasons, without quoting Walter?
Jul 30 2012
next sibling parent reply "Namespace" <rswhite4 googlemail.com> writes:
BTW: Has anyone test my detector and could give me some 
suggestions or critism?
Jul 30 2012
next sibling parent reply Dmitry Olshansky <dmitry.olsh gmail.com> writes:
On 31-Jul-12 00:02, Namespace wrote:
 BTW: Has anyone test my detector and could give me some suggestions or
 critism?
I haven't tested it but offhand I call it inaccurate :) I had only cursory look at it but: regexes are way underpowered to do the task and thus false positives and false negatives are unavoidable. Just throw in more templates and mixins and it will fail ;) -- Dmitry Olshansky
Jul 30 2012
parent reply "Namespace" <rswhite4 googlemail.com> writes:
On Monday, 30 July 2012 at 20:06:42 UTC, Dmitry Olshansky wrote:
 On 31-Jul-12 00:02, Namespace wrote:
 BTW: Has anyone test my detector and could give me some 
 suggestions or
 critism?
I haven't tested it but offhand I call it inaccurate :) I had only cursory look at it but: regexes are way underpowered to do the task and thus false positives and false negatives are unavoidable. Just throw in more templates and mixins and it will fail ;)
As i said: it isn't perfect yet. ;) But maybe one of you could help me. And regex are the only way i know to scan code. And yes i know, sometimes warnings for unused variables _would_ be annoying but then we have to discuss if a new compiler switch is useful. IMO it is, but IMO a shorthand like "?" for not null types is similar useful. Maybe i expect to much, maybe i should use such programms only by myself.
Jul 30 2012
parent Dmitry Olshansky <dmitry.olsh gmail.com> writes:
On 31-Jul-12 00:45, Namespace wrote:
 On Monday, 30 July 2012 at 20:06:42 UTC, Dmitry Olshansky wrote:
 On 31-Jul-12 00:02, Namespace wrote:
 BTW: Has anyone test my detector and could give me some suggestions or
 critism?
I haven't tested it but offhand I call it inaccurate :) I had only cursory look at it but: regexes are way underpowered to do the task and thus false positives and false negatives are unavoidable. Just throw in more templates and mixins and it will fail ;)
As i said: it isn't perfect yet. ;) But maybe one of you could help me. And regex are the only way i know to scan code. And yes i know, sometimes warnings for unused variables _would_ be annoying but then we have to discuss if a new compiler switch is useful. IMO it is, but IMO a shorthand like "?" for not null types is similar useful.
Adding new language features is at best problematic at this point.
 Maybe i expect to much, maybe i should use such programms only by myself.
I see no problem with a special D tool (a-la lint) that will check this and other possible problems. -- Dmitry Olshansky
Jul 30 2012
prev sibling parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 7/30/12, Namespace <rswhite4 googlemail.com> wrote:
 BTW: Has anyone test my detector and could give me some
 suggestions or critism?
I've tried it out and it didn't find any unused variables, but I doubt this is true, I'm not very tidy when it comes to using variables. I do use a lot of templates so maybe the script bailed on those.
Jul 30 2012
parent "Namespace" <rswhite4 googlemail.com> writes:
On Monday, 30 July 2012 at 21:13:42 UTC, Andrej Mitrovic wrote:
 On 7/30/12, Namespace <rswhite4 googlemail.com> wrote:
 BTW: Has anyone test my detector and could give me some
 suggestions or critism?
I've tried it out and it didn't find any unused variables, but I doubt this is true, I'm not very tidy when it comes to using variables. I do use a lot of templates so maybe the script bailed on those.
Templates and object types aren't supported right now. But maybe next time. Until now only primitive types are being detected. But if you have code where you think my programm fails, then i'm very glad if you will post it here. :)
Jul 30 2012
prev sibling next sibling parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 07/30/2012 12:02 PM, Namespace wrote:

 there is no reason which stands against a warning for unused variables.
 Or can you tell me some personal reasons, without quoting Walter?
People comment-out parts of code during development and debugging, leaving unused variables behind (just for a while). Receiving compilation errors for those is not productive. (Warnings would be the same thing as they should be treated as errors.) Additionally, some unused variables do very important work (e.g. RAII structs). Should the compiler warn for only the ones that do not have side-effects in their constructors and destructors? Such questions are not easy to answer. Ali
Jul 30 2012
prev sibling parent reply "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On Monday, July 30, 2012 21:02:14 Namespace wrote:
 That's right. But the majority of programming languages has this
 feature, but D does not. This feature is undeniable effective, so
 IMO there is no reason which stands against a warning for unused
 variables. Or can you tell me some personal reasons, without
 quoting Walter?
Aside from the fact that it can be really annoying when the compiler complains about unused parameters? I believe that the bug report that you posted to includes some discussion on some of the technical issues caused by making unused variables a warning. In particular, it causes problems for generic code as well as template constraints. A _lot_ of templates used for template constraints would generate warnings if usused variables were a warning. So, if you were compiling with -w, it would become _very_ easy to have your program not compile. And there are plenty of cases where generated code ends up with unused variables, and it's fine. I grant you that it's undesirable to have unused variables sitting around in most functions, but there _are_ cases where disallowing that (as making it a warning effectively does) causes problems. This is the sort of thing that's better left to a lint-like tool IMHO. - Jonathan M Davis
Jul 30 2012
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Jonathan M Davis:

 This is the sort of thing that's
 better left to a lint-like tool IMHO.
Putting it in a lint means people have to know what a lint is, desire to search it, install, and add its running to their compilation ways. It also means the lint needs to contain part of a D compiler. Most people I know don't use lints for their C/C++ with no lint. So this idea is good if the lint is built in the compiler, as the analysis option of Clang, do you know about it? Bye, bearophile
Jul 30 2012
parent reply Dmitry Olshansky <dmitry.olsh gmail.com> writes:
On 31-Jul-12 01:37, bearophile wrote:
 Jonathan M Davis:

 This is the sort of thing that's
 better left to a lint-like tool IMHO.
Putting it in a lint means people have to know what a lint is, desire to search it, install, and add its running to their compilation ways.
Just run it once on each release candidate. People constantly seek tools to improve quality of their release code and catch possible bugs that should be enough of motivation to install lint.
It
 also means the lint needs to contain part of a D compiler.
Yeah when was the last time we had this compile as library "discussion"?
 Most people I
 know don't use lints for their C/C++ code.
Most people I know ignore warnings. "Most people I know" is hardly good enough argument. e.g. "most people I know hate tons of compiler switches"

 programmers see such errors on default, with no lint. So this idea is
 good if the lint is built in the compiler, as the analysis option of
 Clang, do you know about it?
I know but DMD won't have it in near future. Other compilers may do what they want to do. -- Dmitry Olshansky
Jul 30 2012
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Dmitry Olshansky:

 "Most people I know" is hardly good enough argument.
The point is that this warning is a basic thing, other compilers have it and I enjoy it in those languages and putting this feature into external tools is not going to help most D programmers.
 I know but DMD won't have it in near future.
There is a long list of things Walter has done to D/DMD in the last four years that initially seemed contrary to his opinions and nearly impossible to happen :-) Bugzilla shows that most of my most important enhancement requests have being accepted. Walter is not set in stone, he's sometimes very slow, but he never stops moving forward, unlike lot of other people I know.
Other compilers may do what they want to do.<
Right. If LDC/GDC introduce this warning and we are able to show its usefulness, maybe Walter will change his mind. In the last two years Walter has introduced in DMD many bugfixes and changes suggested by static analyzers/lints, including Clang, and he has removed several unused variables from DMD suggested by those tools :-] Bye, bearophile
Jul 30 2012
parent reply Dmitry Olshansky <dmitry.olsh gmail.com> writes:
On 31-Jul-12 02:02, bearophile wrote:
 Dmitry Olshansky:

 "Most people I know" is hardly good enough argument.
The point is that this warning is a basic thing, other compilers have it and I enjoy it in those languages and putting this feature into external tools is not going to help
I'm seeing the same argument over and over again :) most D programmers. -- Dmitry Olshansky
Jul 30 2012
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Dmitry Olshansky:

 I'm seeing the same argument over and over again :)

  most D programmers.
What do you look for? A language designed for 5-10% of its users? No thanks. Bye, bearophile
Jul 30 2012
parent reply "Minas" <minas_mina1990 hotmail.co.uk> writes:
I agree that having the compiler make warnings about unused
variables is a really good idea!!!

Java has it and when I program in eclipse it's really useful
because the editor can highlight the particular lines.
Jul 31 2012
parent Timon Gehr <timon.gehr gmx.ch> writes:
On 07/31/2012 11:55 AM, Minas wrote:
 I agree that having the compiler make warnings about unused
 variables is a really good idea!!!

 Java has it and when I program in eclipse it's really useful
 because the editor can highlight the particular lines.
An editor can be configured to point it out even if it is not in the language, if it is considered useful.
Jul 31 2012
prev sibling next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 7/30/12, Namespace <rswhite4 googlemail.com> wrote:
 IMO something like this should be integrated into the D compiler.
As long as it's togglable via a compiler switch. :)
Jul 30 2012
prev sibling next sibling parent reply "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On Monday, July 30, 2012 18:50:08 Andrej Mitrovic wrote:
 On 7/30/12, Namespace <rswhite4 googlemail.com> wrote:
 IMO something like this should be integrated into the D compiler.
As long as it's togglable via a compiler switch. :)
Walter doesn't like compiler switches like that, and he doesn't like it when the compiler complains about unused variables. So, I wouldn't expect it to happen, but anyone's free to create a pull request and try. - Jonathan M Davis
Jul 30 2012
parent reply "Regan Heath" <regan netmail.co.nz> writes:
On Mon, 30 Jul 2012 18:41:51 +0100, Jonathan M Davis <jmdavisProg gmx.com>  
wrote:

 On Monday, July 30, 2012 18:50:08 Andrej Mitrovic wrote:
 On 7/30/12, Namespace <rswhite4 googlemail.com> wrote:
 IMO something like this should be integrated into the D compiler.
As long as it's togglable via a compiler switch. :)
Walter doesn't like compiler switches like that, and he doesn't like it when the compiler complains about unused variables. So, I wouldn't expect it to happen, but anyone's free to create a pull request and try.
Indeed. IIRC Walter's rationale on things like this has always been that they belong in 3rd party tools. 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. R -- Using Opera's revolutionary email client: http://www.opera.com/mail/
Aug 01 2012
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
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, 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. Bye, bearophile
Aug 01 2012
next sibling parent reply "Regan Heath" <regan netmail.co.nz> writes:
On Wed, 01 Aug 2012 11:38:46 +0100, bearophile <bearophileHUGS lycos.com>  
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.
Well, in this case I agree with him. You're not looking at the big picture. If you make detecting un-used variables a /requirement/ for implementing a D compiler, you make it that much less likely someone will write one, which raises the bar for D's adoption. The reason why there are so few good C++ compilers is that the language is too hard to implement, we don't want D to go that way.
 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, it belongs in the compiler
Says you. I disagree. We may have gotten used to it being there, but it's not part of the "compilation" phase but rather part of the "development" phase and/or the "quality control" phase which are arguably the realm of the IDE or a "lint" checker.
 like compile-time array bound tests and other errors currently detected  
 by DMD.
The key word used here is "error". Unused variables do not affect the compilation of a program, they're simply ignored and have no effect. Array bounds errors will crash the program.
 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.
Sure, but everyone is not the bottleneck, Walter is. The work to implement it has to be done by someone, somewhere. If we make it a requirement for a D compiler then every D compiler writer has to do it, including Walter and as a result all D compilers will be that much worse for the wasted time/energy used to implement it, not to mention fix any bugs that arise - as they will be very visible - despite being almost irrelevant to the main purpose of the "compiler". If it's done by a 3rd party tool it will be done better - as more time can be spent on it, as it's a main feature of said tool, etc. In short, it's better for everyone if it's done in a 3rd party tool. Further, that tool could be fully integrated, i.e. distributed by/with the compiler and run as a pre or post compile step automatically such that to users it's indistinguishable whether the compiler or the tool is doing the work. All we need is someone to produce and maintain the tool, and for Walter to add it to the distribution and hook it into the compiler. Then, we can have competing tools, and competition breeds improvement.. R -- Using Opera's revolutionary email client: http://www.opera.com/mail/
Aug 01 2012
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Regan Heath:

 If you make detecting un-used variables a /requirement/ for 
 implementing a D compiler, you make it that much less likely 
 someone will write one,
Detecting unused variables can be written as a part of the front-end. It's meant to be shared by LDC and GDC that use the same front-end.
We may have gotten used to it being there, but it's not part of 
the "compilation" phase but rather part of the "development" 
phase and/or the "quality control" phase which are arguably the 
realm of the IDE or a "lint" checker.<
In theory you are right, in practice I don't know how much this idea is applicable to D/DMD and how much good it does. In Clang they have added a switch to perform extra static tests on the code. It's a feature built in the compiler. I think this is an acceptable place to put an unused variable warning in DMD. They have also built a stand alone analyzer, as you say: http://clang-analyzer.llvm.org/ But this isn't a fully isolated tool, it re-uses large parts of the compiler, it's like a plug-in. I think you can't do this with DMD (maybe it can be done with LDC, but we were talking about a portable tool for D).
 It also doesn't matter what another language choses to do.
compilers too. Looking at other languages is useful because the doesn't have C++/D-style templates, this may add some unused variables to D code, but the situation is not too much different.
Why you'd want an unused variable to be an error is beyond me - 
it has absolutely no effect on the resulting executable, if it 
did it would be a bug.<
For a D detector of unused variables I was asking for a warning, And regarding Go, I can't read the mind of the Go designers, but I think they don't like warnings, on the other hand they want a very tidy Go code, so they have made it an error. Go doesn't have templates and it seems so far its programmers are surviving to the presence of this error. They want tidy code because experience shows that often variables that are defined and not used are spots where the programmer has forgotten something, and sometimes some code is missing. Beside unused variables warning, I'd like another warning, unused last assignment warning, it helps find other bugs: http://d.puremagic.com/issues/show_bug.cgi?id=4694 Thank you, bye, bearophile
Aug 01 2012
parent "Regan Heath" <regan netmail.co.nz> writes:
On Wed, 01 Aug 2012 15:52:22 +0100, bearophile <bearophileHUGS lycos.com>  
wrote:
 Regan Heath:

 If you make detecting un-used variables a /requirement/ for  
 implementing a D compiler, you make it that much less likely someone  
 will write one,
Detecting unused variables can be written as a part of the front-end.
Or it can be written using the front-end.
 It's meant to be shared by LDC and GDC that use the same front-end.
Why?
 We may have gotten used to it being there, but it's not part of the  
 "compilation" phase but rather part of the "development" phase and/or  
 the "quality control" phase which are arguably the realm of the IDE or  
 a "lint" checker.<
In theory you are right, in practice I don't know how much this idea is applicable to D/DMD and how much good it does. In Clang they have added a switch to perform extra static tests on the code. It's a feature built in the compiler. I think this is an acceptable place to put an unused variable warning in DMD.
You're missing my main point which is that you can get the appearance of a compiler feature with a 3rd party tool bundled with the compiler, the difference/benefits of a 3rd party tool are: 1. The "feature" it implements is not a requirement for all D compilers. 2. Walter doesn't have to implement it. And more minor points include: 3. We can have competition between 3rd party vendors. 4. People can select/run their favorite tool. 5. A crashing tool/feature will no stop compilation. Basically, having a 3rd party tool will look exactly like a feature of the compiler, but it will be better for the reasons above. R
Aug 01 2012
prev sibling next sibling parent reply Andre Tampubolon <andre lc.vlsm.org> writes:
The Go compiler is able to detect unused variables, and strangely they 
are regarded as an error.

On 8/1/2012 5:38 PM, bearophile wrote:
 Detecting unused variables is a core feature, 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.

 Bye,
 bearophile
Aug 01 2012
parent "Regan Heath" <regan netmail.co.nz> writes:
On Wed, 01 Aug 2012 12:03:01 +0100, Andre Tampubolon <andre lc.vlsm.org>  
wrote:

 The Go compiler is able to detect unused variables, and strangely they  
 are regarded as an error.
It's not really a question of "able" to, or not. I'm sure were Walter to decide to add this feature to D he would also be "able" to. It also doesn't matter what another language choses to do. Why you'd want an unused variable to be an error is beyond me - it has absolutely no effect on the resulting executable, if it did it would be a bug. What matters, ultimately, from a user point of view is whether the feature exists or not. We can solve that by having a 3rd party tool bundled with the compiler and this would be the best solution for all the reasons outlined earlier. R -- Using Opera's revolutionary email client: http://www.opera.com/mail/
Aug 01 2012
prev sibling parent reply Timon Gehr <timon.gehr gmx.ch> writes:
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.
Aug 01 2012
next sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
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
Aug 01 2012
prev sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
Timon Gehr:

 No. This mustn't be part of the language.

 http://d.puremagic.com/issues/show_bug.cgi?id=7989
I agree there are some problems. But not putting this warning in the default language means such problems will not be faced at the language level itself too. So maybe no good solutions will be found to those problems. So maybe it needs to be an integrated & well designed feature of D.
 This can be a warning at best.
The enhancement request is for a warning :-) Bye, bearophile
Aug 01 2012
prev sibling next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 7/30/12, Jonathan M Davis <jmdavisProg gmx.com> wrote:
 Walter doesn't like compiler switches like that
Walter is a big fat phony, count the number of switches here: http://www.digitalmars.com/ctg/sc.html#switches :D
Jul 30 2012
prev sibling parent "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On Monday, July 30, 2012 20:08:12 Andrej Mitrovic wrote:
 On 7/30/12, Jonathan M Davis <jmdavisProg gmx.com> wrote:
 Walter doesn't like compiler switches like that
Walter is a big fat phony, count the number of switches here: http://www.digitalmars.com/ctg/sc.html#switches
That may be part of _why_ he doesn't like switches for enabling and disabling warnings and the like - that and as many switches are there, I'm not sure that any actually enable or disable specific warnings - which I believe is primarily what he's against. - Jonathan M Davis
Jul 30 2012