Skip to content

[Clang-Tidy][NFC] Simplify check cppcoreguidelines-missing-std-forward #138504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 7, 2025

Conversation

zwuis
Copy link
Contributor

@zwuis zwuis commented May 5, 2025

Remove CaptureInCopy because the cases handled by it are covered by CaptureByRefExplicit.

@llvmbot
Copy link
Member

llvmbot commented May 5, 2025

@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clang-tidy

Author: Yanzuo Liu (zwuis)

Changes

Remove CaptureInCopy because function parameters captured by copy should not be considered forwarded.

No functional changes because implicit captures are not added to capture list until the function is instantiated (P0588R1 is not implemented currently), so that CaptureInCopy never matches anything.


Full diff: https://github.com/llvm/llvm-project/pull/138504.diff

1 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp (+1-4)
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
index bbb35228ce47f..2e8d4f7860021 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
@@ -98,13 +98,10 @@ void MissingStdForwardCheck::registerMatchers(MatchFinder *Finder) {
       allOf(hasCaptureDefaultKind(LambdaCaptureDefault::LCD_ByRef),
             unless(hasAnyCapture(
                 capturesVar(varDecl(hasSameNameAsBoundNode("param"))))));
-  auto CaptureInCopy = allOf(
-      hasCaptureDefaultKind(LambdaCaptureDefault::LCD_ByCopy), HasRefToParm);
   auto CaptureByRefExplicit = hasAnyCapture(
       allOf(hasCaptureKind(LambdaCaptureKind::LCK_ByRef), RefToParm));
 
-  auto CapturedInBody =
-      lambdaExpr(anyOf(CaptureInRef, CaptureInCopy, CaptureByRefExplicit));
+  auto CapturedInBody = lambdaExpr(anyOf(CaptureInRef, CaptureByRefExplicit));
   auto CapturedInCaptureList = hasAnyCapture(capturesVar(
       varDecl(hasInitializer(ignoringParenImpCasts(equalsBoundNode("call"))))));
 

@carlosgalvezp
Copy link
Contributor

because the cases handled by it are covered by CaptureByRefExplicit.

Strange, can you explain why that's the case? Are we missing tests?

Copy link
Contributor Author

@zwuis zwuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange, can you explain why that's the case?

CaptureInCopy matches lambda expressions whose default capture kind is copy and which have an explicit capture referencing function parameter.

CaptureByRefExplicit matches lambda expressions which have an explicit capture captured by reference and referencing function parameter, not requiring default capture kind.

Are we missing tests?

I don't think we miss tests.

@zwuis
Copy link
Contributor Author

zwuis commented May 7, 2025

Thank you for your review!

I don't have commit access. Please help me merge this PR if it's ready.

@carlosgalvezp carlosgalvezp merged commit b7db2e1 into llvm:main May 7, 2025
11 checks passed
petrhosek pushed a commit to petrhosek/llvm-project that referenced this pull request May 8, 2025
llvm#138504)

Remove `CaptureInCopy` because the cases handled by it are covered by
`CaptureByRefExplicit`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants