R
Richard Herring
It is a silly piece of code I must agree. Designed to be difficult to[snip]I read the thread after I tried to solve it I confess.
Not in the context you created. Here is the error from comeau:
error: "CMyBase::CMyBase(CMyBase &)", required for copy that was
eliminated, is not callable because reference parameter cannot be bound
to rvalue
And from gcc:
error: no matching function for call to `CMyBase::CMyBase(CMyBase)'
candidates are: CMyBase::CMyBase(int)
CMyBase::CMyBase(CMyBase&)
dechipher.
And I bow to all you guys obviously superior knowledge. I'm humbled.
What is the borland compiler doing wrong here then?
Not diagnosing an attempt to bind a temporary to a non-const reference.
(since I compiled
it and ran it just fine)
All kinds of programs with undefined behaviour run "just fine".
Should I begin to doubt all programs I have made for it?
No.
(I know about borlands herasy with the standard on acount of the vcl.
Heresy? They have added a couple of keywords and some libraries, and
some of the added library classes have non-C++ construction and
destruction semantics because they aren't written in C++. They haven't
altered the semantics of any standard constructs. AFAIK in other
respects the compiler follows the standard reasonably well.
And I really am two minds about the additions they have made. On the
one hand its certainly more readable, but on the other its less
portable.
That need not be a problem. If you want portability, just don't use the
extensions. (My personal preference would be to keep my code as close to
the standard as possible, with just a thin layer of extensions where
it's necessary to interface to their GUI API. But we're drifting off
topic here.)
But have they made some dangerous stuff to core
functionality?)
No. (Well, no compiler is perfect, but there is no reason to worry about
this one just because it supports some extensions.)