• g++ 14 new feature bug

    From Bonita Montero@Bonita.Montero@gmail.com to comp.lang.c++ on Sun Oct 6 18:22:15 2024
    From Newsgroup: comp.lang.c++

    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 ?
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Bonita Montero@Bonita.Montero@gmail.com to comp.lang.c++ on Sun Oct 6 18:52:19 2024
    From Newsgroup: comp.lang.c++

    Am 06.10.2024 um 18:22 schrieb Bonita Montero:
    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 ?

    Sorry, misconception: copy elision doesn't mean that a copy is
    transformed into a move but that the copy / move does take place
    in the callers place.

    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Andrey Tarasevich@andreytarasevich@hotmail.com to comp.lang.c++ on Sun Oct 6 13:00:33 2024
    From Newsgroup: comp.lang.c++

    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.
    --
    Best regards,
    Andrey
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Bonita Montero@Bonita.Montero@gmail.com to comp.lang.c++ on Mon Oct 7 10:47:59 2024
    From Newsgroup: comp.lang.c++

    Am 06.10.2024 um 22:00 schrieb Andrey Tarasevich:
    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.


    I already corrected myself in that sense before you posted.

    --- Synchronet 3.20a-Linux NewsLink 1.114