www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - default ctor & inheritance bug

reply "Ilya Zaitseff" <sark7 mail333.com> writes:
Code below outputs '1' instead '0'.

'bar' value overrides 'foo' value, when in there are no ctor in class 'B'.
If uncomment B ctor, output is '0', as expected.

<code>
class A
{
   this() {}
}

class B: A
{
   int foo;
//  this() {}
}

class C: B
{
   int bar;

   this()
   {
     foo = 0;
     bar = 1;
   }
}

void main()
{
   C c = new C();
   printf("%d", c.foo); // 1, expecting 0
}
</code>
Dec 20 2004
next sibling parent reply "Simon Buchan" <currently no.where> writes:
On Tue, 21 Dec 2004 00:10:47 +1000, Ilya Zaitseff <sark7 mail333.com>  
wrote:

 Code below outputs '1' instead '0'.

 'bar' value overrides 'foo' value, when in there are no ctor in class  
 'B'.
 If uncomment B ctor, output is '0', as expected.

 <code>
 class A
 {
    this() {}
 }

 class B: A
 {
    int foo;
 //  this() {}
 }

 class C: B
 {
    int bar;

    this()
    {
      foo = 0;
      bar = 1;
    }
 }

 void main()
 {
    C c = new C();
    printf("%d", c.foo); // 1, expecting 0
 }
 </code>

dmd 0.109 on XP outputs 0. What version do you use? -- "Unhappy Microsoft customers have a funny way of becoming Linux, Salesforce.com and Oracle customers." - www.microsoft-watch.com: "The Year in Review: Microsoft Opens Up" -- "I plan on at least one critical patch every month, and I haven't been disappointed." - Adam Hansen, manager of security at Sonnenschein Nath & Rosenthal LLP (Quote from http://www.eweek.com/article2/0,1759,1736104,00.asp) -- "It's been a challenge to "reteach or retrain" Web users to pay for content, said Pizey" -Wired website: "The Incredible Shrinking Comic"
Dec 20 2004
parent reply "Ilya Zaitseff" <sark7 mail333.com> writes:
On Tue, 21 Dec 2004 19:36:19 +1300, Simon Buchan <currently no.where>  
wrote:

 On Tue, 21 Dec 2004 00:10:47 +1000, Ilya Zaitseff <sark7 mail333.com>  
 wrote:

 Code below outputs '1' instead '0'.

 'bar' value overrides 'foo' value, when in there are no ctor in class  
 'B'.
 If uncomment B ctor, output is '0', as expected.

 <code>
 class A
 {
    this() {}
 }

 class B: A
 {
    int foo;
 //  this() {}
 }

 class C: B
 {
    int bar;

    this()
    {
      foo = 0;
      bar = 1;
    }
 }

 void main()
 {
    C c = new C();
    printf("%d", c.foo); // 1, expecting 0
 }
 </code>

dmd 0.109 on XP outputs 0. What version do you use?

Strange, on the other machine there is no such bug. Maybe my D installation is broken.
Dec 21 2004
parent "Simon Buchan" <currently no.where> writes:
On Wed, 22 Dec 2004 13:27:26 +1000, Ilya Zaitseff <sark7 mail333.com>  
wrote:

<snip>
 Strange, on the other machine there is no such bug.
 Maybe my D installation is broken.

I am assusming there would have to be for it to do this... compiler version and environment may help (If they are not identical) Also: this may be somewhat like the eax "return" "behavior" (Its a feature, not a bug! :D), i.e. whatever was in eax is returned from void main(). Unless this always happens with different compilations... or something... -- "Unhappy Microsoft customers have a funny way of becoming Linux, Salesforce.com and Oracle customers." - www.microsoft-watch.com: "The Year in Review: Microsoft Opens Up" -- "I plan on at least one critical patch every month, and I haven't been disappointed." - Adam Hansen, manager of security at Sonnenschein Nath & Rosenthal LLP (Quote from http://www.eweek.com/article2/0,1759,1736104,00.asp) -- "It's been a challenge to "reteach or retrain" Web users to pay for content, said Pizey" -Wired website: "The Incredible Shrinking Comic"
Dec 21 2004
prev sibling parent "Thomas Kuehne" <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Added to DStress as
http://svn.kuehne.cn/dstress/run/constructor_07.d
http://svn.kuehne.cn/dstress/run/constructor_08.d

Thomas

-----BEGIN PGP SIGNATURE-----

iD8DBQFByypS3w+/yD4P9tIRAlYhAJ9GSEtD5dv69V5ODeKdgP5VSWuBNACfXPiE
dPRvaN/2xpgadNoEmWlnwe0=
=mZ74
-----END PGP SIGNATURE-----
Dec 23 2004