Bug 51066 - [C++0x] warning about binding an rvalue-reference to an implicit conversion result
Summary: [C++0x] warning about binding an rvalue-reference to an implicit conversion r...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: diagnostic
Depends on:
Reported: 2011-11-09 17:59 UTC by Jonathan Wakely
Modified: 2017-09-27 07:17 UTC (History)
3 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2017-09-27 00:00:00


Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2011-11-09 17:59:30 UTC
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
Comment 1 Jonathan Wakely 2012-01-19 19:42:33 UTC
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1414 is related
Comment 2 Eric Gallager 2017-09-27 01:18:07 UTC
Confirmed that there is currently no warning.