Test case: ----------------- struct X7419 { double x; this(double x) { this.x = x; } } unittest { enum x = { auto p = X7419(3); return p.x; }(); static assert(x == 3); } ----------------- Compile with: dmd -unittest -inline -c test7419.d Gives the unexpected error: test7419.d(12): Error: static assert (nan == 3) is false The bug was introduced in commit 40160a53a0c72bfbad2e0ad36ec8f1ccbb76ce8d.
It doesn't need unittest. The -inline seems to be necessary, I presume it's creating a ref variable. struct X7419 { double x; this(double x) { this.x = x; } } void bug7419() { enum x = { auto p = X7419(3); return p.x; }(); static assert(x == 3); }
Linky: https://github.com/D-Programming-Language/dmd/commit/40160a53a0c72bfbad2e0ad36ec8f1ccbb76ce8d
Looking at that git commit, if I add back in the following code that was elided: 3450a3451,3459 > > #if 1 > if (op==TOKconstruct && this->e1->op==TOKvar && this->e2->op != TOKthis > && this->e2->op != TOKcomma > && ((VarExp*)this->e1)->var->storage_class & STCref) > wantRef = true; > #endif > > then it works. Note that when -inline is used, the only function that gets inlined is the constructor call. Note the comment for the elision, saying it is to fix something with foreach, yet foreach is not in this example, I think the problem is in CTFE.
(In reply to comment #3) > Looking at that git commit, if I add back in the following code that was > elided: > > 3450a3451,3459 > > > > #if 1 > > if (op==TOKconstruct && this->e1->op==TOKvar && this->e2->op != TOKthis > > && this->e2->op != TOKcomma > > && ((VarExp*)this->e1)->var->storage_class & STCref) > > wantRef = true; > > #endif > > > > > > then it works. > > Note that when -inline is used, the only function that gets inlined is the > constructor call. > > Note the comment for the elision, saying it is to fix something with foreach, > yet foreach is not in this example, I think the problem is in CTFE. That code was introduced as a hack to get ref foreach to work in CTFE, but it isn't correct (the != TOKthis and != TOKcomma is a hack). Later, after fixing some other bugs, ref foreach works without it. I have made a proper fix, which I will post tonight.
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/127d0110b839e5bdc2997ae0b586b1e93c7c8daa 7419 [2.058/CTFE] Constructor of struct is overwritten with -inline The logic for ref variables was incorrect. Stripping out _all_ of the funky foreach code fixes it. Fixes bug 7419.
Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/467cf6687f60dbb4180df036bd0508b9ce408d19 fix issue 6504, fix issue 7419
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル