[PATCH] D43766: [clang-tidy][modernize-make-unique] Checks c++14 flag before using std::make_unique

Arthur O'Dwyer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 1 10:03:28 PST 2018


Quuxplusone added inline comments.


================
Comment at: clang-tidy/modernize/MakeUniqueCheck.cpp:21
+    : MakeSmartPtrCheck(Name, Context, "std::make_unique"),
+      MinimumLanguageVersion(Options.get("MakeUniqueLanguageVersion",
+                                         getDefaultMinimumLanguageVersion())) {}
----------------
aaron.ballman wrote:
> alexfh wrote:
> > ftingaud wrote:
> > > aaron.ballman wrote:
> > > > Why is this is a user-facing option?
> > > > 
> > > > If it needs to be a user-facing option, you also need to implement an override for `storeOptions()` as well.
> > > As the rule was very customizable, I also made the c++ version customizable. But the option is only useful if a user has a custom make_unique that needs c++14 (uses std::make_unique internally) and multiple versions of C++ in their codeline. I agree this is a rather specific usecase. I can remove it and make the code simpler if it is your recommendation.
> > > if a user has a custom make_unique that needs c++14
> > 
> > The only reason to have a custom make_unique that I know is to workaround the absence of std::make_unique in c++11. So this looks like a not very useful case to support.
> Agreed, I'd drop it.
>From the peanut gallery: IIUC, yes, this is not a useful case to support.
If the user has a custom `my::make_unique`, then it is *by definition* usable in C++11. Now, it might still be implemented as a call to `std::make_unique` in C++14... but it will not *require* C++14.
The user's `my::make_unique` will likely require C++11 (not just C++03), but I personally don't think clang-tidy ought to cater to corner cases that involve C++03. I'd just assume that an instruction to "use `my::make_unique`" is appropriate for any translation unit that's being tidied with a custom make_unique.


================
Comment at: test/clang-tidy/modernize-make-unique-cxx14.cpp:10
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use std::make_unique instead
+  // CHECK-FIXES: auto my_ptr = std::make_unique<int>(1);
+  return 0;
----------------
IIUC above, you allow the user to pass in the name of a custom `my::make_unique` function. Could you add a test case for that?


https://reviews.llvm.org/D43766





More information about the cfe-commits mailing list