[clang-tools-extra] [clang-tidy]detecting conversion directly by `make_unique` and `make_shared` in bugprone-optional-value-conversion (PR #119371)

Piotr Zegar via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 10 08:42:07 PST 2024


================
@@ -12,20 +12,44 @@
 #include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include <array>
 
 using namespace clang::ast_matchers;
+using clang::ast_matchers::internal::Matcher;
 
 namespace clang::tidy::bugprone {
 
 namespace {
 
-AST_MATCHER_P(QualType, hasCleanType, ast_matchers::internal::Matcher<QualType>,
-              InnerMatcher) {
+AST_MATCHER_P(QualType, hasCleanType, Matcher<QualType>, InnerMatcher) {
   return InnerMatcher.matches(
       Node.getNonReferenceType().getUnqualifiedType().getCanonicalType(),
       Finder, Builder);
 }
 
+AST_MATCHER_P2(Expr, constructFrom, Matcher<QualType>, TypeMatcher,
+               Matcher<Expr>, ArgumentMatcher) {
+  std::array<StringRef, 2> NameList{
+      "::std::make_unique",
+      "::std::make_shared",
+  };
+  return expr(anyOf(
----------------
PiotrZSL wrote:

that's not efficient, new matchers will be created constantly.
replace this with simple function that returns this matcher.

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


More information about the cfe-commits mailing list