structs are now lvalues - what is with "auto ref"?

monarch_dodra monarchdodra at gmail.com
Mon Dec 24 10:05:32 PST 2012


On Monday, 24 December 2012 at 17:37:54 UTC, Andrei Alexandrescu 
wrote:
> On 12/24/12 12:11 PM, Jonathan M Davis wrote:
>> On Monday, December 24, 2012 17:55:23 Minas Mina wrote:
>>> On Sunday, 23 December 2012 at 23:59:55 UTC, Jonathan M Davis
>>>
>>> wrote:
>>>> On Monday, December 24, 2012 00:48:01 Namespace wrote:
>>>> but Andrei is dead set against
>>>>
>>>> - Jonathan M Davis
>>>
>>> Why?
>>
>> He's convinced that it's caused problems for C++ and was a 
>> major mistake. You
>> can search the newsgroup for discussions on it. The most 
>> recent one which
>> involved Andrei was in the beta group:
>>
>> http://forum.dlang.org/post/4F84D6DD.5090405@digitalmars.com
>>
>> - Jonathan M Davis
>
> An important smoking gun is C++'s min(), which is allows 
> writing unsafe code without casts.
>
> const int& haveANiceDay = min(4, 5);
>
>
> Andrei

But that example  actually works correctly.

TBH, most of the "unsafe" code I have been presented regarding 
the implict "cast + ref problem" comes from msvc accepting code 
which is not actually legal C++.

In "legit" C++, you *can't* bind a rvalue to a (non const) ref. 
gcc will turn you down if you tried any of those "unsafe" 
examples.


More information about the Digitalmars-d-learn mailing list