public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed] libcpp: Avoid pessimizing std::move [PR106272]
@ 2022-07-13 18:24 Marek Polacek
  0 siblings, 0 replies; only message in thread
From: Marek Polacek @ 2022-07-13 18:24 UTC (permalink / raw)
  To: GCC Patches

std::move in a return statement can prevent the NRVO:
<https://developers.redhat.com/blog/2019/04/12/understanding-when-not-to-stdmove-in-c>

PR106272 reports that we have two such cases in class label_text's
member functions.  We have -Wpessimizing-move that's supposed to detect
problematic std::move uses, but in this case it didn't trigger.  I've filed
PR106276 to track that.

Tested x86_64-pc-linux-gnu, applying to trunk.

	PR preprocessor/106272

libcpp/ChangeLog:

	* include/line-map.h (class label_text): Don't std::move in a return
	statement.
---
 libcpp/include/line-map.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index c6379ce25b8..c434a246b13 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -1873,13 +1873,13 @@ public:
      longer-lived owner.  */
   static label_text borrow (const char *buffer)
   {
-    return std::move (label_text (const_cast <char *> (buffer), false));
+    return label_text (const_cast <char *> (buffer), false);
   }
 
   /* Create a label_text instance that takes ownership of BUFFER.  */
   static label_text take (char *buffer)
   {
-    return std::move (label_text (buffer, true));
+    return label_text (buffer, true);
   }
 
   /* Take ownership of the buffer, copying if necessary.  */

base-commit: f70c18524221dcefa6cd26cee7b55503181bd912
-- 
2.36.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-07-13 18:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-13 18:24 [pushed] libcpp: Avoid pessimizing std::move [PR106272] Marek Polacek

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).