Multiple ChoiceBeginner 45s
initializer_list lifetime trap
A function returns std::string_view built from an initializer_list expression; what is the hazard?
Options
- 1The initializer_list object is always heap allocated and therefore leaks unless freed manually
- 2No hazard, because the backing initializer_list array lives in static storage for program lifetime
- 3The backing array is a temporary destroyed at the end of the full expression, leaving a dangling view
- 4The string_view copies the underlying characters into its own buffer, so the returned view is safe
Think you can answer under pressure?
Get matched and answer live questions in 3-minute 1v1 battles. Elo ranking, badge tiers and bragging rights on the line.