public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/51066] New: [C++0x] warning about binding an rvalue-reference to an implicit conversion result
@ 2011-11-09 18:14 redi at gcc dot gnu.org
2012-01-19 20:16 ` [Bug c++/51066] " redi at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2011-11-09 18:14 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/51066] [C++0x] warning about binding an rvalue-reference to an implicit conversion result
2011-11-09 18:14 [Bug c++/51066] New: [C++0x] warning about binding an rvalue-reference to an implicit conversion result redi at gcc dot gnu.org
@ 2012-01-19 20:16 ` redi at gcc dot gnu.org
2021-03-23 11:28 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2012-01-19 20:16 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51066
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-01-19 19:42:33 UTC ---
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1414 is related
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/51066] [C++0x] warning about binding an rvalue-reference to an implicit conversion result
2011-11-09 18:14 [Bug c++/51066] New: [C++0x] warning about binding an rvalue-reference to an implicit conversion result redi at gcc dot gnu.org
2012-01-19 20:16 ` [Bug c++/51066] " redi at gcc dot gnu.org
@ 2021-03-23 11:28 ` redi at gcc dot gnu.org
2021-03-23 11:51 ` redi at gcc dot gnu.org
2023-07-02 0:05 ` egallager at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2021-03-23 11:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51066
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This warning would also help with this horror:
https://twitter.com/zygoloid/status/1367301323838812160
#include <stdio.h>
void f(float&&) { puts("float"); }
void f(int&&) { puts("int"); }
template<typename T> void g(T x) { f(x); }
int main() {
g(1.0f);
g(2);
}
Prints "int\nfloat\n" because f(x) cannot bind directly to an rvalue reference
so there is an implicit conversion.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/51066] [C++0x] warning about binding an rvalue-reference to an implicit conversion result
2011-11-09 18:14 [Bug c++/51066] New: [C++0x] warning about binding an rvalue-reference to an implicit conversion result redi at gcc dot gnu.org
2012-01-19 20:16 ` [Bug c++/51066] " redi at gcc dot gnu.org
2021-03-23 11:28 ` redi at gcc dot gnu.org
@ 2021-03-23 11:51 ` redi at gcc dot gnu.org
2023-07-02 0:05 ` egallager at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2021-03-23 11:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51066
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
And this one https://twitter.com/wakomeup/status/1274778577087627267
struct B { };
struct D : B { };
B b;
D&& d(b); // binds to implicit conversion result
D&& dd(std::move(b)); // binds to implicit conversion result
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/51066] [C++0x] warning about binding an rvalue-reference to an implicit conversion result
2011-11-09 18:14 [Bug c++/51066] New: [C++0x] warning about binding an rvalue-reference to an implicit conversion result redi at gcc dot gnu.org
` (2 preceding siblings ...)
2021-03-23 11:51 ` redi at gcc dot gnu.org
@ 2023-07-02 0:05 ` egallager at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: egallager at gcc dot gnu.org @ 2023-07-02 0:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51066
--- Comment #5 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #3)
> This warning would also help with this horror:
> https://twitter.com/zygoloid/status/1367301323838812160
(In reply to Jonathan Wakely from comment #4)
> And this one https://twitter.com/wakomeup/status/1274778577087627267
Archive links for these:
http://web.archive.org/web/20220327011407/https://twitter.com/zygoloid/status/1367301323838812160
http://web.archive.org/web/20200621190630/https://twitter.com/wakomeup/status/1274778577087627267
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-07-02 0:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-09 18:14 [Bug c++/51066] New: [C++0x] warning about binding an rvalue-reference to an implicit conversion result redi at gcc dot gnu.org
2012-01-19 20:16 ` [Bug c++/51066] " redi at gcc dot gnu.org
2021-03-23 11:28 ` redi at gcc dot gnu.org
2021-03-23 11:51 ` redi at gcc dot gnu.org
2023-07-02 0:05 ` egallager at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).