-
-
Notifications
You must be signed in to change notification settings - Fork 262
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
When given a function invoking NRVO, for example:
C f() {
C c;
return c;
}
The insight returns
C f()
{
C c = C() /* NRVO variable */;
return C(static_cast<C &&>(c));
}
If I substitute this directly in the code however, the compiler can no longer apply NRVO and instead calls the move constructor on c. See https://godbolt.org/z/qecYW1e9e. When returning c directly, there is no move constructor and only one destructor called.
Note however that if c is a parameter then the move construction is necessary, so this seems to be a correct translation in that case, e.g.
C f(C c) {
return c; // return C(static_cast<C &&>(c));
}
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working