Attending this event?
View analytic
Tuesday, September 25 • 15:15 - 15:45
RVO is Harder than it Looks: the story of -Wreturn-std-move

Sign up or log in to save this to your schedule and see who's attending!

Join Arthur O'Dwyer on a deep dive into Return Value Optimization and related topics.

Even C++03 allowed the compiler to "elide" copy construction in certain cases. We'll start with an explanation of the calling convention on a typical machine, showing where the mysterious "return slot" lives, and why it makes sense that C++03 allowed copy elision in certain special cases (but not others). Then we'll show how C++11 (and a subsequent defect report) upped the game by quietly turning the remaining copies into moves, so that the commonly received wisdom these days is that `return std::move(x)` is never necessary and often a pessimization.

...Or is it? We'll show some real-world examples where `return x` quietly copies a large object instead of moving it. We'll explain the little-known notion of a "converting constructor", contrast it with "conversion operator", and show the precise way in which C++17 drops the ball on these examples. Finally, Arthur implemented a Clang compiler warning to detect and suggest fixes for problematic return statements; he'll walk through the relatively painless process of creating that diagnostic, and perhaps inspire you to contribute to Clang yourself!


Tuesday September 25, 2018 15:15 - 15:45

Attendees (73)