[clang-tools-extra] [clang-tidy] Add modernize-make-direct check (PR #118120)

Denis Mikhailov via cfe-commits cfe-commits at lists.llvm.org
Sun May 18 06:30:58 PDT 2025


================
@@ -0,0 +1,20 @@
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::modernize {
+
+class MakeFunctionToDirectCheck : public ClangTidyCheck {
----------------
denzor200 wrote:

It can be refactored with `TransformerClangTidyCheck` usage. Sample for only `std::make_pair` function:
```
auto WarningMessage = cat("use class template argument deduction (CTAD) "
                          "instead of std::make_pair");

return makeRule(
  declStmt(hasSingleDecl(varDecl(
      hasType(autoType()), hasTypeLoc(typeLoc().bind("auto_type_loc")),
      hasInitializer(hasDescendant(
          callExpr(callee(functionDecl(hasName("std::make_pair"))))
              .bind("make_call")))))),
  {changeTo(node("auto_type_loc"), cat("std::pair")),
   changeTo(node("make_call"), cat("{", callArgs("make_call"), "}"))},
  WarningMessage);
```

Look at "abseil-cleanup-ctad" check's internals for more details.
I'm not sure is it possible to change `make_unique` and `make_shared` using this method, but they should not  be in this check as it mentioned before(or at least they must be hidded via option).

BTW it will produce better FixItHint:
```
- auto p1 = std::make_pair(1, "test");
+ std::pair p1 = {1, "test"};
```

https://github.com/llvm/llvm-project/pull/118120


More information about the cfe-commits mailing list