Docs: Section on local variables
bearophile
bearophileHUGS at lycos.com
Thu Apr 26 05:12:45 PDT 2012
Timon Gehr:
> Andrej Mitrovic:
>> Keeping variables clean
>> is the responsibility of the programmer and not the compiler.
>>
>> If it doesn't affect the semantics of code the compiler should
>> shut up. Please don't turn the compiler into a reincarnation
>> of Clippy.
>
> +1.
I think currently the D compiler doesn't shut up in some cases.
Comparing the unused variable warning with Clippy is not good.
Clippy gives suggestions, while here the compiler is giving
something more like an error message.
> Another thing: It might not be unused in every static code path.
>
> Even more important:
>
> template isInputRange(R)
> {
> enum bool isInputRange = is(typeof(
> {
> R r; // can define a range object
> if (r.empty) {} // can test for empty
> r.popFront(); // can invoke popFront()
> auto h = r.front; // can declare an unused variable
> }()));
> }
If the unused variable is a warning, and I use "-wi" that code
compiles.
The warning for unused variables helps me clean up my C code and
has avoided me more than one bug. So I'd like this optional
warning in the D front-end. I'd even like a warning for variables
assigned and then later never read again.
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list