this working on dmd 2.052 release, throw error on dmd git master . ------------------------------------------ class Test1(string name, string file = __FILE__){ static const _file = file ; void test1(){ static const string file2 = _file[0..$] ; } } void main(){ auto obj = new Test1!"Test1" ; obj.test1(); } ----------------------------------------- test.d(5): Error: variable __dollar cannot be read at compile time test.d(5): Error: variable __dollar cannot be read at compile time test.d(10): Error: template instance test.Test1!("Test1") error instantiating
PATCH dsymbol.c, line 1181. if (!*pvar) // if not already initialized { /* Create variable v and set it to the value of ,ドル * which will be a constant. */ VarDeclaration *v = new VarDeclaration(loc, Type::tsize_t, Id::dollar, NULL); if (ce->op == TOKvar) { // if ce is const, get its initializer - ce = fromConstInitializer(WANTvalue, ce); + ce = fromConstInitializer(WANTvalue | WANTexpand, ce); } if (ce->op == TOKstring) { /* It is for a string literal, so the * length will be a const. */
D2 fix: https://github.com/D-Programming-Language/dmd/commit/0c9c52c7123e7336ce732e72099dbebd183742e2
D1 fix: https://github.com/D-Programming-Language/dmd/commit/bd196a9020883d94c7b7c4d8a91943d5735f4f3c
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル