[Bug c++/51066] New: [C++0x] warning about binding an rvalue-reference to an implicit conversion result

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Nov 9 18:14:00 GMT 2011


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51066

             Bug #: 51066
           Summary: [C++0x] warning about binding an rvalue-reference to
                    an implicit conversion result
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: enhancement
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: redi@gcc.gnu.org


Inspired by the thread beginning with c++std-core-20672, G++ should warn about
this code:

struct A { };
struct B { B(A) {} };

A a;
B&& b = a;

warning: 'b' will bind to a temporary of type 'B' created by implicit
conversion from 'a'


This should only give a warning for a local variable of rvalue reference type
that is initialized by a non-reference-related object so that an implicit
conversion occurs.

There should be no warning when the conversion initializes a function parameter
e.g.

void f(B&&);
A a;
f(a);  // ok



More information about the Gcc-bugs mailing list