On Sat, 04 Dec 2010 16:05:07 +0200, Andrei Alexandrescu <seewebsiteforem...@erdani.org> wrote:

On 12/4/10 6:50 AM, so wrote:
I'm 99.99% certain that it's perfectly legal to pass a temporary to a
function
that takes a const T& and that it's in the standard

Oh that is right, but both are different things.

Say, when you have:

T fun() {...}
void bar(const T&) {...}

bar(fun()) // 1. this is perfectly legal.
const T& a = fun(); // 2. not legal, but still you can do it on some
compilers.

Second line is legal too. Petru Marginean and I use it to good effect in my ScopeGuard idiom (a precursor to D's scope guards).

http://www.drdobbs.com/184403758


Andrei

I was sure that always output C4238 on MSVC, and simply rejected on GCC.
Now I tried with 2 versions of MSVC and it didn't give any warnings.
As it looks like this is only for pointers. That is:

const T* a = &fun();

I have encountered this quite a few times and i was sure reference example above also same since i can't think of a reason
that i would take take the address of a temporary function...

--
Using Opera's revolutionary email client: http://www.opera.com/mail/

Reply via email to