https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81167

--- Comment #5 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
Note to self: I believe the "operator T() &&" here is a user-defined conversion
from an rvalue reference to T.

We have in joust at ../../src/gcc/cp/call.c:10071

10071             tree source = source_type (w->convs[0]);

(gdb) p source
$2 = <record_type 0x7ffff052ba80 Derived>

10072             if (! DECL_CONSTRUCTOR_P (w->fn))
10073               source = TREE_TYPE (source);

(gdb) p source
$4 = <tree 0x0>

Guarding that as follows:

--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -10069,7 +10069,8 @@ joust (struct z_candidate *cand1, struct z_candidate
*cand2, bool warn,
       else if (warn)
        {
          tree source = source_type (w->convs[0]);
-         if (! DECL_CONSTRUCTOR_P (w->fn))
+         if (! DECL_CONSTRUCTOR_P (w->fn)
+              && TREE_TYPE (source))
            source = TREE_TYPE (source);
          if (warning (OPT_Wconversion, "choosing %qD over %qD", w->fn, l->fn)
              && warning (OPT_Wconversion, "  for conversion from %qH to %qI",

fixes the problem (or papers over it?), giving:

../../src/pr81167.C: In function ‘void test()’:
../../src/pr81167.C:16:16: warning: choosing ‘bar::operator foo() &&’ over
‘foo::foo(const bar&)’ [-Wconversion]
   foo f = bar ();
                ^
../../src/pr81167.C:16:16: warning:   for conversion from ‘bar’ to ‘foo’
[-Wconversion]
../../src/pr81167.C:16:16: note:   because conversion sequence for the argument
is better

Reply via email to