The C++ rvalue Lifetime Disaster - Arno Schoedl - C++ on Sea 2023
---
The C rvalue Lifetime Disaster - Arno Schoedl - C on Sea 2023
Rvalue references have been with us since C 11. They have originally been introduced to make moving objects more efficient: the object an rvalue reference references is assumed to go out of scope soon and thus may have its resources scavenged without harm. The C standard library, for example std::cref or std::ranges, makes use of yet another aspect of rvalue references: since they go out of scope soon, it is assumed unsafe to hold on to them beyond the scope of the current function, while lvalue references are considered safe. We, too, found this assumption to be very useful for smart memory management, in particular in generic code.
Unfortunately, the C language itself violates this assumption. Rvalues bind to const&. This means that innocent-looking functions silently convert rvalues to lvalue references, hiding any lifetime limitation of the rvalues. Temporary lifetime extension is meant to make binding a temporary to a reference safe by extending the lifetime of the temporary. But this only works as long as the temporary is a prvalue, and already breaks with rvalue references, let alone spuriously generated lvalue ones. These problems are not merely theoretical. We have had hard-to-find memory corruption in our code because of these problems. In this talk, I will describe the problems in detail, present our library-only approach to mitigate the problems, and finally, make an impossible-to-ever-get-into-the-standard proposal of how to put things right.
---
Slides:
Sponsored by think-cell:
---
Arno Schoedl
think-cell founder & CTO.
Arno is responsible for the development of all think-cell software products. He oversees our R&D team, quality assurance and customer care. Before founding think-cell, Arno worked at Microsoft Research and McKinsey. Arno studied computer science and management and holds a Ph.D. from Georgia Tech with a specialization in computer graphics.
---
C on Sea is an annual C and coding conference, in Folkestone, in the UK.
- Annual C on Sea, C conference:
- 2023 Program:
- Twitter:
---
YouTube Videos Filmed, Edited & Optimised by Digital Medium:
#cpp #cpponsea #cppprogramming
1 view
245
77
5 hours ago 00:13:21 1
Kendrick Lamar’s Apple Music Super Bowl Halftime Show
5 hours ago 00:03:11 1
Самолёты -189 Aircraft Airplane हवाई जहाज 飛機 航空Đ
1 day ago 00:00:26 1
Весна Flowers -600 #shorts 花朵 पुष्प フラワーズ 꽃
1 day ago 00:25:37 1
Почему MiSide НЕ ЗАСЛУЖИВАЕТ такого ХАЙПА.
3 days ago 02:34:09 1
[Longplay] VNC - The Virtual Nightclub (1997) - Complete Playthrough
3 days ago 01:49:25 1
Virtual Night Club #1 - Gimme the Chip
4 days ago 00:00:00 8
FIN DE LA GUERRE EN UKRAINE : POUTINE DEVIENT LE MAÎTRE DU JEU ! | LA MATINALE GPTV