www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Possible bug with templates + protection attributes.

reply Kevin VR <azra pandora.be> writes:
Hello,

We have discovered a possible bug which does not allow access of private 
  declared members in the same module when using template classes.

In the next example the class "Baz" works fine. If we take the same 
thing however, and make a template class of it "Bar", the compiler fails 
to compile, complaining about Bar.doSomething() being private.

According to the D-specs it should be accessible in the same module?

<code>
class Bar(Type)
{
     this()
     {
     }

     private void doSomething()
     {
     }
}

class Baz
{
     this()
     {
     }

     private void doSomething()
     {
     }
}

void main()
{
     //this is ok
     Baz a = new Baz();
     a.doSomething();

     //this fails
     Bar!(int) b = new Bar!(int)();
     b.doSomething();
}
</code>

The original post about this was in digitalmars.D.learn under
"Templates + protection attributes problem"
(news://news.digitalmars.com:119/d31ndi$amo$1 digitaldaemon.com)
Apr 07 2005
parent Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Kevin VR schrieb am Fri, 08 Apr 2005 00:25:31 +0200:
 Hello,

 We have discovered a possible bug which does not allow access of private 
   declared members in the same module when using template classes.

 In the next example the class "Baz" works fine. If we take the same 
 thing however, and make a template class of it "Bar", the compiler fails 
 to compile, complaining about Bar.doSomething() being private.

 According to the D-specs it should be accessible in the same module?

<code>
 class Bar(Type)
 {
      this()
      {
      }

      private void doSomething()
      {
      }
 }

 class Baz
 {
      this()
      {
      }

      private void doSomething()
      {
      }
 }

 void main()
 {
      //this is ok
      Baz a = new Baz();
      a.doSomething();

      //this fails
      Bar!(int) b = new Bar!(int)();
      b.doSomething();
 }
</code>

 The original post about this was in digitalmars.D.learn under
 "Templates + protection attributes problem"
 (news://news.digitalmars.com:119/d31ndi$amo$1 digitaldaemon.com)
Added to DStress as http://dstress.kuehne.cn/run/private_04.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCVhsr3w+/yD4P9tIRAgu5AJ9jh5pME056e0RdoYuAPF6w3CtSVACggLNM lNBBJ9i78kTvE+61u5m9p7E= =8Cr2 -----END PGP SIGNATURE-----
Apr 07 2005