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@xxxxxxxxxxx> 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. 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