Author: Haojian Wu Date: 2024-10-14T21:09:00+02:00 New Revision: 0eaccee1800331d6a4a3a58d52325279ca187066
URL: https://github.com/llvm/llvm-project/commit/0eaccee1800331d6a4a3a58d52325279ca187066 DIFF: https://github.com/llvm/llvm-project/commit/0eaccee1800331d6a4a3a58d52325279ca187066.diff LOG: [Clang] Diagnose dangling references in std::vector. (#111753) This is a follow-up to https://github.com/llvm/llvm-project/pull/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 #111680 Added: Modified: clang/lib/Sema/CheckExprLifetime.cpp clang/test/Sema/warn-lifetime-analysis-nocfg.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/CheckExprLifetime.cpp b/clang/lib/Sema/CheckExprLifetime.cpp index 009b8d000e6b0e..9b3894767d8629 100644 --- a/clang/lib/Sema/CheckExprLifetime.cpp +++ b/clang/lib/Sema/CheckExprLifetime.cpp @@ -404,7 +404,7 @@ shouldTrackFirstArgumentForConstructor(const CXXConstructExpr *Ctor) { if (LHSRecordDecl->hasAttr<PointerAttr>()) return true; - if (Ctor->getConstructor()->getNumParams() != 1 || + if (Ctor->getConstructor()->param_empty() || !isContainerOfPointer(LHSRecordDecl)) return false; diff --git a/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp b/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp index 731639ab16a735..688f55edfe84df 100644 --- a/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp +++ b/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp @@ -164,14 +164,16 @@ template<typename T> struct initializer_list { const T* ptr; size_t sz; }; -template <typename T> +template<typename T> class allocator {}; +template <typename T, typename Alloc = allocator<T>> struct vector { typedef __gnu_cxx::basic_iterator<T> iterator; iterator begin(); iterator end(); const T *data() const; vector(); - vector(initializer_list<T> __l); + vector(initializer_list<T> __l, + const Alloc& alloc = Alloc()); template<typename InputIterator> vector(InputIterator first, InputIterator __last); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits