Bug 9382 – Alias declaration should not require the semantics completion of aliased template instance.

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-01-23T21:23:05Z
Last change time
2024-12-13T18:03:52Z
Assigned to
No Owner
Creator
Kenji Hara
Moved to GitHub: dmd#17570 →

Comments

Comment #0 by k.hara.pg — 2013-01-23T21:23:05Z
Essentially this code should succeed to compile, but in current it fails with "recursive alias declaration" error. code: ---- void main() { CustomFloat!8 f; // [1] line 3 } template CustomFloat(uint bits) { static if (bits == 8) alias CustomFloat!( 4, 3) CustomFloat; // [2] L7 static if (bits == 64) alias CustomFloat!(52, 11) CustomFloat; static if (bits == 80) alias CustomFloat!(64, 15) CustomFloat; // [6][8] L9 } struct CustomFloat(uint precision, uint exponentWidth) { union ToBinary(F) { CustomFloat!(F.sizeof*8 < 80 ? F.sizeof*8 : 80) get; // [5] L15 } enum x = max_10_exp(); // run max_10_exp's semantic3 static @property int max_10_exp() { CustomFloat max; return cast(int) max.get!real; // [3][7] L22 } @property F get(F)() { ToBinary!F result; // [4][8] L26 return F.init; } } output: ---- test.d( 9): Error: alias test.CustomFloat!(80u).CustomFloat recursive alias declaration test.d(26): Error: template instance test.CustomFloat!(64, 15).CustomFloat.ToBinary!(real) error instantiating test.d(22): instantiated from here: get!(real) test.d( 9): instantiated from here: CustomFloat!(64, 15) test.d(15): instantiated from here: CustomFloat!(80u) test.d(26): instantiated from here: ToBinary!(real) test.d(22): instantiated from here: get!(real) test.d( 7): instantiated from here: CustomFloat!(4, 3) test.d( 3): instantiated from here: CustomFloat!(8) ---- The root cause of this issue is, if you make an alias of template instance, the alias declaration will try to instantiate the template *completely*. If the template is a template struct, its semantic() and semantic3() will run. But in my thought, invoking semantic3 is not essentially be required for the alias creation. Such the eager semantic will cause a unnecessary forward reference, as above.
Comment #1 by github-bugzilla — 2013-01-23T23:42:34Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/6502337a21a7ae3ce6519127a33c83b016a7408d Add workaround for bug 9382, which introduced by fixing bug 5933 https://github.com/D-Programming-Language/phobos/commit/47d47579053c6c742d43e106d0d24a081fde3c35 Merge pull request #1096 from 9rnsr/fix5933 Add workaround for bug 9382, which introduced by fixing bug 5933
Comment #2 by robert.schadek — 2024-12-13T18:03:52Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17570 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB