Francesco S. Carta wrote:
Keith H Duggar<duggar@alum.mit.edu>, on 30/07/2010 09:06:01, wrote:
On Jul 30, 10:49 am, "Balog Pal"<p...@lib.hu> wrote:
"Keith H Duggar"<dug...@alum.mit.edu>
I guess what I really want is 1) and 2), after detecting whether T
is fundamental or not.
T const& t = T() ;
I vaguely recall that even that requires access to the copy ctor, and
the
compiler is allowed to use it too, though most do not. (Even more
vaguely I recall an accident with MSVC version around 5.0 where copy
was actually used before binding the reference.)
Yeah, you are right. How odd.
Could someone point out some reference to this requirement? MinGW 4.4.0
allows the above statement even for T = [some type with copy constructor
declared private and not even defined] where that statement has no
access to the private interface of T.
If it is a requirement, the compiler should have refused the code I
posted in the other branch of this thread, but it compiled it just fine.
The clause is [8.5.3/5]:
A reference to type ?cv1 T1? is initialized by an expression of type
?cv2 T2? as follows:
- If the initializer expression
[non applicable clause]
- Otherwise, the reference shall be to a non-volatile const type
(i.e.,
cv1 shall be const).
[example]
- If the initializer expression is an rvalue, with T2 a class type,
and
?cv1 T1? is reference-compatible with ?cv2 T2,? the reference is
bound in one of the following ways (the choice is
implementation-defined): - The reference is bound to the object
represented by the rvalue (see
3.10) or to a sub-object within that object.
- A temporary of type ?cv1 T2? [sic] is created, and a constructor
is
called to copy the entire rvalue object into the temporary. The
reference is bound to the temporary or to a sub-object within
the temporary.
The constructor that would be used to make the copy shall be
callable whether or not the copy is actually done.
- Otherwise [non applicable clause]
Is it yet another GCC extension? In case, is it a compliant one, for
what you can tell?
No, it's not an extension. Also, g++ on linux rejects the following code:
class dummy {
dummy ( dummy const& ) {}
public:
dummy ( void ) {}
};
int main ( void ) {
dummy x = dummy();
}
If the windows version accepts the code, it would be a bug.
No, it rejects it as expected. Could you please check if the Linux