[clang] [clang] Infer lifetime_capture_by for STL containers (PR #117122)

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 22 03:44:40 PST 2024


================
@@ -7,3 +7,106 @@ struct S {
 };
 
 // CHECK: CXXMethodDecl {{.*}}clang::lifetime_capture_by(a, b, global)
+
+// ****************************************************************************
+// Infer annotation for STL container methods.
+// ****************************************************************************
+namespace __gnu_cxx {
+template <typename T>
+struct basic_iterator {};
+}
+
+namespace std {
+template<typename T> class allocator {};
+template <typename T, typename Alloc = allocator<T>>
+struct vector {
+  typedef __gnu_cxx::basic_iterator<T> iterator;
+  iterator begin();
+
+  vector();
+
+  void push_back(const T&);
+  void push_back(T&&);
+
+  void insert(iterator, T&&);
+};
+} // namespace std
+struct [[gsl::Pointer()]] View {};
+std::vector<View> views;
+// CHECK:   ClassTemplateSpecializationDecl {{.*}} struct vector definition implicit_instantiation
+// CHECK:       TemplateArgument type 'View'
+// CHECK-NOT:   LifetimeCaptureByAttr
----------------
hokein wrote:

> That would add the annotation to all of its specializations which is not something we want.

Can you give a counter example? 

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


More information about the cfe-commits mailing list