public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [wwwdocs] Document C++ DR 1579 in /gcc-5/porting_to.html
@ 2015-03-10 17:44 Jonathan Wakely
  2015-03-10 18:11 ` Sandra Loosemore
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2015-03-10 17:44 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 175 bytes --]

This change shouldn't cause many porting headaches, but it did cause
one package to fail to build (due to a bug in the package), so it's
worth documenting.

Committed to CVS.

[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 1558 bytes --]

Index: porting_to.html
===================================================================
RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-5/porting_to.html,v
retrieving revision 1.5
diff -u -r1.5 porting_to.html
--- porting_to.html	18 Feb 2015 13:41:12 -0000	1.5
+++ porting_to.html	10 Mar 2015 17:37:15 -0000
@@ -385,6 +385,38 @@
 It is recommended to use <code>true</code>, resp. <code>false</code> keywords
 in such cases.
 
+<h3>Return by converting move constructor</h3>
+
+<p>GCC 5 implements
+<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1579">DR 1579</a>
+which means that in a function like:</p>
+
+<pre><code>
+  X
+  foo()
+  {
+    Y y;
+    return y;
+  }
+</code></pre>
+
+<p>GCC will first attempt to construct the return value as if <code>y</code> 
+were an rvalue, and if that fails then it will try again for an lvalue
+(all C++11 compilers already do this when returning a variable of the
+same type as the function returns, but now they are required to do it
+when the types are not the same).
+This will change the constructor that gets called in some cases,
+for example it might now call <code>X(Y&amp;&amp;)</code> instead of
+<code>X(const Y&amp;)</code>.
+</p>
+<p>
+In most cases the only observable difference will be code that runs faster
+(by moving instead of copying) but if it causes a problem the new behavior
+can be prevented by ensuring the compiler treats <code>y</code> as an lvalue,
+using <code>return X(y);</code> or
+<code>return static_cast&lt;Y&amp;&gt;(y);</code>.
+</p>
+
 <h3>Links</h3>
 
 <p>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [wwwdocs] Document C++ DR 1579 in /gcc-5/porting_to.html
  2015-03-10 17:44 [wwwdocs] Document C++ DR 1579 in /gcc-5/porting_to.html Jonathan Wakely
@ 2015-03-10 18:11 ` Sandra Loosemore
  2015-03-10 18:59   ` Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: Sandra Loosemore @ 2015-03-10 18:11 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-patches

On 03/10/2015 11:43 AM, Jonathan Wakely wrote:
>
> +<h3>Return by converting move constructor</h3>
> +
> +<p>GCC 5 implements
> +<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1579">DR 1579</a>
> +which means that in a function like:</p>
> +
> +<pre><code>
> +  X
> +  foo()
> +  {
> +    Y y;
> +    return y;
> +  }
> +</code></pre>
> +
> +<p>GCC will first attempt to construct the return value as if <code>y</code>
> +were an rvalue, and if that fails then it will try again for an lvalue
> +(all C++11 compilers already do this when returning a variable of the
> +same type as the function returns, but now they are required to do it
> +when the types are not the same).
> +This will change the constructor that gets called in some cases,
> +for example it might now call <code>X(Y&amp;&amp;)</code> instead of
> +<code>X(const Y&amp;)</code>.
> +</p>
> +<p>
> +In most cases the only observable difference will be code that runs faster
> +(by moving instead of copying) but if it causes a problem the new behavior
> +can be prevented by ensuring the compiler treats <code>y</code> as an lvalue,
> +using <code>return X(y);</code> or
> +<code>return static_cast&lt;Y&amp;&gt;(y);</code>.
> +</p>
> +

Errrmmmm.  If GCC 5 implements (present tense) this new feature, why is 
the description written mostly in the future tense?  :-(

-Sandra the grammar geek

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [wwwdocs] Document C++ DR 1579 in /gcc-5/porting_to.html
  2015-03-10 18:11 ` Sandra Loosemore
@ 2015-03-10 18:59   ` Jonathan Wakely
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Wakely @ 2015-03-10 18:59 UTC (permalink / raw)
  To: Sandra Loosemore; +Cc: gcc-patches

On 10/03/15 12:10 -0600, Sandra Loosemore wrote:
>Errrmmmm.  If GCC 5 implements (present tense) this new feature, why 
>is the description written mostly in the future tense?  :-(

When compiling such a function, GCC will do as described.

I'm happy to change it though, how's the attached revision?

(I also changed "as if y were an rvalue" to "as though y were an
rvalue" because the repetition of "if" that follows seems clunky now I
read it again.)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-03-10 18:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-10 17:44 [wwwdocs] Document C++ DR 1579 in /gcc-5/porting_to.html Jonathan Wakely
2015-03-10 18:11 ` Sandra Loosemore
2015-03-10 18:59   ` Jonathan Wakely

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