[clang-tools-extra] [clang-tidy] Add modernize-make-direct check (PR #118120)
Baranov Victor via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 11 13:02:57 PDT 2025
================
@@ -0,0 +1,78 @@
+//===--- MakeFunctionToDirectCheck.cpp - clang-tidy ----------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "MakeFunctionToDirectCheck.h"
+#include "../utils/TransformerClangTidyCheck.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Tooling/Transformer/RangeSelector.h"
+#include "clang/Tooling/Transformer/RewriteRule.h"
+#include "clang/Tooling/Transformer/Stencil.h"
+
+using namespace ::clang::ast_matchers;
+using namespace ::clang::transformer;
+
+namespace clang::tidy::modernize {
+
+namespace {
+
+RewriteRuleWith<std::string>
+makeFunctionToDirectCheckImpl(bool CheckMakePair, bool CheckMakeOptional,
+ bool CheckMakeTuple) {
+ std::vector<RewriteRuleWith<std::string>> Rules;
+
+ // Helper to create a rule for a specific make_* function
+ auto createRule = [](StringRef MakeFunction, StringRef DirectType) {
+ auto WarningMessage = cat("use class template argument deduction (CTAD) "
+ "instead of ",
+ MakeFunction);
+
+ return makeRule(
+ callExpr(callee(functionDecl(hasName(MakeFunction))),
+ unless(hasParent(implicitCastExpr(hasImplicitDestinationType(
+ qualType(hasCanonicalType(qualType(asString("void")))))))))
----------------
vbvictor wrote:
Could you please elaborate why do you need this `unless(hasParen(...))` in your check?
I didn't find tests that will use this behavior, or I couldn't understand what existing test used it:(
https://github.com/llvm/llvm-project/pull/118120
More information about the cfe-commits
mailing list