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

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 23 03:38:22 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()};
----------------
Xazax-hun wrote:

Not strictly related to this PR, but we could add some tests for more deeply nested containers like `std::vector<std::vector<std::string_view>>`. Regardless if we gat warnings for those or not, documenting whether this case works in tests have some value. 

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


More information about the cfe-commits mailing list