From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id 5C9D43858D1E for ; Sat, 19 Nov 2022 10:07:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5C9D43858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-x62c.google.com with SMTP id gv23so18588215ejb.3 for ; Sat, 19 Nov 2022 02:07:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=+DzKtay50ocx/fOtFwB/3Tjt5tl7nXHOtq3GCTCPkpw=; b=SDZ2Z22W273Z+BWdTyXBgXHwgluM4FBkb/rHEAEA2t+Tbpf1j9LZJMz5MuKGp3f/Aq E/rUAzRlxbOtlUuu16Z6P1Tia3hYki8SD4QNHH/6vNrxKtyvIhUCfZ5cdMhMHb8Dop5k atosmGZgIh8YfPvboaZCQyih4WRytZiAEbtxI4S8nq6VjqhxfxthS776lavv129g+Ct9 B2eWG/BSA8OZGr+3/c08UX/7ZUV16Vu2eCK/SR/dbz010tThme4uQoSPGrWVNIS6ohYm bdnBBS9SMSm39y09HQexpDitkD+XnmVonO92ICgl9IeKLzQCr9H3g1P1LghA23ej86UA NoWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+DzKtay50ocx/fOtFwB/3Tjt5tl7nXHOtq3GCTCPkpw=; b=W+0sKSX38SvPBzg42TUvU3XBG0LJnJuI7TyslhoQ1h/V3uLgi3dr1wqHZyNuhSfW5K 5o92ZFMUjhSOhHpBJ0p670iD6rHB0SlKownk/8JUhAdnR1gsrSBZA34ZiIos+uxN+H/2 PcT9h/rukJGRGtCy2GDlYI8oZZw61TwCU1dGLkL0bnnyoxhjo5ua1i4WtMOpgnEJVoNb 7H+oxa7xiARwImDowB7ezrPK7L78kwfP1FF9Hy/HNLdeOziQki3i9AkrStD5bflQKNpK 2Sjx6BxAgr4rv00yRgoqwaUFHm4ichEI+v7b+QnhMxonOok83HhmjaGOsprZsgb/5tnu Jeeg== X-Gm-Message-State: ANoB5pnS8E/fl1EzfuwWOwzJUbg8IiRFMH+1gKo23KVCtQcFkHInD1xM P/MdrxBavVOgw3dWOqqXNjVGIzP0nv3ocQ90cQY= X-Google-Smtp-Source: AA0mqf46VY7yTqn01YM4d16FD1cB8uGSkaQ16ZYgK0U+rZLIonJlpv7XIUNn9HUAh3kWnWJ4EMTDRVw6VE7ZJR8DJHA= X-Received: by 2002:a17:906:a397:b0:7ae:5381:bd02 with SMTP id k23-20020a170906a39700b007ae5381bd02mr8763252ejz.286.1668852444013; Sat, 19 Nov 2022 02:07:24 -0800 (PST) MIME-Version: 1.0 References: <32119174b061d5bf07e3d39063709f852ff5ca5f.camel@gmx.at> <20221118215804.GC25951@gate.crashing.org> In-Reply-To: <20221118215804.GC25951@gate.crashing.org> From: Jonathan Wakely Date: Sat, 19 Nov 2022 10:07:10 +0000 Message-ID: Subject: Re: Guaranteed copy elision To: Segher Boessenkool Cc: Martin Oberzalek , gcc-help Content-Type: multipart/alternative; boundary="0000000000001ba8ab05edcffdf4" X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --0000000000001ba8ab05edcffdf4 Content-Type: text/plain; charset="UTF-8" On Fri, 18 Nov 2022, 22:00 Segher Boessenkool, 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 > > > 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 > --0000000000001ba8ab05edcffdf4--