Skip to content

NRVO not eliding copy on immediatly-invoked lambda #144323

Open
@hcmh

Description

@hcmh

clang trunk from Compiler Explorer does not perform NRVO on the following code (triggering -Wnrvo):

    const char d = 'a';
    const auto b = [] (auto c) {
        std::string a{c};
        return a;
    }(d);

Changing the lambda argument from auto

[] (char c) { ...

or adding an explicit trailing return type:

[] (auto c) -> std::string { ...

does lead to NRVO.

Expected behavior: No error when compiling with -Werror -Wnrvo.
LLVM version: trunk from Compiler Explorer

Example on Compiler Explorer

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions