[PATCH] rvalue reference implementation for C++0x

Russell Yanofsky russ@yanofsky.org
Mon Mar 19 12:07:00 GMT 2007

On Sun, 2007-03-11 at 17:54 -0400, Jason Merrill wrote:
> struct A {};
> struct B {};
> struct C
> {
>   operator A();
>   operator B&();
> };
> C c;
> void f (A&&);
> void f (B&&);
> int main()
> {
>    f (c);
> }

This case does seem to be handled correctly by the patch, it gives

        t.C: In function 'int main()':
        t.C:16: error: call of overloaded 'f(C&)' is ambiguous
        t.C:11: note: candidates are: void f(A&&)
        t.C:12: note:                 void f(B&&)

The place where it happens is inside convert_ics()  at

      if (t1->cand->fn != t2->cand->fn)
	return 0;

This is the part of the code that attempts to compare two user-defined
conversion sequences. Since the standard only defines ordering on
user-defined conversion sequences "if they contain the same user-defined
conversion function or constructor" the example is ambiguous like you
say, but it is handled correctly with the patch. The patch compares
rvaluedness in the standard conversion sequences, but only after the
point in the code where the user-defined conversion sequences are found
to be indistinguishable.

-  Russell Yanofsky (PGP ID: 0x5FAA0216)
-  http://russ.yanofsky.org/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20070319/7aa6c892/attachment.sig>

More information about the Gcc-patches mailing list