[PATCH] D148424: [clang-tidy][NFC] Improve doc of cppcoreguidelines-misleading-capture-default-by-value

Carlos Galvez via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 15 05:07:29 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rGfa3de2ed2964: [clang-tidy][NFC] Improve doc of cppcoreguidelines-misleading-capture-default… (authored by carlosgalvezp).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148424/new/

https://reviews.llvm.org/D148424

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst


Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst
===================================================================
--- clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst
+++ clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst
@@ -5,10 +5,14 @@
 
 Warns when lambda specify a by-value capture default and capture ``this``.
 
-By-value capture-defaults in member functions can be misleading about
-whether data members are captured by value or reference. For example,
-specifying the capture default ``[=]`` will still capture data members
-by reference.
+By-value capture defaults in member functions can be misleading about whether
+data members are captured by value or reference. This occurs because specifying
+the capture default ``[=]`` actually captures the ``this`` pointer by value,
+not the data members themselves. As a result, data members are still indirectly
+accessed via the captured ``this`` pointer, which essentially means they are
+being accessed by reference. Therefore, even when using ``[=]``, data members
+are effectively captured by reference, which might not align with the user's
+expectations.
 
 Examples:
 
Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -112,11 +112,6 @@
   This check relies heavily on, but is not exclusive to, the functions from
   the *Annex K. "Bounds-checking interfaces"* of C11.
 
-- New :doc:`cppcoreguidelines-misleading-capture-default-by-value
-  <clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value>` check.
-
-  Warns when lambda specify a by-value capture default and capture ``this``.
-
 - New :doc:`cppcoreguidelines-avoid-capturing-lambda-coroutines
   <clang-tidy/checks/cppcoreguidelines/avoid-capturing-lambda-coroutines>` check.
 
@@ -124,6 +119,11 @@
   use-after-free errors and suggests avoiding captures or ensuring the lambda
   closure object has a guaranteed lifetime.
 
+- New :doc:`cppcoreguidelines-misleading-capture-default-by-value
+  <clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value>` check.
+
+  Warns when lambda specify a by-value capture default and capture ``this``.
+
 - New :doc:`cppcoreguidelines-rvalue-reference-param-not-moved
   <clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved>` check.
 
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
===================================================================
--- clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
@@ -16,11 +16,8 @@
 
 /// Warns when lambda specify a by-value capture default and capture ``this``.
 ///
-/// By-value capture defaults in lambas defined within member functions can be
-/// misleading about whether capturing data member is by value or reference.
-/// For example, [=] will capture local variables by value but member variables
-/// by reference. CppCoreGuideline F.54 suggests to never use by-value capture
-/// default when capturing this.
+/// By-value capture defaults in member functions can be misleading about
+/// whether data members are captured by value or reference.
 ///
 /// For the user-facing documentation see:
 /// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.html


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148424.513891.patch
Type: text/x-patch
Size: 3658 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230415/4638b43e/attachment-0001.bin>


More information about the cfe-commits mailing list