Warning on template parameter identifier shadowing?

Paul Backus snarwin at gmail.com
Wed Aug 5 16:35:12 UTC 2020

On Wednesday, 5 August 2020 at 16:22:48 UTC, Steven Schveighoffer 
> 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 ...;
>>      }
>> }
> 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. The 
compiler accepts lots of code that's confusing to read.

The appropriate place for a rule like this is in a style guide or 
a configurable linter.

(This would also interact very badly with string-based code 
generation, since there's no reliable way to generate unique 
identifiers at compile time.)

More information about the Digitalmars-d mailing list