public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106276] New: Missing -Wpessimizing-move warning
@ 2022-07-13 0:51 mpolacek at gcc dot gnu.org
2022-07-13 7:21 ` [Bug c++/106276] " marxin at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-07-13 0:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106276
Bug ID: 106276
Summary: Missing -Wpessimizing-move warning
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: mpolacek at gcc dot gnu.org
Target Milestone: ---
Looks like we're missing a warning on the std::move line here:
namespace std {
template <typename _Tp> _Tp &&move(_Tp &&);
}
char take_buffer;
struct label_text {
label_text take() { return std::move(label_text(&take_buffer)); }
label_text(char *);
};
$ xclang++ -c -Wall -W line-map.ii
line-map.ii:6:30: warning: moving a temporary object prevents copy elision
[-Wpessimizing-move]
label_text take() { return std::move(label_text(&take_buffer)); }
^
line-map.ii:6:30: note: remove std::move call here
label_text take() { return std::move(label_text(&take_buffer)); }
^~~~~~~~~~ ~
$ xg++ -c -Wall -W line-map.ii
$
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/106276] Missing -Wpessimizing-move warning
2022-07-13 0:51 [Bug c++/106276] New: Missing -Wpessimizing-move warning mpolacek at gcc dot gnu.org
@ 2022-07-13 7:21 ` marxin at gcc dot gnu.org
2022-07-13 11:58 ` mpolacek at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-07-13 7:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106276
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Last reconfirmed| |2022-07-13
CC| |marxin at gcc dot gnu.org
Status|UNCONFIRMED |NEW
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/106276] Missing -Wpessimizing-move warning
2022-07-13 0:51 [Bug c++/106276] New: Missing -Wpessimizing-move warning mpolacek at gcc dot gnu.org
2022-07-13 7:21 ` [Bug c++/106276] " marxin at gcc dot gnu.org
@ 2022-07-13 11:58 ` mpolacek at gcc dot gnu.org
2022-07-13 18:36 ` dcb314 at hotmail dot com
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-07-13 11:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106276
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/106276] Missing -Wpessimizing-move warning
2022-07-13 0:51 [Bug c++/106276] New: Missing -Wpessimizing-move warning mpolacek at gcc dot gnu.org
2022-07-13 7:21 ` [Bug c++/106276] " marxin at gcc dot gnu.org
2022-07-13 11:58 ` mpolacek at gcc dot gnu.org
@ 2022-07-13 18:36 ` dcb314 at hotmail dot com
2022-07-13 19:09 ` mpolacek at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: dcb314 at hotmail dot com @ 2022-07-13 18:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106276
David Binderman <dcb314 at hotmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |dcb314 at hotmail dot com
--- Comment #1 from David Binderman <dcb314 at hotmail dot com> ---
Can a simpler word than "elison" be used ? Remove or delete maybe ?
This would help stop many folks, including me, reaching for their dictionaries
to discover what the compiler is warning about.
Eschew prolixity.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/106276] Missing -Wpessimizing-move warning
2022-07-13 0:51 [Bug c++/106276] New: Missing -Wpessimizing-move warning mpolacek at gcc dot gnu.org
` (2 preceding siblings ...)
2022-07-13 18:36 ` dcb314 at hotmail dot com
@ 2022-07-13 19:09 ` mpolacek at gcc dot gnu.org
2022-07-13 20:16 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-07-13 19:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106276
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
IMHO no. "Copy elision" is a well-established term in C++ and naming it
differently would be more confusing.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/106276] Missing -Wpessimizing-move warning
2022-07-13 0:51 [Bug c++/106276] New: Missing -Wpessimizing-move warning mpolacek at gcc dot gnu.org
` (3 preceding siblings ...)
2022-07-13 19:09 ` mpolacek at gcc dot gnu.org
@ 2022-07-13 20:16 ` redi at gcc dot gnu.org
2022-07-13 20:19 ` redi at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2022-07-13 20:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106276
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Agreed. Inventing new imprecise terminology for it would not be an improvement.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/106276] Missing -Wpessimizing-move warning
2022-07-13 0:51 [Bug c++/106276] New: Missing -Wpessimizing-move warning mpolacek at gcc dot gnu.org
` (4 preceding siblings ...)
2022-07-13 20:16 ` redi at gcc dot gnu.org
@ 2022-07-13 20:19 ` redi at gcc dot gnu.org
2022-07-16 0:43 ` mpolacek at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2022-07-13 20:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106276
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to David Binderman from comment #1)
> This would help stop many folks, including me, reaching for their
> dictionaries
> to discover what the compiler is warning about.
Don't use a dictionary then:
https://en.cppreference.com/w/cpp/language/copy_elision
https://en.wikipedia.org/wiki/Copy_elision
https://stackoverflow.com/questions/12953127/what-are-copy-elision-and-return-value-optimization
The gcc manual also explains the warning better than looking up individual
words in a dictionary will.
> Eschew prolixity.
This is not prolixity, it's a term of art.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/106276] Missing -Wpessimizing-move warning
2022-07-13 0:51 [Bug c++/106276] New: Missing -Wpessimizing-move warning mpolacek at gcc dot gnu.org
` (5 preceding siblings ...)
2022-07-13 20:19 ` redi at gcc dot gnu.org
@ 2022-07-16 0:43 ` mpolacek at gcc dot gnu.org
2022-08-15 14:00 ` cvs-commit at gcc dot gnu.org
2022-08-15 14:04 ` mpolacek at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-07-16 0:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106276
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=90428
--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Ah, this is pretty much a dup of a half of bug 90428.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/106276] Missing -Wpessimizing-move warning
2022-07-13 0:51 [Bug c++/106276] New: Missing -Wpessimizing-move warning mpolacek at gcc dot gnu.org
` (6 preceding siblings ...)
2022-07-16 0:43 ` mpolacek at gcc dot gnu.org
@ 2022-08-15 14:00 ` cvs-commit at gcc dot gnu.org
2022-08-15 14:04 ` mpolacek at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-08-15 14:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106276
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:ae3459cd5956fcd29e8aa5408efb707cb7d9b14f
commit r13-2045-gae3459cd5956fcd29e8aa5408efb707cb7d9b14f
Author: Marek Polacek <polacek@redhat.com>
Date: Fri Jul 22 18:10:30 2022 -0400
c++: Extend -Wpessimizing-move for class prvalues [PR106276]
We already have a warning that warns about pessimizing std::move
in a return statement, when it prevents the NRVO:
T fn()
{
T t;
return std::move (t); // warning \o/
}
However, the warning doesn't warn when what we are returning is a class
prvalue, that is, when std::move prevents the RVO:
T fn()
{
T t;
return std::move (T{}); // no warning :-(
}
This came up recently in GCC:
<https://gcc.gnu.org/pipermail/gcc-patches/2022-July/598177.html>.
This patch fixes that. I would like to extend the warning further, so
that it warns in more contexts, e.g.:
T t = std::move(T());
or
void foo (T);
foo (std::move(T()));
PR c++/106276
gcc/cp/ChangeLog:
* typeck.cc (can_do_rvo_p): New.
(maybe_warn_pessimizing_move): Warn when moving a temporary object
in a return statement prevents copy elision.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/Wpessimizing-move7.C: New test.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/106276] Missing -Wpessimizing-move warning
2022-07-13 0:51 [Bug c++/106276] New: Missing -Wpessimizing-move warning mpolacek at gcc dot gnu.org
` (7 preceding siblings ...)
2022-08-15 14:00 ` cvs-commit at gcc dot gnu.org
@ 2022-08-15 14:04 ` mpolacek at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-08-15 14:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106276
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Done for GCC 13.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-08-15 14:04 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-13 0:51 [Bug c++/106276] New: Missing -Wpessimizing-move warning mpolacek at gcc dot gnu.org
2022-07-13 7:21 ` [Bug c++/106276] " marxin at gcc dot gnu.org
2022-07-13 11:58 ` mpolacek at gcc dot gnu.org
2022-07-13 18:36 ` dcb314 at hotmail dot com
2022-07-13 19:09 ` mpolacek at gcc dot gnu.org
2022-07-13 20:16 ` redi at gcc dot gnu.org
2022-07-13 20:19 ` redi at gcc dot gnu.org
2022-07-16 0:43 ` mpolacek at gcc dot gnu.org
2022-08-15 14:00 ` cvs-commit at gcc dot gnu.org
2022-08-15 14:04 ` mpolacek 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).