[clang-tools-extra] Add flag to specify an alternative to std::forward (PR #138755)

2025-05-07 Thread Dimitrije Dobrota via cfe-commits

https://github.com/DimitrijeDobrota updated 
https://github.com/llvm/llvm-project/pull/138755



  



Rate limit · GitHub


  body {
background-color: #f6f8fa;
color: #24292e;
font-family: -apple-system,BlinkMacSystemFont,Segoe 
UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;
font-size: 14px;
line-height: 1.5;
margin: 0;
  }

  .container { margin: 50px auto; max-width: 600px; text-align: center; 
padding: 0 24px; }

  a { color: #0366d6; text-decoration: none; }
  a:hover { text-decoration: underline; }

  h1 { line-height: 60px; font-size: 48px; font-weight: 300; margin: 0px; 
text-shadow: 0 1px 0 #fff; }
  p { color: rgba(0, 0, 0, 0.5); margin: 20px 0 40px; }

  ul { list-style: none; margin: 25px 0; padding: 0; }
  li { display: table-cell; font-weight: bold; width: 1%; }

  .logo { display: inline-block; margin-top: 35px; }
  .logo-img-2x { display: none; }
  @media
  only screen and (-webkit-min-device-pixel-ratio: 2),
  only screen and (   min--moz-device-pixel-ratio: 2),
  only screen and ( -o-min-device-pixel-ratio: 2/1),
  only screen and (min-device-pixel-ratio: 2),
  only screen and (min-resolution: 192dpi),
  only screen and (min-resolution: 2dppx) {
.logo-img-1x { display: none; }
.logo-img-2x { display: inline-block; }
  }

  #suggestions {
margin-top: 35px;
color: #ccc;
  }
  #suggestions a {
color: #66;
font-weight: 200;
font-size: 14px;
margin: 0 10px;
  }


  
  



  Whoa there!
  You have exceeded a secondary rate limit.
Please wait a few minutes before you try again;
in some cases this may take up to an hour.
  
  
https://support.github.com/contact";>Contact Support —
https://githubstatus.com";>GitHub Status —
https://twitter.com/githubstatus";>@githubstatus
  

  

  

  

  

  


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Add flag to specify an alternative to std::move (PR #138757)

2025-05-07 Thread Dimitrije Dobrota via cfe-commits

https://github.com/DimitrijeDobrota updated 
https://github.com/llvm/llvm-project/pull/138757



  



Rate limit · GitHub


  body {
background-color: #f6f8fa;
color: #24292e;
font-family: -apple-system,BlinkMacSystemFont,Segoe 
UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;
font-size: 14px;
line-height: 1.5;
margin: 0;
  }

  .container { margin: 50px auto; max-width: 600px; text-align: center; 
padding: 0 24px; }

  a { color: #0366d6; text-decoration: none; }
  a:hover { text-decoration: underline; }

  h1 { line-height: 60px; font-size: 48px; font-weight: 300; margin: 0px; 
text-shadow: 0 1px 0 #fff; }
  p { color: rgba(0, 0, 0, 0.5); margin: 20px 0 40px; }

  ul { list-style: none; margin: 25px 0; padding: 0; }
  li { display: table-cell; font-weight: bold; width: 1%; }

  .logo { display: inline-block; margin-top: 35px; }
  .logo-img-2x { display: none; }
  @media
  only screen and (-webkit-min-device-pixel-ratio: 2),
  only screen and (   min--moz-device-pixel-ratio: 2),
  only screen and ( -o-min-device-pixel-ratio: 2/1),
  only screen and (min-device-pixel-ratio: 2),
  only screen and (min-resolution: 192dpi),
  only screen and (min-resolution: 2dppx) {
.logo-img-1x { display: none; }
.logo-img-2x { display: inline-block; }
  }

  #suggestions {
margin-top: 35px;
color: #ccc;
  }
  #suggestions a {
color: #66;
font-weight: 200;
font-size: 14px;
margin: 0 10px;
  }


  
  



  Whoa there!
  You have exceeded a secondary rate limit.
Please wait a few minutes before you try again;
in some cases this may take up to an hour.
  
  
https://support.github.com/contact";>Contact Support —
https://githubstatus.com";>GitHub Status —
https://twitter.com/githubstatus";>@githubstatus
  

  

  

  

  

  


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add flag to specify an alternative to std::forward (PR #138755)

2025-05-08 Thread Dimitrije Dobrota via cfe-commits

https://github.com/DimitrijeDobrota edited 
https://github.com/llvm/llvm-project/pull/138755
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Add flag to specify an alternative to std::forward (PR #138755)

2025-05-08 Thread Dimitrije Dobrota via cfe-commits

DimitrijeDobrota wrote:

> LGTM. It looks similar as #138757. could you add a test for both PR.

I have the issue where I want to test the `custom_move` and I need check to 
pass only for `-check-suffix=,MOVEFUNCTION` and fail for everything else, since 
it still expects `::std::move`. I am not sure how to write this. Apart from 
this, I've managed to add necessary checks for the existing set of test cases.

```c++
void move_with_custom(Obj&& o) {
  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: rvalue reference parameter 'o' 
is never moved from inside the function body 
[cppcoreguidelines-rvalue-reference-param-not-moved]
  // CHECK-MESSAGES-MOVEFUNCTION: no error in this case

  Obj other{custom_move(o)};
```

https://github.com/llvm/llvm-project/pull/138755
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add flag to specify an alternative to std::forward (PR #138755)

2025-06-30 Thread Dimitrije Dobrota via cfe-commits

https://github.com/DimitrijeDobrota updated 
https://github.com/llvm/llvm-project/pull/138755

>From b6d3a401284022bca317079154764c80b18dcbdd Mon Sep 17 00:00:00 2001
From: Dimitrije Dobrota 
Date: Tue, 6 May 2025 22:18:43 +0200
Subject: [PATCH 1/4] Add flag to specify an alternative to std::forward

Since std::forward is nothing more than a cast, part of STL and not the
language itself, it's easy to provide a custom implementation if one
wishes not to include the entirety of .

Added flag (ForwardFunction) provides a way to continue using this
essential check even with the custom implementation of forwarding.
---
 .../cppcoreguidelines/MissingStdForwardCheck.cpp  | 11 ++-
 .../cppcoreguidelines/MissingStdForwardCheck.h|  7 +--
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 
 .../checks/cppcoreguidelines/missing-std-forward.rst  |  8 
 4 files changed, 27 insertions(+), 3 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
index cf299609e646d..268b51f76a2c3 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
@@ -120,7 +120,7 @@ void MissingStdForwardCheck::registerMatchers(MatchFinder 
*Finder) {
   equalsBoundNode("param"), 
equalsBoundNode("var")),
 CapturedInLambda)),
   callee(unresolvedLookupExpr(hasAnyDeclaration(
-  namedDecl(hasUnderlyingDecl(hasName("::std::forward")),
+  namedDecl(hasUnderlyingDecl(hasName(ForwardFunction)),
 
   unless(anyOf(hasAncestor(typeLoc()),
hasAncestor(expr(hasUnevaluatedContext());
@@ -149,4 +149,13 @@ void MissingStdForwardCheck::check(const 
MatchFinder::MatchResult &Result) {
   << Param;
 }
 
+MissingStdForwardCheck::MissingStdForwardCheck(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  ForwardFunction(Options.get("ForwardFunction", "::std::forward")) {}
+
+void MissingStdForwardCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "ForwardFunction", ForwardFunction);
+}
+
 } // namespace clang::tidy::cppcoreguidelines
diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.h 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.h
index 5995ad588855e..f833b8031f8af 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.h
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.h
@@ -21,8 +21,7 @@ namespace clang::tidy::cppcoreguidelines {
 /// 
http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/missing-std-forward.html
 class MissingStdForwardCheck : public ClangTidyCheck {
 public:
-  MissingStdForwardCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  MissingStdForwardCheck(StringRef Name, ClangTidyContext *Context);
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
@@ -31,6 +30,10 @@ class MissingStdForwardCheck : public ClangTidyCheck {
   std::optional getCheckTraversalKind() const override {
 return TK_IgnoreUnlessSpelledInSource;
   }
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
+
+private:
+  const StringRef ForwardFunction;
 };
 
 } // namespace clang::tidy::cppcoreguidelines
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index e50d40b76e8c4..fdcc51af8ead7 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -327,6 +327,10 @@ Changes in existing checks
   ` check by fixing
   some false positives involving smart pointers to arrays.
 
+- Improved :doc:`cppcoreguidelines-missing-std-forward
+  ` check by adding a
+  flag to specify the function used for forwarding instead of ``std::forward``.
+
 Removed checks
 ^^
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
index 0c311b59a5d5a..d6cc1e53f768d 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
@@ -35,6 +35,14 @@ Example:
 f(1, 2); // Incorrect - may not invoke the desired qualified function 
operator
   }
 
+Options
+---
+
+.. option:: ForwardFunction
+
+   Specify the function used for forwarding.
+   Default is `::std::forward`.
+
 This check implements `F.19
 

[clang-tools-extra] [clang-tidy] Add flag to specify an alternative to std::move in cppcoreguidelines-rvalue-reference-param-not-moved (PR #138757)

2025-06-30 Thread Dimitrije Dobrota via cfe-commits

https://github.com/DimitrijeDobrota updated 
https://github.com/llvm/llvm-project/pull/138757

>From 28723cca6270be1cb2ebaddc23e47b3a7b38e6a4 Mon Sep 17 00:00:00 2001
From: Dimitrije Dobrota 
Date: Tue, 6 May 2025 22:42:04 +0200
Subject: [PATCH 1/4] Add flag to specify an alternative to std::move

Since std::move is nothing more than a cast, part of STL and not the
language itself, it's easy to provide a custom implementation if one
wishes not to include the entirety of .

Added flag (MoveFunction) provides a way to continue using this
essential check even with the custom implementation of moving.
---
 .../RvalueReferenceParamNotMovedCheck.cpp | 8 +---
 .../cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h | 1 +
 clang-tools-extra/docs/ReleaseNotes.rst   | 5 +
 .../rvalue-reference-param-not-moved.rst  | 5 +
 4 files changed, 16 insertions(+), 3 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
index 8c386d5bc7945..272152644d7dd 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
@@ -42,9 +42,9 @@ void 
RvalueReferenceParamNotMovedCheck::registerMatchers(MatchFinder *Finder) {
   StatementMatcher MoveCallMatcher =
   callExpr(
   argumentCountIs(1),
-  anyOf(callee(functionDecl(hasName("::std::move"))),
+  anyOf(callee(functionDecl(hasName(MoveFunction))),
 callee(unresolvedLookupExpr(hasAnyDeclaration(
-namedDecl(hasUnderlyingDecl(hasName("::std::move"))),
+namedDecl(hasUnderlyingDecl(hasName(MoveFunction))),
   hasArgument(
   0, argumentOf(
  AllowPartialMove,
@@ -122,7 +122,8 @@ 
RvalueReferenceParamNotMovedCheck::RvalueReferenceParamNotMovedCheck(
   AllowPartialMove(Options.get("AllowPartialMove", false)),
   IgnoreUnnamedParams(Options.get("IgnoreUnnamedParams", false)),
   IgnoreNonDeducedTemplateTypes(
-  Options.get("IgnoreNonDeducedTemplateTypes", false)) {}
+  Options.get("IgnoreNonDeducedTemplateTypes", false)),
+  MoveFunction(Options.get("MoveFunction", "::std::move")) {}
 
 void RvalueReferenceParamNotMovedCheck::storeOptions(
 ClangTidyOptions::OptionMap &Opts) {
@@ -130,6 +131,7 @@ void RvalueReferenceParamNotMovedCheck::storeOptions(
   Options.store(Opts, "IgnoreUnnamedParams", IgnoreUnnamedParams);
   Options.store(Opts, "IgnoreNonDeducedTemplateTypes",
 IgnoreNonDeducedTemplateTypes);
+  Options.store(Opts, "MoveFunction", MoveFunction);
 }
 
 } // namespace clang::tidy::cppcoreguidelines
diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h
index d8c3d2bd4ba0e..950c0206745d7 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h
@@ -32,6 +32,7 @@ class RvalueReferenceParamNotMovedCheck : public 
ClangTidyCheck {
   const bool AllowPartialMove;
   const bool IgnoreUnnamedParams;
   const bool IgnoreNonDeducedTemplateTypes;
+  const StringRef MoveFunction;
 };
 
 } // namespace clang::tidy::cppcoreguidelines
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index e50d40b76e8c4..832a2c402a563 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -327,6 +327,11 @@ Changes in existing checks
   ` check by fixing
   some false positives involving smart pointers to arrays.
 
+- Improved :doc:`cppcoreguidelines-rvalue-reference-param-not-moved
+  ` check
+  by adding a flag to specify the function used for moving instead of
+  ``std::move``.
+
 Removed checks
 ^^
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst
index ffa3a9d61e48e..aa2bed9e888a4 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst
@@ -79,6 +79,11 @@ Options
   T other = std::forward(t);
 }
 
+.. option:: MoveFunction
+
+   Specify the function used for moving.
+   Default is `::std::move`.
+
 This check implements `F.18
 
`_
 from the C++ Core Guidelines.

>From 648995c897f09604ec0

[clang-tools-extra] [clang-tidy] Add flag to specify an alternative to std::move in cppcoreguidelines-rvalue-reference-param-not-moved (PR #138757)

2025-06-30 Thread Dimitrije Dobrota via cfe-commits

https://github.com/DimitrijeDobrota updated 
https://github.com/llvm/llvm-project/pull/138757

>From 28723cca6270be1cb2ebaddc23e47b3a7b38e6a4 Mon Sep 17 00:00:00 2001
From: Dimitrije Dobrota 
Date: Tue, 6 May 2025 22:42:04 +0200
Subject: [PATCH 1/4] Add flag to specify an alternative to std::move

Since std::move is nothing more than a cast, part of STL and not the
language itself, it's easy to provide a custom implementation if one
wishes not to include the entirety of .

Added flag (MoveFunction) provides a way to continue using this
essential check even with the custom implementation of moving.
---
 .../RvalueReferenceParamNotMovedCheck.cpp | 8 +---
 .../cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h | 1 +
 clang-tools-extra/docs/ReleaseNotes.rst   | 5 +
 .../rvalue-reference-param-not-moved.rst  | 5 +
 4 files changed, 16 insertions(+), 3 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
index 8c386d5bc7945..272152644d7dd 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
@@ -42,9 +42,9 @@ void 
RvalueReferenceParamNotMovedCheck::registerMatchers(MatchFinder *Finder) {
   StatementMatcher MoveCallMatcher =
   callExpr(
   argumentCountIs(1),
-  anyOf(callee(functionDecl(hasName("::std::move"))),
+  anyOf(callee(functionDecl(hasName(MoveFunction))),
 callee(unresolvedLookupExpr(hasAnyDeclaration(
-namedDecl(hasUnderlyingDecl(hasName("::std::move"))),
+namedDecl(hasUnderlyingDecl(hasName(MoveFunction))),
   hasArgument(
   0, argumentOf(
  AllowPartialMove,
@@ -122,7 +122,8 @@ 
RvalueReferenceParamNotMovedCheck::RvalueReferenceParamNotMovedCheck(
   AllowPartialMove(Options.get("AllowPartialMove", false)),
   IgnoreUnnamedParams(Options.get("IgnoreUnnamedParams", false)),
   IgnoreNonDeducedTemplateTypes(
-  Options.get("IgnoreNonDeducedTemplateTypes", false)) {}
+  Options.get("IgnoreNonDeducedTemplateTypes", false)),
+  MoveFunction(Options.get("MoveFunction", "::std::move")) {}
 
 void RvalueReferenceParamNotMovedCheck::storeOptions(
 ClangTidyOptions::OptionMap &Opts) {
@@ -130,6 +131,7 @@ void RvalueReferenceParamNotMovedCheck::storeOptions(
   Options.store(Opts, "IgnoreUnnamedParams", IgnoreUnnamedParams);
   Options.store(Opts, "IgnoreNonDeducedTemplateTypes",
 IgnoreNonDeducedTemplateTypes);
+  Options.store(Opts, "MoveFunction", MoveFunction);
 }
 
 } // namespace clang::tidy::cppcoreguidelines
diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h
index d8c3d2bd4ba0e..950c0206745d7 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h
@@ -32,6 +32,7 @@ class RvalueReferenceParamNotMovedCheck : public 
ClangTidyCheck {
   const bool AllowPartialMove;
   const bool IgnoreUnnamedParams;
   const bool IgnoreNonDeducedTemplateTypes;
+  const StringRef MoveFunction;
 };
 
 } // namespace clang::tidy::cppcoreguidelines
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index e50d40b76e8c4..832a2c402a563 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -327,6 +327,11 @@ Changes in existing checks
   ` check by fixing
   some false positives involving smart pointers to arrays.
 
+- Improved :doc:`cppcoreguidelines-rvalue-reference-param-not-moved
+  ` check
+  by adding a flag to specify the function used for moving instead of
+  ``std::move``.
+
 Removed checks
 ^^
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst
index ffa3a9d61e48e..aa2bed9e888a4 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst
@@ -79,6 +79,11 @@ Options
   T other = std::forward(t);
 }
 
+.. option:: MoveFunction
+
+   Specify the function used for moving.
+   Default is `::std::move`.
+
 This check implements `F.18
 
`_
 from the C++ Core Guidelines.

>From 648995c897f09604ec0

[clang-tools-extra] [clang-tidy] Add flag to specify an alternative to std::move in cppcoreguidelines-rvalue-reference-param-not-moved (PR #138757)

2025-06-30 Thread Dimitrije Dobrota via cfe-commits

https://github.com/DimitrijeDobrota updated 
https://github.com/llvm/llvm-project/pull/138757

>From 28723cca6270be1cb2ebaddc23e47b3a7b38e6a4 Mon Sep 17 00:00:00 2001
From: Dimitrije Dobrota 
Date: Tue, 6 May 2025 22:42:04 +0200
Subject: [PATCH 1/3] Add flag to specify an alternative to std::move

Since std::move is nothing more than a cast, part of STL and not the
language itself, it's easy to provide a custom implementation if one
wishes not to include the entirety of .

Added flag (MoveFunction) provides a way to continue using this
essential check even with the custom implementation of moving.
---
 .../RvalueReferenceParamNotMovedCheck.cpp | 8 +---
 .../cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h | 1 +
 clang-tools-extra/docs/ReleaseNotes.rst   | 5 +
 .../rvalue-reference-param-not-moved.rst  | 5 +
 4 files changed, 16 insertions(+), 3 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
index 8c386d5bc7945..272152644d7dd 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
@@ -42,9 +42,9 @@ void 
RvalueReferenceParamNotMovedCheck::registerMatchers(MatchFinder *Finder) {
   StatementMatcher MoveCallMatcher =
   callExpr(
   argumentCountIs(1),
-  anyOf(callee(functionDecl(hasName("::std::move"))),
+  anyOf(callee(functionDecl(hasName(MoveFunction))),
 callee(unresolvedLookupExpr(hasAnyDeclaration(
-namedDecl(hasUnderlyingDecl(hasName("::std::move"))),
+namedDecl(hasUnderlyingDecl(hasName(MoveFunction))),
   hasArgument(
   0, argumentOf(
  AllowPartialMove,
@@ -122,7 +122,8 @@ 
RvalueReferenceParamNotMovedCheck::RvalueReferenceParamNotMovedCheck(
   AllowPartialMove(Options.get("AllowPartialMove", false)),
   IgnoreUnnamedParams(Options.get("IgnoreUnnamedParams", false)),
   IgnoreNonDeducedTemplateTypes(
-  Options.get("IgnoreNonDeducedTemplateTypes", false)) {}
+  Options.get("IgnoreNonDeducedTemplateTypes", false)),
+  MoveFunction(Options.get("MoveFunction", "::std::move")) {}
 
 void RvalueReferenceParamNotMovedCheck::storeOptions(
 ClangTidyOptions::OptionMap &Opts) {
@@ -130,6 +131,7 @@ void RvalueReferenceParamNotMovedCheck::storeOptions(
   Options.store(Opts, "IgnoreUnnamedParams", IgnoreUnnamedParams);
   Options.store(Opts, "IgnoreNonDeducedTemplateTypes",
 IgnoreNonDeducedTemplateTypes);
+  Options.store(Opts, "MoveFunction", MoveFunction);
 }
 
 } // namespace clang::tidy::cppcoreguidelines
diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h
index d8c3d2bd4ba0e..950c0206745d7 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h
@@ -32,6 +32,7 @@ class RvalueReferenceParamNotMovedCheck : public 
ClangTidyCheck {
   const bool AllowPartialMove;
   const bool IgnoreUnnamedParams;
   const bool IgnoreNonDeducedTemplateTypes;
+  const StringRef MoveFunction;
 };
 
 } // namespace clang::tidy::cppcoreguidelines
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index e50d40b76e8c4..832a2c402a563 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -327,6 +327,11 @@ Changes in existing checks
   ` check by fixing
   some false positives involving smart pointers to arrays.
 
+- Improved :doc:`cppcoreguidelines-rvalue-reference-param-not-moved
+  ` check
+  by adding a flag to specify the function used for moving instead of
+  ``std::move``.
+
 Removed checks
 ^^
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst
index ffa3a9d61e48e..aa2bed9e888a4 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst
@@ -79,6 +79,11 @@ Options
   T other = std::forward(t);
 }
 
+.. option:: MoveFunction
+
+   Specify the function used for moving.
+   Default is `::std::move`.
+
 This check implements `F.18
 
`_
 from the C++ Core Guidelines.

>From 648995c897f09604ec0

[clang-tools-extra] [clang-tidy] Add flag to specify an alternative to std::forward (PR #138755)

2025-06-30 Thread Dimitrije Dobrota via cfe-commits

https://github.com/DimitrijeDobrota updated 
https://github.com/llvm/llvm-project/pull/138755

>From b6d3a401284022bca317079154764c80b18dcbdd Mon Sep 17 00:00:00 2001
From: Dimitrije Dobrota 
Date: Tue, 6 May 2025 22:18:43 +0200
Subject: [PATCH 1/3] Add flag to specify an alternative to std::forward

Since std::forward is nothing more than a cast, part of STL and not the
language itself, it's easy to provide a custom implementation if one
wishes not to include the entirety of .

Added flag (ForwardFunction) provides a way to continue using this
essential check even with the custom implementation of forwarding.
---
 .../cppcoreguidelines/MissingStdForwardCheck.cpp  | 11 ++-
 .../cppcoreguidelines/MissingStdForwardCheck.h|  7 +--
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 
 .../checks/cppcoreguidelines/missing-std-forward.rst  |  8 
 4 files changed, 27 insertions(+), 3 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
index cf299609e646d..268b51f76a2c3 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
@@ -120,7 +120,7 @@ void MissingStdForwardCheck::registerMatchers(MatchFinder 
*Finder) {
   equalsBoundNode("param"), 
equalsBoundNode("var")),
 CapturedInLambda)),
   callee(unresolvedLookupExpr(hasAnyDeclaration(
-  namedDecl(hasUnderlyingDecl(hasName("::std::forward")),
+  namedDecl(hasUnderlyingDecl(hasName(ForwardFunction)),
 
   unless(anyOf(hasAncestor(typeLoc()),
hasAncestor(expr(hasUnevaluatedContext());
@@ -149,4 +149,13 @@ void MissingStdForwardCheck::check(const 
MatchFinder::MatchResult &Result) {
   << Param;
 }
 
+MissingStdForwardCheck::MissingStdForwardCheck(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  ForwardFunction(Options.get("ForwardFunction", "::std::forward")) {}
+
+void MissingStdForwardCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "ForwardFunction", ForwardFunction);
+}
+
 } // namespace clang::tidy::cppcoreguidelines
diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.h 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.h
index 5995ad588855e..f833b8031f8af 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.h
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.h
@@ -21,8 +21,7 @@ namespace clang::tidy::cppcoreguidelines {
 /// 
http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/missing-std-forward.html
 class MissingStdForwardCheck : public ClangTidyCheck {
 public:
-  MissingStdForwardCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  MissingStdForwardCheck(StringRef Name, ClangTidyContext *Context);
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
@@ -31,6 +30,10 @@ class MissingStdForwardCheck : public ClangTidyCheck {
   std::optional getCheckTraversalKind() const override {
 return TK_IgnoreUnlessSpelledInSource;
   }
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
+
+private:
+  const StringRef ForwardFunction;
 };
 
 } // namespace clang::tidy::cppcoreguidelines
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index e50d40b76e8c4..fdcc51af8ead7 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -327,6 +327,10 @@ Changes in existing checks
   ` check by fixing
   some false positives involving smart pointers to arrays.
 
+- Improved :doc:`cppcoreguidelines-missing-std-forward
+  ` check by adding a
+  flag to specify the function used for forwarding instead of ``std::forward``.
+
 Removed checks
 ^^
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
index 0c311b59a5d5a..d6cc1e53f768d 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
@@ -35,6 +35,14 @@ Example:
 f(1, 2); // Incorrect - may not invoke the desired qualified function 
operator
   }
 
+Options
+---
+
+.. option:: ForwardFunction
+
+   Specify the function used for forwarding.
+   Default is `::std::forward`.
+
 This check implements `F.19