~/talk

Surprises in Object Lifetime

Talkat CppCon 2018 · 2018-09-23..09-28· [c-and-cpp]
slides:none on file

Concrete surprises: implicit wrappers like reference_wrapper and string_view produce dangling references with no compiler warnings, returning or binding to temporaries sometimes extends lifetime but not recursively, and initializer_list creates hidden const arrays that can cause five allocations when building a vector. Structured bindings block moves, and C++17 if-init bindings leak into else blocks. Examples run on Compiler Explorer with clang/gcc; static tools miss many cases while sanitizers and constexpr checks reliably catch the undefined behaviors.

AI-written summary · about

  1. 0:00Introduction and welcome
  2. 2:52What is object lifetime
  3. 8:13Basic object lifetime examples
  4. 13:14Reference wrappers surprises
  5. 17:14Strings lifetime surprises
  6. 19:26Moved-from objects destruction
  7. 22:59Temporary lifetime extension
  8. 27:08Initializer list allocations
  9. 32:54Standard array efficiency
  10. 38:38Range-based for loops
  11. 41:48C++20 for-init statements
  12. 43:34If-init statement scope
  13. 44:39RVO and NRVO
  14. 47:32Structured bindings moves
  15. 51:11Constructor exceptions
  16. 53:59Delegating constructors
  17. 55:05Avoiding lifetime surprises
  18. 58:56Constexpr and sanitizers
  19. 1:00:01Q&A
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.