Local static variables must have unique names within a function's scope.
Steven Schveighoffer
schveiguy at yahoo.com
Fri Jan 19 18:33:57 UTC 2018
On 1/19/18 1:11 PM, H. S. Teoh wrote:
> Fortunately this is not the case. However, the static variable case is
> annoying, and it's actually one case of a larger problem:
>
> void main() {
> foreach (i; 0 .. 10) {
> struct S {
> int x;
> }
> auto s = S(i);
> }
> foreach (i; 11 .. 20) {
> struct S { // <---- this is line 9
> int y;
> }
> auto s = S(i);
> }
> }
>
> The compiler says:
>
> test.d(9): Error: declaration S is already defined in another scope in main
>
> even though the respective scopes of the declarations are disjoint. IMO,
> this is a needless, arbitrary restriction. Worse yet, the compiles ICEs
> after this, so I filed a bug:
>
> https://issues.dlang.org/show_bug.cgi?id=18266
Related: https://issues.dlang.org/show_bug.cgi?id=17653
-Steve
More information about the Digitalmars-d-learn
mailing list