public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Segher Boessenkool <segher@kernel.crashing.org>
Cc: Martin Oberzalek <kingleo@gmx.at>, gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: Guaranteed copy elision
Date: Sat, 19 Nov 2022 10:07:10 +0000	[thread overview]
Message-ID: <CAH6eHdSCZx0uDDQU_QoQbm=kR=mtY73=R6n9=PsjN4W3+FpAYQ@mail.gmail.com> (raw)
In-Reply-To: <20221118215804.GC25951@gate.crashing.org>

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

On Fri, 18 Nov 2022, 22:00 Segher Boessenkool, <segher@kernel.crashing.org>
wrote:

> On Fri, Nov 18, 2022 at 10:35:20PM +0100, Martin Oberzalek via Gcc-help
> wrote:
> > Am Freitag, dem 18.11.2022 um 16:05 +0100 schrieb Stefan Ring via Gcc-
> > help:
> > > On Tue, Nov 15, 2022 at 6:48 AM Yubin Ruan via Gcc-help
> > > <gcc-help@gcc.gnu.org> wrote:
> > > > Is there any language facility to help us guarantee that at compile
> > > > time
> > > > (such as some kind of static_assert() ) so that we can be confident
> > > > writing
> > > > those one-liner ?
>
> > With c++ language features this may is a solution:
>
> Nope.  Try with -O0 for example.
>
> There is no way to guarantee copy elision.  It isn't even clear what
> *exactly* you want guaranteed, what "copy elision" means *exactly*, what
> "guaranteeing copy elision" means, etc.
>

The standard defines what it means here:
https://eel.is/c++draft/class.copy.elision

Since C++17 it is guaranteed in certain situations:
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0135r0.html

There is a proposal to guarantee it in more cases, including the one the OP
asked about:
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2025r2.html
That has not been approved for the standard, but it explains the status quo
quite well.


> If you write clear and simple (which means: not artificially made
> complex) and correct source code, you can trust the compiler will
> generate good machine code for you (if you use -O2 or such).  If not,
> bug reports are welcome!
>
> A C compiler is not a "portable assembler", you have no direct control
> over generated code.  This is a good thing: the compiler is much better
> at writing fast machine code than users are.
>
>
> Segher
>

  reply	other threads:[~2022-11-19 10:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-15  5:47 Yubin Ruan
2022-11-18 15:05 ` Stefan Ring
2022-11-18 21:35   ` Martin Oberzalek
2022-11-18 21:58     ` Segher Boessenkool
2022-11-19 10:07       ` Jonathan Wakely [this message]
2022-11-19 10:12 ` Jonathan Wakely
2022-11-21 14:17   ` Yubin Ruan
2022-11-21 14:20     ` Jonathan Wakely

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='CAH6eHdSCZx0uDDQU_QoQbm=kR=mtY73=R6n9=PsjN4W3+FpAYQ@mail.gmail.com' \
    --to=jwakely.gcc@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=kingleo@gmx.at \
    --cc=segher@kernel.crashing.org \
    /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).