www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - disable this propgates through reference

reply Benjamin Thaut <code benjamin-thaut.de> writes:
Consider this reduced sample:

module main;

class Container(K,V)
{
   private:
   static struct Pair
   {
     K key;
     V value;
   }

   Pair[] m_Data;

   public:
   ref V opIndex(K key)
   {
     return m_Data[0].value;
   }
}


module mod1;

import main;

class Foo
{
   private:

   struct bar2
   {
      disable this();
   }

   class InnerBar {
     bar2 b;
   }

   struct bar1
   {
     InnerBar b;
   }

   Container!(void*, bar1) m_container;

   public:

   void work()
   {
     auto value = m_container[null];
   }
}


Compilation fails in the main module at line 17 which is:
return m_Data[0].value;

The error message is: (tested with 2.058 and 2.059)
main.d(17): Error: can only initialize const member value inside constructor

The strange here is, I just want to return a reference at that point, 
why does it even want to initialize anything? After a hour of searching 
I managed to produce the above reduced sample, it all comes down to the 
 disable this() in bar2. If it is removed everything works fine. Also 
the container and the usage of it need to be in two different modules, 
otherwise it will work. Is this a bug or do I not understand something 
about  disable this() ?

Kind Regards
Benjamin Thaut
Jun 24 2012
parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Sunday, June 24, 2012 18:02:30 Benjamin Thaut wrote:
 The strange here is, I just want to return a reference at that point,
 why does it even want to initialize anything? After a hour of searching
 I managed to produce the above reduced sample, it all comes down to the
  disable this() in bar2. If it is removed everything works fine. Also
 the container and the usage of it need to be in two different modules,
 otherwise it will work. Is this a bug or do I not understand something
 about  disable this() ?
Even stranger, as far as I can tell, disable this(); is completely broken: http://d.puremagic.com/issues/show_bug.cgi?id=7021 - Jonathan M Davis
Jul 09 2012