public inbox for
help / color / mirror / Atom feed
* gcc-wwwdocs branch master updated. 0f3b5000bce0237ddf2f852099fea998cf476267
@ 2022-10-12 22:47 Marek Polacek
  0 siblings, 0 replies; only message in thread
From: Marek Polacek @ 2022-10-12 22:47 UTC (permalink / raw)
  To: gcc-cvs-wwwdocs

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gcc-wwwdocs".

The branch, master has been updated
       via  0f3b5000bce0237ddf2f852099fea998cf476267 (commit)
      from  205feff8608570c4be7306cbf05b53d0540905f8 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 0f3b5000bce0237ddf2f852099fea998cf476267
Author: Marek Polacek <>
Date:   Wed Oct 12 18:46:30 2022 -0400

    gcc-13/porting_to: Add notes wrt implicit move rules changes

diff --git a/htdocs/gcc-13/porting_to.html b/htdocs/gcc-13/porting_to.html
index 84a00f21..ccd3f08f 100644
--- a/htdocs/gcc-13/porting_to.html
+++ b/htdocs/gcc-13/porting_to.html
@@ -42,5 +42,69 @@ be included explicitly when compiled with GCC 13:
+<h3 id="P2266">Implicit move rules change</h3>
+GCC 13 implements C++23 <a href="">P2266</a> which
+simplified the rules for implicit move.  As a consequence, valid C++20
+code that relies on a returned <em>id-expression</em>'s being an lvalue
+may change behavior or fail to compile in C++23.  For example:</p>
+   decltype(auto) f(int&& x) { return (x); }  // returns int&&; previously returned int&
+   int& g(int&& x) { return x; }  // ill-formed; previously well-formed
+<h3 id="two-stage-or">Two-stage overload resolution for implicit move removed</h3>
+<p>GCC 13 removed the two-stage overload resolution when performing
+implicit move, whereby the compiler does two separate overload resolutions:
+one treating the operand as an rvalue, and then (if that resolution fails)
+another one treating the operand as an lvalue.  In the standard this was
+introduced in C++11 and implemented in gcc in
+<a href=";a=commitdiff;h=4ce8c5dea53d80736b9c0ba6faa7430ed65ed365">
+r251035</a>.  In
+<a href=";a=commitdiff;h=1722e2013f05f1f1f99379dbaa0c0df356da731f">
+r11-2412</a>, the fallback overload resolution was disabled in C++20 (but
+not in C++17).  Then C++23 <a href="">P2266</a>
+removed the fallback overload resolution, and changed the implicit move
+rules once again.</p>
+<p>The two overload resolutions approach was complicated and quirky, so users
+should transition to the newer model.  This change means that code that
+previously didn't compile in C++17 will now compile, for example:</p>
+   struct S1 { S1(S1 &&); };
+   struct S2 : S1 {};
+   S1
+   f (S2 s)
+   {
+     return s; // OK, derived-to-base, use S1::S1(S1&&)
+   }
+<p>Conversely, code that used to work in C++17 may not compile anymore.
+For example, the following example used to compile in C++11...17 because
+we performed two separate overload resolutions: one treating the operand
+as an rvalue, and then (if that resolution failed) another one treating
+the operand as an lvalue.<br>
+   struct W {
+     W();
+   };
+   struct F {
+     F(W&);
+     F(W&&) = delete;
+   };
+   F fn ()
+   {
+     W w;
+     return w; // use w as rvalue -> use of deleted function F::F(W&&)
+   }


Summary of changes:
 htdocs/gcc-13/porting_to.html | 64 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)


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

only message in thread, other threads:[~2022-10-12 22:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-12 22:47 gcc-wwwdocs branch master updated. 0f3b5000bce0237ddf2f852099fea998cf476267 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).