This is the mail archive of the gcc@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]

conversion operator and pass-by-reference


Hi,

Consider the following snippet:

struct B {};

struct A
{
    operator B() {B b; return b;}
};

void f(B b) {}

void f_ref(B& b) {}

int main()
{
  A a;
  f(a);      // OK
  f_ref(a);  // doesn't compile

  return 0;
}

It is not a problem for the compiler to convert a to a B through the
used-defined conversion operator. However, the logical extension of
converting a to a B& doesn't work.

Is this behaviour as prescribed by the standard, or is it a bug in g++?

Thanks,

Peter

-------------------------------------
Peter Bienstman
Department of Information Technology
INTEC/IMEC - University of Gent
St.-Pietersnieuwstraat 41
B-9000 Gent - Belgium
E-mail: Peter.Bienstman@rug.ac.be
Tel: +32 9 264 3445
Fax: +32 9 264 3593
-------------------------------------


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