[Issue 6969] Forward reference on template class triangle

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Nov 10 00:39:06 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=6969


Rob T <alanb at ucora.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |alanb at ucora.com


--- Comment #7 from Rob T <alanb at ucora.com> 2012-11-10 00:39:04 PST ---
(In reply to comment #6)
> This works:
> 
> class A
> {
>     alias C C1;
> }
> class B
> {
>     alias A A1;
> }
> class C : B
> {
> }

It works because there are no actual circular references, and that's because
the class alias are in reality pointers, and pointers are known data types
irrespective of what they may represent (the definition expansion should stop
at the pointer). The compiler is certainly able to determine what the pointers
represent for dereferencing purposes as the class structures and contents are
100% knowable.

Note that if you convert the pointers to represent structs, ie change class to
struct, and fix up struct C to contain struct B due to a lack of inheritance,
it will no longer work, which is to be expected. To make the struct version
work again, you simply change the contained B to a pointer.

// this fails, and it should fail, so we're good.
struct A()
{
    C!() C1;
}
struct B
{
    A!() A1;
}
struct C() 
{
    B s;
}

// this works, and it should work, so we're good.
struct A()
{
    C!() C1;
}
struct B
{
    A!() A1;
}
struct C() 
{
    B* s; // changed to pointer
}

The problem at hand is definitely a bug from what I see.

--rt

-- 
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