November 14, 2005 scope instantiation bug with alias template parameters | ||||
---|---|---|---|---|
| ||||
In this example, outside() seems to be instantiated only once, with the first use of test:local(). test.val is always 123, no matter what its template parameter is. (if you reverse the last two lines, then b passes and a fails -- test.val is always 456). I suspect this one is not trivial. --------------- template outside(alias s) { const int outval = s.localval; } template test(alias f) { template local() { const int localval = f.x; } const int val = outside!(local!()).outval; } template a() { const int x = 123; } template b() { const int x = 456; } static assert( test!( a!() ).val == 123); static assert( test!( b!() ).val == 456); int main() { return 0; } ----------- |
November 19, 2005 Re: scope instantiation bug with alias template parameters | ||||
---|---|---|---|---|
| ||||
Posted in reply to Don Clugston Attachments: | Don Clugston schrieb am 2005-11-14: > In this example, outside() seems to be instantiated only once, with the first use of test:local(). > > test.val is always 123, no matter what its template parameter is. (if you reverse the last two lines, then b passes and a fails -- test.val is always 456). > > I suspect this one is not trivial. > > --------------- > template outside(alias s) > { > const int outval = s.localval; > } > > template test(alias f) > { > template local() { const int localval = f.x; } > const int val = outside!(local!()).outval; > } > > template a() > { const int x = 123; } > > template b() > { const int x = 456; } > > static assert( test!( a!() ).val == 123); > static assert( test!( b!() ).val == 456); > > int main() { return 0; } > ----------- Added to DStress as http://dstress.kuehne.cn/run/t/template_18_A.d http://dstress.kuehne.cn/run/t/template_18_B.d Thomas |
Copyright © 1999-2021 by the D Language Foundation