This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Implicit conversion error using g++



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




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]