Skip to content
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

[clang-tidy] Add modernize-make-direct check #118120

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hjanuschka
Copy link
Contributor

Adds a new check that converts std::make_* function calls to direct constructor calls using CTAD. Transforms make_optional, make_unique, make_shared and make_pair into their equivalent direct constructor calls, leveraging C++17's class template argument deduction.

Adds a new check that converts std::make_* function calls to direct constructor
calls using CTAD. Transforms make_optional, make_unique, make_shared and make_pair
into their equivalent direct constructor calls, leveraging C++17's class template
argument deduction.
Copy link

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff 056153f36eca184f81969f5cd5c8cd967c935f96 2bcf868d023b5be2f3c88f1d68dd2084b7db4604 --extensions h,cpp -- clang-tools-extra/clang-tidy/modernize/MakeFunctionToDirectCheck.cpp clang-tools-extra/clang-tidy/modernize/MakeFunctionToDirectCheck.h clang-tools-extra/test/clang-tidy/checkers/modernize/make-direct-check.cpp clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
View the diff from clang-format here.
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 45754f0a0b..55a2deeba0 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -124,7 +124,7 @@ public:
         "modernize-use-uncaught-exceptions");
     CheckFactories.registerCheck<UseUsingCheck>("modernize-use-using");
     CheckFactories.registerCheck<MakeFunctionToDirectCheck>(
-    "modernize-make-direct");
+        "modernize-make-direct");
   }
 };
 

@firewave
Copy link

firewave commented Nov 29, 2024

This will conflict with modernize-make-shared and modernize-make-unique.

I also very sure having new in any modern C++ code is very much to be avoided.

Having no insight on the differences of the inner workings - but just based on https://en.cppreference.com/w/cpp/memory/shared_ptr/make_shared#Notes this appears to be something behaving very differently and less optimal/safe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants