This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Implicit conversion error using g++
- To: Alexandre Oliva <aoliva at redhat dot com>
- Subject: Re: Implicit conversion error using g++
- From: Daniel dot Walker at lhsl dot com
- Date: Mon, 9 Jul 2001 15:48:08 -0700
- Cc: David Berthelot <davidb at Magma-DA dot COM>,gcc-help at gcc dot gnu dot org
OK, let me make sure I have this straight. With copy-initialization the
target object is always initialized with the copy-constructor. So, it had
better be able to get a temporary to copy from in one conversion (my
example required two conversion; a cast and then a constructor, so it was
ill-formed) With direct-initialization any constructor may be used (in my
example, gcc found the cast operator to Foo and matched that to a
constructor from Foo.)
Thanks for the help and the citation! So, about the single conversion or
constructor. Does the standard give implementers leeway with how many can
be involved in an implicit conversion or is this set in stone? I'm a little
too accustomed to MSDEV, and its random magic tricks.
Thanks again!
Daniel Walker
Alexandre Oliva
<aoliva@redhat.com> To: David Berthelot <davidb@Magma-DA.COM>
Sent by: cc: Daniel.Walker@lhsl.com, gcc-help@gcc.gnu.org
aoliva@guarana.lsd.ic. Subject: Re: Implicit conversion error using g++
unicamp.br
07/09/2001 03:41 PM
On Jul 9, 2001, David Berthelot <davidb@Magma-DA.COM> wrote:
> Alexandre Oliva wrote:
>> Nope. Both lines perform object initialization, so the assignment
>> operator plays no role. The difference is that `Baz b1(bar)' is a
>> direct initialization, whereas `Baz b2 = bar' is a copy
>> initialization. The former may use a user-defined conversion sequence
>> plus a constructor, but the latter needs a single user-defined
>> conversion sequence, that can contain either a constructor or a
>> conversion function. See [dcl.init]/11-14 for details.
> Ok, I get it. In fact line 14 would translate by:
> - Baz(const Foo&) (right hand side of equal)
> - Baz(const Baz&) (for b2)
> Am I correct ?
Yep
> So the code is supposed to work ?
Nope, because a user-defined conversion sequence can involve no more
than a single constructor *or* a single user-defined conversion
function.
--
Alexandre Oliva Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist *Please* write to mailing lists, not to me