Author: Baranov Victor
Date: 2025-08-05T10:41:15+03:00
New Revision: c5e6938c6710a1c34a32830c743f19a29ffef6e5

URL: 
https://github.com/llvm/llvm-project/commit/c5e6938c6710a1c34a32830c743f19a29ffef6e5
DIFF: 
https://github.com/llvm/llvm-project/commit/c5e6938c6710a1c34a32830c743f19a29ffef6e5.diff

LOG: [clang-tidy][docs][NFC] Add limitation of variable lifetimes in 
performance-unnecessary-copy-initialization (#151862)

Addresses https://github.com/llvm/llvm-project/issues/150189.

Added: 
    

Modified: 
    
clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-copy-initialization.rst

Removed: 
    


################################################################################
diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-copy-initialization.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-copy-initialization.rst
index bb4f42c88d62f..0e9d5476e7016 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-copy-initialization.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-copy-initialization.rst
@@ -59,3 +59,22 @@ Options
    types that don't own the underlying data. Like for `AllowedTypes` above,
    regular expressions are accepted and the inclusion of `::` determines 
whether
    the qualified typename is matched or not.
+
+
+Limitations
+-----------
+
+This check does not perform lifetime analysis and may suggest replacing copies
+with const references that could become dangling. Be cautious when the
+referenced object might be invalidated by subsequent operations.
+
+.. code-block:: c++
+
+  void consume(const S&);
+
+  void func(std::vector<S> &Vec) {
+    const auto It = Vec.begin();
+    const S Value(*It); // The warning will suggest making this a const 
reference.
+    Vec.erase(It); // Container modifications could invalidate references.
+    consume(Value); // Safe with copy, dangling reference otherwise.
+  }


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to