@disable this propgates through reference
Benjamin Thaut
code at benjamin-thaut.de
Sun Jun 24 09:02:30 PDT 2012
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
More information about the Digitalmars-d
mailing list