Skip to content

Commit fa3de2e

Browse files
committed
[clang-tidy][NFC] Improve doc of cppcoreguidelines-misleading-capture-default-by-value
Also fix ordering in Release Notes. Differential Revision: https://reviews.llvm.org/D148424
1 parent d5193e3 commit fa3de2e

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@ namespace clang::tidy::cppcoreguidelines {
1616

1717
/// Warns when lambda specify a by-value capture default and capture ``this``.
1818
///
19-
/// By-value capture defaults in lambas defined within member functions can be
20-
/// misleading about whether capturing data member is by value or reference.
21-
/// For example, [=] will capture local variables by value but member variables
22-
/// by reference. CppCoreGuideline F.54 suggests to never use by-value capture
23-
/// default when capturing this.
19+
/// By-value capture defaults in member functions can be misleading about
20+
/// whether data members are captured by value or reference.
2421
///
2522
/// For the user-facing documentation see:
2623
/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.html

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,18 @@ New checks
112112
This check relies heavily on, but is not exclusive to, the functions from
113113
the *Annex K. "Bounds-checking interfaces"* of C11.
114114

115-
- New :doc:`cppcoreguidelines-misleading-capture-default-by-value
116-
<clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value>` check.
117-
118-
Warns when lambda specify a by-value capture default and capture ``this``.
119-
120115
- New :doc:`cppcoreguidelines-avoid-capturing-lambda-coroutines
121116
<clang-tidy/checks/cppcoreguidelines/avoid-capturing-lambda-coroutines>` check.
122117

123118
Flags C++20 coroutine lambdas with non-empty capture lists that may cause
124119
use-after-free errors and suggests avoiding captures or ensuring the lambda
125120
closure object has a guaranteed lifetime.
126121

122+
- New :doc:`cppcoreguidelines-misleading-capture-default-by-value
123+
<clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value>` check.
124+
125+
Warns when lambda specify a by-value capture default and capture ``this``.
126+
127127
- New :doc:`cppcoreguidelines-rvalue-reference-param-not-moved
128128
<clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved>` check.
129129

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ cppcoreguidelines-misleading-capture-default-by-value
55

66
Warns when lambda specify a by-value capture default and capture ``this``.
77

8-
By-value capture-defaults in member functions can be misleading about
9-
whether data members are captured by value or reference. For example,
10-
specifying the capture default ``[=]`` will still capture data members
11-
by reference.
8+
By-value capture defaults in member functions can be misleading about whether
9+
data members are captured by value or reference. This occurs because specifying
10+
the capture default ``[=]`` actually captures the ``this`` pointer by value,
11+
not the data members themselves. As a result, data members are still indirectly
12+
accessed via the captured ``this`` pointer, which essentially means they are
13+
being accessed by reference. Therefore, even when using ``[=]``, data members
14+
are effectively captured by reference, which might not align with the user's
15+
expectations.
1216

1317
Examples:
1418

0 commit comments

Comments
 (0)