Warning on template parameter identifier shadowing?

Johan j at j.nl
Wed Aug 5 21:56:34 UTC 2020


On Wednesday, 5 August 2020 at 16:35:12 UTC, Paul Backus wrote:
> On Wednesday, 5 August 2020 at 16:22:48 UTC, Steven 
> Schveighoffer wrote:
>> On 8/5/20 12:10 PM, Paul Backus wrote:
>>> 
>>> Not a fan. There are cases where I've done this 
>>> intentionally--not with eponymous template members, but with 
>>> private helper templates:
>>> 
>>> template foo(T) {
>>>      enum helper(T) = ...; // error?
>>>      void foo(T i) {
>>>          static if (helper!T) ...;
>>>          else ...;
>>>      }
>>> }

Can you explain the "intentionally"? What purpose did it serve to 
name the template parameters the same? (in the code given, if you 
only ever used helper!T, you could have made "helper" a 
non-templated enum)

template foo(T) {
      enum helper = ...uses T...;
      void foo(T i) {
          static if (helper) ...;
          else ...;
      }
}

>>
>> I've intentionally done that, and even though it worked, 
>> rewrote the template parameter names because it's confusing to 
>> read.
>>
>> It would have to be a long deprecation cycle.
>>
>> I would be in favor of the change.
>>
>> -Steve
>
> "Confusing to read" does not justify a compiler warning.

Actually, I think it does. There are not many other reasons I can 
think of for why we have the existing "warnings".

The bigger problem is that warnings are all or nothing, instead 
of being able to disable/enable warnings to what the user likes 
[*]. So there is no way to gently add warnings and get user 
experience and feedback.

-Johan

[*] https://github.com/dlang/dmd/pull/5592




More information about the Digitalmars-d mailing list