[Issue 9382] New: Alias declaration should not require the semantics completion of aliased template instance.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jan 23 21:23:07 PST 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9382
Summary: Alias declaration should not require the semantics
completion of aliased template instance.
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: k.hara.pg at gmail.com
--- Comment #0 from Kenji Hara <k.hara.pg at gmail.com> 2013-01-23 21:23:05 PST ---
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.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list