[clang] [clang] Detect dangling assignment for "Container<Pointer>" case. (PR #108205)

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 2 07:35:01 PDT 2024


================
@@ -601,17 +601,23 @@ void test() {
   std::optional<std::string_view> o4 = std::optional<std::string_view>(s); 
 
   // FIXME: should work for assignment cases
-  v1 = {std::string()};
-  o1 = std::string();
+  v1 = {std::string()}; // expected-warning {{object backing the pointer}}
+  o1 = std::string(); // expected-warning {{object backing the pointer}}
 
   // no warning on copying pointers.
   std::vector<std::string_view> n1 = {std::string_view()};
+  n1 = {std::string_view()};
----------------
hokein wrote:

Done, added. Current we only support the first-level nested container.

https://github.com/llvm/llvm-project/pull/108205


More information about the cfe-commits mailing list