public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Pedro Alves <palves@redhat.com>
Cc: gcc-patches List <gcc-patches@gcc.gnu.org>,
		Ville Voutilainen <ville.voutilainen@gmail.com>
Subject: Re: C++ PATCH for P0135, C++17 guaranteed copy elision
Date: Wed, 05 Oct 2016 23:22:00 -0000	[thread overview]
Message-ID: <CADzB+2mjquRQ62MDkpBCtP7cxjahiuDQOm+-2rZTv3Yf5Oaq_w@mail.gmail.com> (raw)
In-Reply-To: <68323906-2179-82c7-98f9-0fd2ddb40ab5@redhat.com>

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

On Wed, Oct 5, 2016 at 7:15 PM, Pedro Alves <palves@redhat.com> wrote:
> On 10/05/2016 11:57 PM, Jason Merrill wrote:
>> --- a/gcc/c-family/c-opts.c
>> +++ b/gcc/c-family/c-opts.c
>> @@ -1579,6 +1579,7 @@ set_std_cxx1z (int iso)
>> +  flag_elide_constructors = 2;

Oops, that was an earlier version of the patch.  Here's what I checked
in, which doesn't touch flag_elide_constructors.

> Does -fno-elide-constructors have any effect in C++17 mode?
> Should it perhaps be an error, or ignored?

It does have an effect: it avoids open-coding trivial copies.  I
suppose I should update the documentation.

Jason

[-- Attachment #2: elision.diff --]
[-- Type: text/plain, Size: 1560 bytes --]

commit d47a992158cc6f8a6d84f365e7d4f88ee567b640
Author: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Wed Oct 5 22:59:02 2016 +0000

            Implement P0135R1, Guaranteed copy elision.
    
            * cvt.c (ocp_convert): Don't re-copy a TARGET_EXPR in C++17.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@240820 138bc75d-0d04-0410-961f-82ee72b054a4

diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 2f5f15a..ecc8ef8 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -693,8 +693,11 @@ ocp_convert (tree type, tree expr, int convtype, int flags,
   if (error_operand_p (e))
     return error_mark_node;
 
-  if (MAYBE_CLASS_TYPE_P (type) && (convtype & CONV_FORCE_TEMP))
-    /* We need a new temporary; don't take this shortcut.  */;
+  if (MAYBE_CLASS_TYPE_P (type) && (convtype & CONV_FORCE_TEMP)
+      && !(cxx_dialect >= cxx1z
+	   && TREE_CODE (e) == TARGET_EXPR))
+    /* We need a new temporary; don't take this shortcut.  But in C++17, don't
+       force a temporary if we already have one.  */;
   else if (same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (e)))
     {
       if (same_type_p (type, TREE_TYPE (e)))
diff --git a/gcc/testsuite/g++.dg/cpp1z/elide1.C b/gcc/testsuite/g++.dg/cpp1z/elide1.C
new file mode 100644
index 0000000..a0538bb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/elide1.C
@@ -0,0 +1,16 @@
+// { dg-options -std=c++1z }
+
+struct A
+{
+  A();
+  A(const A&) = delete;
+};
+
+bool b;
+A a = A();
+A a1 = b ? A() : A();
+A a2 = (42, A());
+
+A f();
+A a3 = f();
+A a4 = b ? A() : f();

  reply	other threads:[~2016-10-05 23:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-05 22:57 Jason Merrill
2016-10-05 23:16 ` Pedro Alves
2016-10-05 23:22   ` Jason Merrill [this message]
2016-10-06 21:26     ` Jason Merrill
2016-10-08 16:27       ` Jason Merrill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADzB+2mjquRQ62MDkpBCtP7cxjahiuDQOm+-2rZTv3Yf5Oaq_w@mail.gmail.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=palves@redhat.com \
    --cc=ville.voutilainen@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).