[clang] [clang] Don't infer lifetime_capture-by for reference of raw pointer types. (PR #122240)

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 9 04:07:08 PST 2025


================
@@ -406,7 +406,7 @@ void use() {
   strings.insert(strings.begin(), std::string());
 
   std::vector<const std::string*> pointers;
-  pointers.push_back(getLifetimeBoundPointer(std::string())); // expected-warning {{object whose reference is captured by 'pointers' will be destroyed at the end of the full-expression}}
+  pointers.push_back(getLifetimeBoundPointer(std::string()));
----------------
Xazax-hun wrote:

For a follow-up PR, but I wonder if we can actually get this diagnostic back in the future. I think in case the pointer originates from a gsl owner, it is a strong indication that we care about the lifetime of the pointee and not the pointer itself and the capture_by annotation is what we actually want. 

But I am also OK never supporting this scenario as it starts to get a bit convoluted. 

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


More information about the cfe-commits mailing list