File tree Expand file tree Collapse file tree 3 files changed +15
-14
lines changed Expand file tree Collapse file tree 3 files changed +15
-14
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -5,10 +5,14 @@ cppcoreguidelines-misleading-capture-default-by-value
55
66Warns 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
1317Examples:
1418
You can’t perform that action at this time.
0 commit comments