Recursive template instantiation

Stefan Koch via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Mar 13 16:02:56 PDT 2017


On Monday, 13 March 2017 at 22:59:36 UTC, ag0aep6g wrote:
> On 03/13/2017 03:26 PM, Jack Applegame wrote:
>> I'm pretty sure that this code should compile
>> (https://dpaste.dzfl.pl/cf1e1ee6ef4b):
>>
>> struct A(T) {
>>     ~this() {
>>         char[T.sizeof] data;
>>     }
>> }
>>
>> struct B(T) {
>>     A!T foo;
>> }
>>
>> struct C {
>>     B!C bar;
>> }
>>
>> void main() {
>>     C c;
>> }
>>
>> But it doesn't:
>> /d300/f416.d(3): Error: struct f416.C no size because of 
>> forward
>> reference /d300/f416.d(12): Error: template instance 
>> f416.B!(C) error
>> instantiating
>
> It compiles when it's a normal method instead of a destructor:
>
> ----
> struct A(T) {
>     void m() {
>         char[T.sizeof] data;
>     }
> }
> /* ... rest as above ... */
> ----
>
> I don't see how the destructor makes a difference. Soo, bug?

Try to use m.


More information about the Digitalmars-d-learn mailing list