Francesco said:
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.
Best
Kai-Uwe Bux