g++ 14 has a new feature which that warns when a return value
optimization / copy elision doesn't take place. Here's my example:
https://godbolt.org/z/G8Eh1hrsd
As you can see the compiler warns twice - but moves according to
the program output nevertheless. Is this a bug ?
g++ 14 has a new feature which that warns when a return value
optimization / copy elision doesn't take place. Here's my example:
https://godbolt.org/z/G8Eh1hrsd
As you can see the compiler warns twice - but moves according to
the program output nevertheless. Is this a bug ?
On 10/06/24 9:22 AM, Bonita Montero wrote:
g++ 14 has a new feature which that warns when a return value
optimization / copy elision doesn't take place. Here's my example:
https://godbolt.org/z/G8Eh1hrsd
As you can see the compiler warns twice - but moves according to
the program output nevertheless. Is this a bug ?
NRVO (which is what the option name refers to) is not about moving
instead of copying. It is about eliminating the named local object
entirely, effectively transforming it into a reference to the caller-
owned recipient object. In case of NRVO the result is constructed
directly in the external recipient object.
In your case the NRVO does not happen. Hence the warning.
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 991 |
Nodes: | 10 (1 / 9) |
Uptime: | 76:03:21 |
Calls: | 12,949 |
Calls today: | 3 |
Files: | 186,574 |
Messages: | 3,264,538 |