Step 2 of 6
Review: dangling references
std::string_view and references are cheap views of data owned by someone else. The classic review catch: a view that outlives what it points at. It compiles cleanly, often seems to work in testing, and then prints garbage in production.
Red flags to look for:
- returning a
string_viewor a reference to a local or a temporary - storing a
string_viewmember initialized from a temporarystd::string - keeping a reference into a container that later grows
Your turn: this pull request adds a greeting helper and a Tag type. Both have lifetime bugs. Fix them by making each owner hold its own std::string. (The checks inspect the types too, since dangling-view bugs can seem to work by luck.)
Previous: Review: pagination Next: Review: leaks on the error path