May 22, 2012
On 5/22/12 1:14 PM, Steven Schveighoffer wrote:
> I agree, it's unsound. But so is this:
>
> int *blah = void;
>
> *blah = 5;
>
> It doesn't mean that the language should forbid it, or that the compiler
> isn't implemented as designed.

Initialization with void is a feature. My example shows the fail of a feature. There is no comparison.

> At the *very least*, the address to member function operation should be
> illegal in @safe code.

It should be verboten. Other means should be devised for achieving whatever utility is there.

>> At best things could be arranged that &Test.foo has type void
>> function(Test) or something.
>
> I would suggest that it should be:
>
> function(Test this) with the 'this' being mangled into the name, and
> affect the calling convention.
>
> Structs would be function(ref Test this).
>
> And const/shared/immutable decorations should apply properly to the
> 'this' parameter.
>
> I'd wholeheartedly support such an improvement. In fact, I'd be willing
> to write a DIP on it, if Walter had a chance of approving it. I just
> don't know if it would happen...

Very reasonable. Walter, could you please weigh in on this.


Thanks,

Andrei

May 22, 2012
On Tue, 22 May 2012 15:29:10 -0400, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:

> On 5/22/12 1:14 PM, Steven Schveighoffer wrote:
>> I agree, it's unsound. But so is this:
>>
>> int *blah = void;
>>
>> *blah = 5;
>>
>> It doesn't mean that the language should forbid it, or that the compiler
>> isn't implemented as designed.
>
> Initialization with void is a feature. My example shows the fail of a feature. There is no comparison.

Your example shows an invalid use for a feature.  There are valid uses for that feature that are not unsound.

But I think we are on the same page -- the misfeature is not that you *can* take a member address, it's the *type* that it is given.

>> At the *very least*, the address to member function operation should be
>> illegal in @safe code.
>
> It should be verboten. Other means should be devised for achieving whatever utility is there.

I agree, the feature is prone to error.

-Steve
May 22, 2012
On 5/22/12 4:05 PM, Steven Schveighoffer wrote:
> On Tue, 22 May 2012 15:29:10 -0400, Andrei Alexandrescu
> <SeeWebsiteForEmail@erdani.org> wrote:
>
>> On 5/22/12 1:14 PM, Steven Schveighoffer wrote:
>>> I agree, it's unsound. But so is this:
>>>
>>> int *blah = void;
>>>
>>> *blah = 5;
>>>
>>> It doesn't mean that the language should forbid it, or that the compiler
>>> isn't implemented as designed.
>>
>> Initialization with void is a feature. My example shows the fail of a
>> feature. There is no comparison.
>
> Your example shows an invalid use for a feature. There are valid uses
> for that feature that are not unsound.

Typing must always be sound.

Andrei

1 2 3
Next ›   Last »