Shadowing of module global TLS variables is not an error

Steven Schveighoffer schveiguy at
Fri Aug 14 12:51:41 UTC 2020

On 8/14/20 4:58 AM, Per Nordlöw wrote:
> Shouldn't this code give a shadowing error?
> int x;                          // global?
> void test() @safe nothrow @nogc
> {
>      int x = x;                  // shouldn't this give a shadowing 
> warning?
> }

I don't know if this is a hard-fast rule, but my view of the shadowing 
error is that if you can access the variable, it's not shadowing.

You can access the global via .x

But in the following, there is no way to access the outer x:

void test()
    int x; // x1
    foreach(x; [1, 2, 3]) { /* how to access x1 here? */ }

> The real offender is not this though, it's shadowing members from super classes. 

Super members can also be accessed via scope naming: super.x


More information about the Digitalmars-d mailing list