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: UNCONFIRMED
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
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2011-11-09 17:59 UTC by Jonathan Wakely
Modified: 2012-01-19 19:42 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

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