Christoph Bartoschek <bartoschek@gmx.de> wrote in message news:<vs23m1-j76.ln1@ID-80222.user.uni-berlin.de>...[color=blue]
> Hi,
>
> gcc 3.4 rejects the following program:
>
> class T {
> public:
> T() : a(3) {}
> explicit T(T const & other) : a(other.a) {}
> private:
> int a;
> };
>
> void func(T const & obj) {
> }
>
> int main() {
> func(T());
> }
>
> The error is:
>
> no matching function for call to `T::T(const T&)'
>
> There is some reasoning about it at:
>
>
http://gcc.gnu.org/bugs.html#cxx_rvalbind
>
> This seems to be correct for private copy constructors, but I am not sure
> whether the interpretation by the gcc team also applies to explicit copy
> constructors. Is there some discussion about the correct interpretation of
> the standard for explicit copy constructors?[/color]
Yes, CWG issue 152. It changed between C++98 and C++03.
The new rules are:
When objects of class type are direct-initialized (8.5 dcl.init), or
copy-initialized from an expression of the same or a derived class
type (8.5 dcl.init), overload resolution selects the constructor. For
direct-initialization, the candidate functions are all the
constructors of the class of the object being initialized. For
copy-initialization, the candidate functions are all the converting
constructors (12.3.1 class.conv.ctor ) of that class.
A non-explicit copy constructor (12.8 class.copy) is a converting
constructor.
This form requires copy-initialization to copy the temporary to the
bound argument (although the actual copy may be optimized out). In
this case, there's no converting ctor available.
Regards,
Michiel Salters