47 lines · plain
1.. title:: clang-tidy - bugprone-dangling-handle2 3bugprone-dangling-handle4========================5 6Detect dangling references in value handles like ``std::string_view``.7These dangling references can be a result of constructing handles from8temporary values, where the temporary is destroyed soon after the handle9is created.10 11Examples:12 13.. code-block:: c++14 15 string_view View = string(); // View will dangle.16 string A;17 View = A + "A"; // still dangle.18 19 vector<string_view> V;20 V.push_back(string()); // V[0] is dangling.21 V.resize(3, string()); // V[1] and V[2] will also dangle.22 23 string_view f() {24 // All these return values will dangle.25 return string();26 string S;27 return S;28 char Array[10]{};29 return Array;30 }31 32 span<int> g() {33 array<int, 1> V;34 return {V};35 int Array[10]{};36 return {Array};37 }38 39Options40-------41 42.. option:: HandleClasses43 44 A semicolon-separated list of class names that should be treated as handles.45 By default only ``std::basic_string_view``,46 ``std::experimental::basic_string_view`` and ``std::span`` are considered.47