Bug in using string mixins inside of a struct?

kenji hara k.hara.pg at gmail.com
Wed Mar 27 04:33:00 PDT 2013


2013/3/27 Timon Gehr <timon.gehr at gmx.ch>

> Because of a questionable patch (written by Kenji Hara, I think) some time
> ago, the following works:
>
> struct S{
>     template T(int x){
>         auto s = x; // implicitly static
>     }
> }
>
> I consider this bad language design.


In above case, 's' cannot make a field in S.
Because such a feature would make impossible to determine the size of S.

void main() {
    S s;
    assert(s.T!0.s == 0);  // If T!0.s is a field of s,
    assert(s.T!1.s == 1);  // also T!1.s is a field...
    pragma(msg, S.sizeof == ??);  // ???
}

So, variables in template declaration will always make "static' variables.

Kenji Hara
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130327/c70d9f05/attachment.html>


More information about the Digitalmars-d mailing list