extern(C++) and struct (constness mangling problem ?)

Timon Gehr timon.gehr at gmx.ch
Wed Nov 30 04:30:10 PST 2011


On 11/30/2011 11:57 AM, deadalnix wrote:
> Le 30/11/2011 03:07, Andrei Alexandrescu a écrit :
>> On 11/29/11 2:22 PM, Timon Gehr wrote:
>>> The default initializer can easily be disabled:
>>>
>>> struct S{
>>> int x;
>>> @disable this();
>>> @disable void[0] init;
>>> @disable this(this);
>>> }
>>>
>>> Now nobody can do
>>> auto x = S.init;
>>>
>
> @disable void[0] init; Sound hacky as hell. Is it made by design, or is
> it a consequence of the current compiler implementation ?
>

Built-in properties can be hidden (I am almost sure it is by design), 
void[0] just means 'field with size 0' and is explicitly allowed by the 
language specification. @disable is by design as well. I orthogonally 
combined those three features in order to disable the built-in .init 
property.


>>> But it is still possible to do:
>>>
>>> S[1] x;
>>>
>>> I'd have expected that to fail with disabled this(). Is this a bug?
>>
>> Yes.
>>
>> Andrei
>
> It make much more sense that way. At least we can prevent us from
> getting garbage struct when it comes to interface with C++.



More information about the Digitalmars-d mailing list