Thank you!

Tejas notrealemail at gmail.com
Wed Sep 8 13:27:19 UTC 2021


On Wednesday, 8 September 2021 at 12:28:13 UTC, Basile B. wrote:
> On Tuesday, 7 September 2021 at 13:36:39 UTC, Tejas wrote:
>> On Tuesday, 7 September 2021 at 08:46:48 UTC, Basile B. wrote:
>>> On Tuesday, 7 September 2021 at 05:01:30 UTC, Tejas wrote:
>>>> On Tuesday, 7 September 2021 at 01:34:01 UTC, Basile B. 
>>>> wrote:
>>>>> [...]
>>>>
>>>> Don't you think it would be better to raise a warning though 
>>>> instead of silently fixing it?
>>>
>>> no. as compiler experiment people can add a flag to generated 
>>> temproaries and then printf on a visitor for VarExp and then 
>>> will probabably be surprised by the amount of message 
>>> printf'd like 2567 times
>>>
>>> "look boy am saving expressivity for ya here"
>>>
>>>>
>>>> It would help people understand the differences between [...]
>>
>>
>>
>> ```d
>> import std.stdio;
>>
>> struct S { int i; }
>>
>> S _s;
>>
>> S s (){return _s;}
>>
>> void main()
>> {
>>     s().i = 42;
>>     writeln(_s.i == 42);
>> }
>>
>> Output:
>> false
>> ```
>>
>> Wow, compiler help much appreciated
>
> I see that the conversation has forked on the validity of this 
> kind of code, so I've should have chosen a better example (set 
> `i` storage to `__gshared`). The point was just to show that 
> tempraries a created.

And I was arguing that that behavior should be either disabled(I 
don't feel this way anymore) or at least  emit a warning(still 
feel this way).

This isn't the first time, apparently:

https://issues.dlang.org/show_bug.cgi?id=3008

Even more troubling is this one, where `auto` decides to return 
`struct` by value rather than reference:
https://issues.dlang.org/show_bug.cgi?id=15231

The second one is more serious, I think.
No matter the default option picked by `auto`, it'll always be 
wrong in the other context.


More information about the Digitalmars-d mailing list