Skip to content

Commit 6f6d4de

Browse files
hokeinDanielCChen
authored andcommitted
[Clang] Diagnose dangling references in std::vector. (llvm#111753)
This is a follow-up to llvm#108344. The original bailout check was overly strict, causing it to miss cases like the vector(initializer_list, allocator) constructor. This patch relaxes the check to address that issue. Fix llvm#111680
1 parent 8ac1788 commit 6f6d4de

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

clang/lib/Sema/CheckExprLifetime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ shouldTrackFirstArgumentForConstructor(const CXXConstructExpr *Ctor) {
404404
if (LHSRecordDecl->hasAttr<PointerAttr>())
405405
return true;
406406

407-
if (Ctor->getConstructor()->getNumParams() != 1 ||
407+
if (Ctor->getConstructor()->param_empty() ||
408408
!isContainerOfPointer(LHSRecordDecl))
409409
return false;
410410

clang/test/Sema/warn-lifetime-analysis-nocfg.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,16 @@ template<typename T>
164164
struct initializer_list {
165165
const T* ptr; size_t sz;
166166
};
167-
template <typename T>
167+
template<typename T> class allocator {};
168+
template <typename T, typename Alloc = allocator<T>>
168169
struct vector {
169170
typedef __gnu_cxx::basic_iterator<T> iterator;
170171
iterator begin();
171172
iterator end();
172173
const T *data() const;
173174
vector();
174-
vector(initializer_list<T> __l);
175+
vector(initializer_list<T> __l,
176+
const Alloc& alloc = Alloc());
175177

176178
template<typename InputIterator>
177179
vector(InputIterator first, InputIterator __last);

0 commit comments

Comments
 (0)