[clang] [clang] Infer lifetime_capture_by for STL containers (PR #117122)
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 22 00:45:21 PST 2024
================
@@ -268,6 +268,40 @@ void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) {
}
}
+static bool IsPointerLikeType(QualType QT) {
+ QT = QT.getNonReferenceType();
+ if (QT->isPointerType())
+ return true;
+ auto *RD = QT->getAsCXXRecordDecl();
+ if (!RD)
+ return false;
+ RD = RD->getCanonicalDecl();
+ if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD))
+ RD = CTSD->getSpecializedTemplate()->getTemplatedDecl();
----------------
usx95 wrote:
We fail to detect pointer types which are templates:
```cpp
template <class T> struct [[gsl::Pointer()]] ViewTemplate {};
std::vector<ViewTemplate<int>> templated_views;
```
```cpp
template<typename T>
struct [[gsl::Pointer]] Span {
Span(const std::vector<T> &V);
};
void use() {
std::vector<Span<int>> spans;
spans.push_back(std::vector<int>{1, 2, 3}); // warning.
}
```
https://github.com/llvm/llvm-project/pull/117122
More information about the cfe-commits
mailing list