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

2018-03-20 Thread Frederic Tingaud via Phabricator via cfe-commits
ftingaud added a comment.

Hi,
Yes please!


https://reviews.llvm.org/D43766



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2018-03-14 Thread Frederic Tingaud via Phabricator via cfe-commits
ftingaud updated this revision to Diff 138398.
ftingaud added a comment.

Clean code along code review recommendations.


https://reviews.llvm.org/D43766

Files:
  clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tidy/modernize/MakeSmartPtrCheck.h
  clang-tidy/modernize/MakeUniqueCheck.cpp
  clang-tidy/modernize/MakeUniqueCheck.h
  test/clang-tidy/modernize-make-unique-cxx11.cpp
  test/clang-tidy/modernize-make-unique-cxx14.cpp
  test/clang-tidy/modernize-make-unique-macros.cpp
  test/clang-tidy/modernize-make-unique.cpp

Index: test/clang-tidy/modernize-make-unique.cpp
===
--- test/clang-tidy/modernize-make-unique.cpp
+++ test/clang-tidy/modernize-make-unique.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++11 \
+// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++14 \
 // RUN:   -I%S/Inputs/modernize-smart-ptr
 
 #include "unique_ptr.h"
Index: test/clang-tidy/modernize-make-unique-macros.cpp
===
--- test/clang-tidy/modernize-make-unique-macros.cpp
+++ test/clang-tidy/modernize-make-unique-macros.cpp
@@ -1,6 +1,6 @@
 // RUN: %check_clang_tidy %s modernize-make-unique %t -- \
 // RUN:   -config="{CheckOptions: [{key: modernize-make-unique.IgnoreMacros, value: 0}]}" \
-// RUN:   -- -std=c++11  -I%S/Inputs/modernize-smart-ptr
+// RUN:   -- -std=c++14  -I%S/Inputs/modernize-smart-ptr
 
 #include "unique_ptr.h"
 
Index: test/clang-tidy/modernize-make-unique-cxx14.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-make-unique-cxx14.cpp
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++14 \
+// RUN:   -I%S/Inputs/modernize-smart-ptr
+
+#include "unique_ptr.h"
+// CHECK-FIXES: #include 
+
+void f() {
+  auto my_ptr = std::unique_ptr(new int(1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use std::make_unique instead
+  // CHECK-FIXES: auto my_ptr = std::make_unique(1);
+}
Index: test/clang-tidy/modernize-make-unique-cxx11.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-make-unique-cxx11.cpp
@@ -0,0 +1,10 @@
+// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++11 \
+// RUN:   -I%S/Inputs/modernize-smart-ptr
+
+#include "unique_ptr.h"
+// CHECK-FIXES: #include "unique_ptr.h"
+
+void f() {
+  auto my_ptr = std::unique_ptr(new int(1));
+  // CHECK-FIXES: auto my_ptr = std::unique_ptr(new int(1));
+}
Index: clang-tidy/modernize/MakeUniqueCheck.h
===
--- clang-tidy/modernize/MakeUniqueCheck.h
+++ clang-tidy/modernize/MakeUniqueCheck.h
@@ -31,6 +31,11 @@
 
 protected:
   SmartPtrTypeMatcher getSmartPointerTypeMatcher() const override;
+
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override;
+
+private:
+  const bool RequireCPlusPlus14;
 };
 
 } // namespace modernize
Index: clang-tidy/modernize/MakeUniqueCheck.cpp
===
--- clang-tidy/modernize/MakeUniqueCheck.cpp
+++ clang-tidy/modernize/MakeUniqueCheck.cpp
@@ -17,7 +17,8 @@
 
 MakeUniqueCheck::MakeUniqueCheck(StringRef Name,
  clang::tidy::ClangTidyContext *Context)
-: MakeSmartPtrCheck(Name, Context, "std::make_unique") {}
+: MakeSmartPtrCheck(Name, Context, "std::make_unique"),
+  RequireCPlusPlus14(Options.get("MakeSmartPtrFunction", "").empty()) {}
 
 MakeUniqueCheck::SmartPtrTypeMatcher
 MakeUniqueCheck::getSmartPointerTypeMatcher() const {
@@ -36,6 +37,11 @@
 equalsBoundNode(PointerType;
 }
 
+bool MakeUniqueCheck::isLanguageVersionSupported(
+const LangOptions &LangOpts) const {
+  return RequireCPlusPlus14 ? LangOpts.CPlusPlus14 : LangOpts.CPlusPlus11;
+}
+
 } // namespace modernize
 } // namespace tidy
 } // namespace clang
Index: clang-tidy/modernize/MakeSmartPtrCheck.h
===
--- clang-tidy/modernize/MakeSmartPtrCheck.h
+++ clang-tidy/modernize/MakeSmartPtrCheck.h
@@ -40,6 +40,9 @@
   /// in this class.
   virtual SmartPtrTypeMatcher getSmartPointerTypeMatcher() const = 0;
 
+  /// Returns whether the C++ version is compatible with current check.
+  virtual bool isLanguageVersionSupported(const LangOptions &LangOpts) const;
+
   static const char PointerType[];
   static const char ConstructorCall[];
   static const char ResetCall[];
Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp
===
--- clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -61,16 +61,21 @@
   Options.store(Opts, "IgnoreMacros", IgnoreMacros);
 }
 
+bool MakeSmartPtrCheck::isLanguageVersionSupported(
+const 

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

2018-03-14 Thread Frederic Tingaud via Phabricator via cfe-commits
ftingaud added a comment.

Hi,

I think all requested modifications were done.

Regards,

Fred


https://reviews.llvm.org/D43766



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2018-03-01 Thread Frederic Tingaud via Phabricator via cfe-commits
ftingaud added inline comments.



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(1);
+  return 0;

Quuxplusone wrote:
> 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?
It is tested by modernize-make-unique-header.cpp and the patch doesn't change 
the feature.


https://reviews.llvm.org/D43766



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2018-03-01 Thread Frederic Tingaud via Phabricator via cfe-commits
ftingaud updated this revision to Diff 136575.
ftingaud added a comment.

Remove customizable c++ version that added no real value.


https://reviews.llvm.org/D43766

Files:
  clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tidy/modernize/MakeSmartPtrCheck.h
  clang-tidy/modernize/MakeUniqueCheck.cpp
  clang-tidy/modernize/MakeUniqueCheck.h
  test/clang-tidy/modernize-make-unique-cxx11.cpp
  test/clang-tidy/modernize-make-unique-cxx14.cpp
  test/clang-tidy/modernize-make-unique-macros.cpp
  test/clang-tidy/modernize-make-unique.cpp

Index: test/clang-tidy/modernize-make-unique.cpp
===
--- test/clang-tidy/modernize-make-unique.cpp
+++ test/clang-tidy/modernize-make-unique.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++11 \
+// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++14 \
 // RUN:   -I%S/Inputs/modernize-smart-ptr
 
 #include "unique_ptr.h"
Index: test/clang-tidy/modernize-make-unique-macros.cpp
===
--- test/clang-tidy/modernize-make-unique-macros.cpp
+++ test/clang-tidy/modernize-make-unique-macros.cpp
@@ -1,6 +1,6 @@
 // RUN: %check_clang_tidy %s modernize-make-unique %t -- \
 // RUN:   -config="{CheckOptions: [{key: modernize-make-unique.IgnoreMacros, value: 0}]}" \
-// RUN:   -- -std=c++11  -I%S/Inputs/modernize-smart-ptr
+// RUN:   -- -std=c++14  -I%S/Inputs/modernize-smart-ptr
 
 #include "unique_ptr.h"
 
Index: test/clang-tidy/modernize-make-unique-cxx14.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-make-unique-cxx14.cpp
@@ -0,0 +1,12 @@
+// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++14 \
+// RUN:   -I%S/Inputs/modernize-smart-ptr
+
+#include "unique_ptr.h"
+// CHECK-FIXES: #include 
+
+int main() {
+  auto my_ptr = std::unique_ptr(new int(1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use std::make_unique instead
+  // CHECK-FIXES: auto my_ptr = std::make_unique(1);
+  return 0;
+}
Index: test/clang-tidy/modernize-make-unique-cxx11.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-make-unique-cxx11.cpp
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++11 \
+// RUN:   -I%S/Inputs/modernize-smart-ptr
+
+#include "unique_ptr.h"
+// CHECK-FIXES: #include "unique_ptr.h"
+
+int main() {
+  auto my_ptr = std::unique_ptr(new int(1));
+  // CHECK-FIXES: auto my_ptr = std::unique_ptr(new int(1));
+  return 0;
+}
Index: clang-tidy/modernize/MakeUniqueCheck.h
===
--- clang-tidy/modernize/MakeUniqueCheck.h
+++ clang-tidy/modernize/MakeUniqueCheck.h
@@ -31,6 +31,11 @@
 
 protected:
   SmartPtrTypeMatcher getSmartPointerTypeMatcher() const override;
+
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override;
+
+private:
+  const bool RequireCPlusPlus14;
 };
 
 } // namespace modernize
Index: clang-tidy/modernize/MakeUniqueCheck.cpp
===
--- clang-tidy/modernize/MakeUniqueCheck.cpp
+++ clang-tidy/modernize/MakeUniqueCheck.cpp
@@ -17,7 +17,8 @@
 
 MakeUniqueCheck::MakeUniqueCheck(StringRef Name,
  clang::tidy::ClangTidyContext *Context)
-: MakeSmartPtrCheck(Name, Context, "std::make_unique") {}
+: MakeSmartPtrCheck(Name, Context, "std::make_unique"),
+  RequireCPlusPlus14(Options.get("MakeSmartPtrFunction", "").empty()) {}
 
 MakeUniqueCheck::SmartPtrTypeMatcher
 MakeUniqueCheck::getSmartPointerTypeMatcher() const {
@@ -36,6 +37,13 @@
 equalsBoundNode(PointerType;
 }
 
+bool MakeUniqueCheck::isLanguageVersionSupported(
+const LangOptions &LangOpts) const {
+  if (RequireCPlusPlus14)
+return LangOpts.CPlusPlus14;
+  return LangOpts.CPlusPlus11;
+}
+
 } // namespace modernize
 } // namespace tidy
 } // namespace clang
Index: clang-tidy/modernize/MakeSmartPtrCheck.h
===
--- clang-tidy/modernize/MakeSmartPtrCheck.h
+++ clang-tidy/modernize/MakeSmartPtrCheck.h
@@ -40,6 +40,9 @@
   /// in this class.
   virtual SmartPtrTypeMatcher getSmartPointerTypeMatcher() const = 0;
 
+  /// Returns whether the C++ version is compatible with current check.
+  virtual bool isLanguageVersionSupported(const LangOptions &LangOpts) const;
+
   static const char PointerType[];
   static const char ConstructorCall[];
   static const char ResetCall[];
Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp
===
--- clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -61,16 +61,21 @@
   Options.store(Opts, "IgnoreMacros", IgnoreMacros);
 }
 
+bool

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

2018-03-01 Thread Frederic Tingaud via Phabricator via cfe-commits
ftingaud 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:
> 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.



Comment at: clang-tidy/modernize/MakeUniqueCheck.cpp:25
+const std::string MakeUniqueCheck::getDefaultMinimumLanguageVersion() const {
+  return Options.get("MakeSmartPtrFunction", "").empty() ? "c++14" : "c++11";
+}

aaron.ballman wrote:
> What is this option? Why is this returning a string literal rather than 
> something less error-prone like an enumeration?
I made the MinimumLanguageVersion a string literal to make it customizable by 
the user. If we remove the customization, we can switch to an enum or a boolean.


https://reviews.llvm.org/D43766



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2018-02-28 Thread Frederic Tingaud via Phabricator via cfe-commits
ftingaud updated this revision to Diff 136286.
ftingaud added a comment.

Correct case of custom make_unique functions that should still work in c++11.


https://reviews.llvm.org/D43766

Files:
  clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tidy/modernize/MakeSmartPtrCheck.h
  clang-tidy/modernize/MakeUniqueCheck.cpp
  clang-tidy/modernize/MakeUniqueCheck.h
  test/clang-tidy/modernize-make-unique-cxx11.cpp
  test/clang-tidy/modernize-make-unique-cxx14.cpp
  test/clang-tidy/modernize-make-unique-macros.cpp
  test/clang-tidy/modernize-make-unique.cpp

Index: test/clang-tidy/modernize-make-unique.cpp
===
--- test/clang-tidy/modernize-make-unique.cpp
+++ test/clang-tidy/modernize-make-unique.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++11 \
+// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++14 \
 // RUN:   -I%S/Inputs/modernize-smart-ptr
 
 #include "unique_ptr.h"
Index: test/clang-tidy/modernize-make-unique-macros.cpp
===
--- test/clang-tidy/modernize-make-unique-macros.cpp
+++ test/clang-tidy/modernize-make-unique-macros.cpp
@@ -1,6 +1,6 @@
 // RUN: %check_clang_tidy %s modernize-make-unique %t -- \
 // RUN:   -config="{CheckOptions: [{key: modernize-make-unique.IgnoreMacros, value: 0}]}" \
-// RUN:   -- -std=c++11  -I%S/Inputs/modernize-smart-ptr
+// RUN:   -- -std=c++14  -I%S/Inputs/modernize-smart-ptr
 
 #include "unique_ptr.h"
 
Index: test/clang-tidy/modernize-make-unique-cxx14.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-make-unique-cxx14.cpp
@@ -0,0 +1,12 @@
+// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++14 \
+// RUN:   -I%S/Inputs/modernize-smart-ptr
+
+#include "unique_ptr.h"
+// CHECK-FIXES: #include 
+
+int main() {
+  auto my_ptr = std::unique_ptr(new int(1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use std::make_unique instead
+  // CHECK-FIXES: auto my_ptr = std::make_unique(1);
+  return 0;
+}
Index: test/clang-tidy/modernize-make-unique-cxx11.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-make-unique-cxx11.cpp
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++11 \
+// RUN:   -I%S/Inputs/modernize-smart-ptr
+
+#include "unique_ptr.h"
+// CHECK-FIXES: #include "unique_ptr.h"
+
+int main() {
+  auto my_ptr = std::unique_ptr(new int(1));
+  // CHECK-FIXES: auto my_ptr = std::unique_ptr(new int(1));
+  return 0;
+}
Index: clang-tidy/modernize/MakeUniqueCheck.h
===
--- clang-tidy/modernize/MakeUniqueCheck.h
+++ clang-tidy/modernize/MakeUniqueCheck.h
@@ -31,6 +31,13 @@
 
 protected:
   SmartPtrTypeMatcher getSmartPointerTypeMatcher() const override;
+
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override;
+
+private:
+  const std::string MinimumLanguageVersion;
+
+  const std::string getDefaultMinimumLanguageVersion() const;
 };
 
 } // namespace modernize
Index: clang-tidy/modernize/MakeUniqueCheck.cpp
===
--- clang-tidy/modernize/MakeUniqueCheck.cpp
+++ clang-tidy/modernize/MakeUniqueCheck.cpp
@@ -17,7 +17,13 @@
 
 MakeUniqueCheck::MakeUniqueCheck(StringRef Name,
  clang::tidy::ClangTidyContext *Context)
-: MakeSmartPtrCheck(Name, Context, "std::make_unique") {}
+: MakeSmartPtrCheck(Name, Context, "std::make_unique"),
+  MinimumLanguageVersion(Options.get("MakeUniqueLanguageVersion",
+ getDefaultMinimumLanguageVersion())) {}
+
+const std::string MakeUniqueCheck::getDefaultMinimumLanguageVersion() const {
+  return Options.get("MakeSmartPtrFunction", "").empty() ? "c++14" : "c++11";
+}
 
 MakeUniqueCheck::SmartPtrTypeMatcher
 MakeUniqueCheck::getSmartPointerTypeMatcher() const {
@@ -36,6 +42,13 @@
 equalsBoundNode(PointerType;
 }
 
+bool MakeUniqueCheck::isLanguageVersionSupported(
+const LangOptions &LangOpts) const {
+  if (MinimumLanguageVersion == "c++14")
+return LangOpts.CPlusPlus14;
+  return LangOpts.CPlusPlus11;
+}
+
 } // namespace modernize
 } // namespace tidy
 } // namespace clang
Index: clang-tidy/modernize/MakeSmartPtrCheck.h
===
--- clang-tidy/modernize/MakeSmartPtrCheck.h
+++ clang-tidy/modernize/MakeSmartPtrCheck.h
@@ -40,6 +40,9 @@
   /// in this class.
   virtual SmartPtrTypeMatcher getSmartPointerTypeMatcher() const = 0;
 
+  /// Returns whether the C++ version is compatible with current check.
+  virtual bool isLanguageVersionSupported(const LangOptions &LangOpts) const;
+
   static const char PointerType[];
   static const char

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

2018-02-28 Thread Frederic Tingaud via Phabricator via cfe-commits
ftingaud updated this revision to Diff 136245.
ftingaud added a comment.

Apply clang-format on changelist.


https://reviews.llvm.org/D43766

Files:
  clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tidy/modernize/MakeSmartPtrCheck.h
  clang-tidy/modernize/MakeUniqueCheck.cpp
  clang-tidy/modernize/MakeUniqueCheck.h
  test/clang-tidy/modernize-make-unique-cxx11.cpp
  test/clang-tidy/modernize-make-unique-cxx14.cpp
  test/clang-tidy/modernize-make-unique-header.cpp
  test/clang-tidy/modernize-make-unique-macros.cpp
  test/clang-tidy/modernize-make-unique.cpp

Index: test/clang-tidy/modernize-make-unique.cpp
===
--- test/clang-tidy/modernize-make-unique.cpp
+++ test/clang-tidy/modernize-make-unique.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++11 \
+// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++14 \
 // RUN:   -I%S/Inputs/modernize-smart-ptr
 
 #include "unique_ptr.h"
Index: test/clang-tidy/modernize-make-unique-macros.cpp
===
--- test/clang-tidy/modernize-make-unique-macros.cpp
+++ test/clang-tidy/modernize-make-unique-macros.cpp
@@ -1,6 +1,6 @@
 // RUN: %check_clang_tidy %s modernize-make-unique %t -- \
 // RUN:   -config="{CheckOptions: [{key: modernize-make-unique.IgnoreMacros, value: 0}]}" \
-// RUN:   -- -std=c++11  -I%S/Inputs/modernize-smart-ptr
+// RUN:   -- -std=c++14  -I%S/Inputs/modernize-smart-ptr
 
 #include "unique_ptr.h"
 
Index: test/clang-tidy/modernize-make-unique-header.cpp
===
--- test/clang-tidy/modernize-make-unique-header.cpp
+++ test/clang-tidy/modernize-make-unique-header.cpp
@@ -5,7 +5,7 @@
 // RUN:  {key: modernize-make-unique.MakeSmartPtrFunctionHeader, \
 // RUN:   value: 'make_unique_util.h'} \
 // RUN: ]}" \
-// RUN:   -- -std=c++11 -I%S/Inputs/modernize-smart-ptr
+// RUN:   -- -std=c++14 -I%S/Inputs/modernize-smart-ptr
 
 #include "unique_ptr.h"
 // CHECK-FIXES: #include "make_unique_util.h"
Index: test/clang-tidy/modernize-make-unique-cxx14.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-make-unique-cxx14.cpp
@@ -0,0 +1,12 @@
+// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++14 \
+// RUN:   -I%S/Inputs/modernize-smart-ptr
+
+#include "unique_ptr.h"
+// CHECK-FIXES: #include 
+
+int main() {
+  auto my_ptr = std::unique_ptr(new int(1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use std::make_unique instead
+  // CHECK-FIXES: auto my_ptr = std::make_unique(1);
+  return 0;
+}
Index: test/clang-tidy/modernize-make-unique-cxx11.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-make-unique-cxx11.cpp
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++11 \
+// RUN:   -I%S/Inputs/modernize-smart-ptr
+
+#include "unique_ptr.h"
+// CHECK-FIXES-NOT: #include 
+
+int main() {
+  auto my_ptr = std::unique_ptr(new int(1));
+  // CHECK-FIXES-NOT: auto my_ptr = std::make_unique(1);
+  return 0;
+}
Index: clang-tidy/modernize/MakeUniqueCheck.h
===
--- clang-tidy/modernize/MakeUniqueCheck.h
+++ clang-tidy/modernize/MakeUniqueCheck.h
@@ -31,6 +31,8 @@
 
 protected:
   SmartPtrTypeMatcher getSmartPointerTypeMatcher() const override;
+
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override;
 };
 
 } // namespace modernize
Index: clang-tidy/modernize/MakeUniqueCheck.cpp
===
--- clang-tidy/modernize/MakeUniqueCheck.cpp
+++ clang-tidy/modernize/MakeUniqueCheck.cpp
@@ -36,6 +36,11 @@
 equalsBoundNode(PointerType;
 }
 
+bool MakeUniqueCheck::isLanguageVersionSupported(
+const LangOptions &LangOpts) const {
+  return LangOpts.CPlusPlus14;
+}
+
 } // namespace modernize
 } // namespace tidy
 } // namespace clang
Index: clang-tidy/modernize/MakeSmartPtrCheck.h
===
--- clang-tidy/modernize/MakeSmartPtrCheck.h
+++ clang-tidy/modernize/MakeSmartPtrCheck.h
@@ -40,6 +40,9 @@
   /// in this class.
   virtual SmartPtrTypeMatcher getSmartPointerTypeMatcher() const = 0;
 
+  /// Returns whether the C++ version is compatible with current check.
+  virtual bool isLanguageVersionSupported(const LangOptions &LangOpts) const;
+
   static const char PointerType[];
   static const char ConstructorCall[];
   static const char ResetCall[];
Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp
===
--- clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -61,16 +61,21 @@
   Options.store(Opts, "Ignor

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

2018-02-27 Thread Frederic Tingaud via Phabricator via cfe-commits
ftingaud updated this revision to Diff 136094.
ftingaud added a comment.

Remove two useless namespaces


https://reviews.llvm.org/D43766

Files:
  clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tidy/modernize/MakeSmartPtrCheck.h
  clang-tidy/modernize/MakeUniqueCheck.cpp
  clang-tidy/modernize/MakeUniqueCheck.h
  test/clang-tidy/modernize-make-unique-cxx11.cpp
  test/clang-tidy/modernize-make-unique-cxx14.cpp
  test/clang-tidy/modernize-make-unique-header.cpp
  test/clang-tidy/modernize-make-unique-macros.cpp
  test/clang-tidy/modernize-make-unique.cpp

Index: test/clang-tidy/modernize-make-unique.cpp
===
--- test/clang-tidy/modernize-make-unique.cpp
+++ test/clang-tidy/modernize-make-unique.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++11 \
+// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++14 \
 // RUN:   -I%S/Inputs/modernize-smart-ptr
 
 #include "unique_ptr.h"
Index: test/clang-tidy/modernize-make-unique-macros.cpp
===
--- test/clang-tidy/modernize-make-unique-macros.cpp
+++ test/clang-tidy/modernize-make-unique-macros.cpp
@@ -1,6 +1,6 @@
 // RUN: %check_clang_tidy %s modernize-make-unique %t -- \
 // RUN:   -config="{CheckOptions: [{key: modernize-make-unique.IgnoreMacros, value: 0}]}" \
-// RUN:   -- -std=c++11  -I%S/Inputs/modernize-smart-ptr
+// RUN:   -- -std=c++14  -I%S/Inputs/modernize-smart-ptr
 
 #include "unique_ptr.h"
 
Index: test/clang-tidy/modernize-make-unique-header.cpp
===
--- test/clang-tidy/modernize-make-unique-header.cpp
+++ test/clang-tidy/modernize-make-unique-header.cpp
@@ -5,7 +5,7 @@
 // RUN:  {key: modernize-make-unique.MakeSmartPtrFunctionHeader, \
 // RUN:   value: 'make_unique_util.h'} \
 // RUN: ]}" \
-// RUN:   -- -std=c++11 -I%S/Inputs/modernize-smart-ptr
+// RUN:   -- -std=c++14 -I%S/Inputs/modernize-smart-ptr
 
 #include "unique_ptr.h"
 // CHECK-FIXES: #include "make_unique_util.h"
Index: test/clang-tidy/modernize-make-unique-cxx14.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-make-unique-cxx14.cpp
@@ -0,0 +1,12 @@
+// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++14 \
+// RUN:   -I%S/Inputs/modernize-smart-ptr
+
+#include "unique_ptr.h"
+// CHECK-FIXES: #include 
+
+int main() {
+  auto my_ptr = std::unique_ptr(new int(1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use std::make_unique instead
+  // CHECK-FIXES: auto my_ptr = std::make_unique(1);
+  return 0;
+}
Index: test/clang-tidy/modernize-make-unique-cxx11.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-make-unique-cxx11.cpp
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++11 \
+// RUN:   -I%S/Inputs/modernize-smart-ptr
+
+#include "unique_ptr.h"
+// CHECK-FIXES-NOT: #include 
+
+int main() {
+  auto my_ptr = std::unique_ptr(new int(1));
+  // CHECK-FIXES-NOT: auto my_ptr = std::make_unique(1);
+  return 0;
+}
Index: clang-tidy/modernize/MakeUniqueCheck.h
===
--- clang-tidy/modernize/MakeUniqueCheck.h
+++ clang-tidy/modernize/MakeUniqueCheck.h
@@ -31,6 +31,8 @@
 
 protected:
   SmartPtrTypeMatcher getSmartPointerTypeMatcher() const override;
+
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override;
 };
 
 } // namespace modernize
Index: clang-tidy/modernize/MakeUniqueCheck.cpp
===
--- clang-tidy/modernize/MakeUniqueCheck.cpp
+++ clang-tidy/modernize/MakeUniqueCheck.cpp
@@ -36,6 +36,10 @@
 equalsBoundNode(PointerType;
 }
 
+bool MakeUniqueCheck::isLanguageVersionSupported(const LangOptions &LangOpts) const {
+   return LangOpts.CPlusPlus14;
+}
+
 } // namespace modernize
 } // namespace tidy
 } // namespace clang
Index: clang-tidy/modernize/MakeSmartPtrCheck.h
===
--- clang-tidy/modernize/MakeSmartPtrCheck.h
+++ clang-tidy/modernize/MakeSmartPtrCheck.h
@@ -40,6 +40,9 @@
   /// in this class.
   virtual SmartPtrTypeMatcher getSmartPointerTypeMatcher() const = 0;
 
+  /// Returns whether the C++ version is compatible with current check.
+  virtual bool isLanguageVersionSupported(const LangOptions &LangOpts) const;
+
   static const char PointerType[];
   static const char ConstructorCall[];
   static const char ResetCall[];
Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp
===
--- clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -61,16 +61,21 @@
   Options.store(Opts, "IgnoreMacros",

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

2018-02-27 Thread Frederic Tingaud via Phabricator via cfe-commits
ftingaud updated this revision to Diff 136093.
ftingaud added a comment.

Update with tests and cleaning as indicated by reviewers.


https://reviews.llvm.org/D43766

Files:
  clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tidy/modernize/MakeSmartPtrCheck.h
  clang-tidy/modernize/MakeUniqueCheck.cpp
  clang-tidy/modernize/MakeUniqueCheck.h
  test/clang-tidy/modernize-make-unique-cxx11.cpp
  test/clang-tidy/modernize-make-unique-cxx14.cpp
  test/clang-tidy/modernize-make-unique-header.cpp
  test/clang-tidy/modernize-make-unique-macros.cpp
  test/clang-tidy/modernize-make-unique.cpp

Index: test/clang-tidy/modernize-make-unique.cpp
===
--- test/clang-tidy/modernize-make-unique.cpp
+++ test/clang-tidy/modernize-make-unique.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++11 \
+// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++14 \
 // RUN:   -I%S/Inputs/modernize-smart-ptr
 
 #include "unique_ptr.h"
Index: test/clang-tidy/modernize-make-unique-macros.cpp
===
--- test/clang-tidy/modernize-make-unique-macros.cpp
+++ test/clang-tidy/modernize-make-unique-macros.cpp
@@ -1,6 +1,6 @@
 // RUN: %check_clang_tidy %s modernize-make-unique %t -- \
 // RUN:   -config="{CheckOptions: [{key: modernize-make-unique.IgnoreMacros, value: 0}]}" \
-// RUN:   -- -std=c++11  -I%S/Inputs/modernize-smart-ptr
+// RUN:   -- -std=c++14  -I%S/Inputs/modernize-smart-ptr
 
 #include "unique_ptr.h"
 
Index: test/clang-tidy/modernize-make-unique-header.cpp
===
--- test/clang-tidy/modernize-make-unique-header.cpp
+++ test/clang-tidy/modernize-make-unique-header.cpp
@@ -5,7 +5,7 @@
 // RUN:  {key: modernize-make-unique.MakeSmartPtrFunctionHeader, \
 // RUN:   value: 'make_unique_util.h'} \
 // RUN: ]}" \
-// RUN:   -- -std=c++11 -I%S/Inputs/modernize-smart-ptr
+// RUN:   -- -std=c++14 -I%S/Inputs/modernize-smart-ptr
 
 #include "unique_ptr.h"
 // CHECK-FIXES: #include "make_unique_util.h"
Index: test/clang-tidy/modernize-make-unique-cxx14.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-make-unique-cxx14.cpp
@@ -0,0 +1,12 @@
+// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++14 \
+// RUN:   -I%S/Inputs/modernize-smart-ptr
+
+#include "unique_ptr.h"
+// CHECK-FIXES: #include 
+
+int main() {
+  auto my_ptr = std::unique_ptr(new int(1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use std::make_unique instead
+  // CHECK-FIXES: auto my_ptr = std::make_unique(1);
+  return 0;
+}
Index: test/clang-tidy/modernize-make-unique-cxx11.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-make-unique-cxx11.cpp
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++11 \
+// RUN:   -I%S/Inputs/modernize-smart-ptr
+
+#include "unique_ptr.h"
+// CHECK-FIXES-NOT: #include 
+
+int main() {
+  auto my_ptr = std::unique_ptr(new int(1));
+  // CHECK-FIXES-NOT: auto my_ptr = std::make_unique(1);
+  return 0;
+}
Index: clang-tidy/modernize/MakeUniqueCheck.h
===
--- clang-tidy/modernize/MakeUniqueCheck.h
+++ clang-tidy/modernize/MakeUniqueCheck.h
@@ -31,6 +31,8 @@
 
 protected:
   SmartPtrTypeMatcher getSmartPointerTypeMatcher() const override;
+
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override;
 };
 
 } // namespace modernize
Index: clang-tidy/modernize/MakeUniqueCheck.cpp
===
--- clang-tidy/modernize/MakeUniqueCheck.cpp
+++ clang-tidy/modernize/MakeUniqueCheck.cpp
@@ -36,6 +36,10 @@
 equalsBoundNode(PointerType;
 }
 
+bool MakeUniqueCheck::isLanguageVersionSupported(const LangOptions &LangOpts) const {
+   return LangOpts.CPlusPlus14;
+}
+
 } // namespace modernize
 } // namespace tidy
 } // namespace clang
Index: clang-tidy/modernize/MakeSmartPtrCheck.h
===
--- clang-tidy/modernize/MakeSmartPtrCheck.h
+++ clang-tidy/modernize/MakeSmartPtrCheck.h
@@ -40,6 +40,9 @@
   /// in this class.
   virtual SmartPtrTypeMatcher getSmartPointerTypeMatcher() const = 0;
 
+  /// Returns whether the C++ version is compatible with current check.
+  virtual bool isLanguageVersionSupported(const clang::LangOptions &LangOpts) const;
+
   static const char PointerType[];
   static const char ConstructorCall[];
   static const char ResetCall[];
Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp
===
--- clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -61,16 +61,21 @@
   

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

2018-02-26 Thread Frederic Tingaud via Phabricator via cfe-commits
ftingaud created this revision.
ftingaud added reviewers: hokein, Prazek.
ftingaud added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, xazax.hun.

For a c++11 code, the clang-tidy rule "modernize-make-unique" should return 
immediately, as std::make_unique is not supported.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43766

Files:
  clang-tidy/modernize/MakeSharedCheck.cpp
  clang-tidy/modernize/MakeSharedCheck.h
  clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tidy/modernize/MakeSmartPtrCheck.h
  clang-tidy/modernize/MakeUniqueCheck.cpp
  clang-tidy/modernize/MakeUniqueCheck.h


Index: clang-tidy/modernize/MakeUniqueCheck.h
===
--- clang-tidy/modernize/MakeUniqueCheck.h
+++ clang-tidy/modernize/MakeUniqueCheck.h
@@ -31,6 +31,8 @@
 
 protected:
   SmartPtrTypeMatcher getSmartPointerTypeMatcher() const override;
+
+  bool isVersionSupported(const clang::LangOptions &LangOpts) const override;
 };
 
 } // namespace modernize
Index: clang-tidy/modernize/MakeUniqueCheck.cpp
===
--- clang-tidy/modernize/MakeUniqueCheck.cpp
+++ clang-tidy/modernize/MakeUniqueCheck.cpp
@@ -36,6 +36,10 @@
 
equalsBoundNode(PointerType;
 }
 
+bool MakeUniqueCheck::isVersionSupported(const clang::LangOptions &LangOpts) 
const {
+   return LangOpts.CPlusPlus14;
+}
+
 } // namespace modernize
 } // namespace tidy
 } // namespace clang
Index: clang-tidy/modernize/MakeSmartPtrCheck.h
===
--- clang-tidy/modernize/MakeSmartPtrCheck.h
+++ clang-tidy/modernize/MakeSmartPtrCheck.h
@@ -40,6 +40,9 @@
   /// in this class.
   virtual SmartPtrTypeMatcher getSmartPointerTypeMatcher() const = 0;
 
+  /// Returns whether the C++ version is compatible with current check.
+  virtual bool isVersionSupported(const clang::LangOptions &LangOpts) const = 
0;
+
   static const char PointerType[];
   static const char ConstructorCall[];
   static const char ResetCall[];
Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp
===
--- clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -62,15 +62,15 @@
 }
 
 void MakeSmartPtrCheck::registerPPCallbacks(CompilerInstance &Compiler) {
-  if (getLangOpts().CPlusPlus11) {
+  if (isVersionSupported(getLangOpts())) {
 Inserter.reset(new utils::IncludeInserter(
 Compiler.getSourceManager(), Compiler.getLangOpts(), IncludeStyle));
 Compiler.getPreprocessor().addPPCallbacks(Inserter->CreatePPCallbacks());
   }
 }
 
 void MakeSmartPtrCheck::registerMatchers(ast_matchers::MatchFinder *Finder) {
-  if (!getLangOpts().CPlusPlus11)
+  if (!isVersionSupported(getLangOpts()))
 return;
 
   // Calling make_smart_ptr from within a member function of a type with a
Index: clang-tidy/modernize/MakeSharedCheck.h
===
--- clang-tidy/modernize/MakeSharedCheck.h
+++ clang-tidy/modernize/MakeSharedCheck.h
@@ -34,6 +34,8 @@
 
 protected:
   SmartPtrTypeMatcher getSmartPointerTypeMatcher() const override;
+
+  bool isVersionSupported(const clang::LangOptions &LangOpts) const override;
 };
 
 } // namespace modernize
Index: clang-tidy/modernize/MakeSharedCheck.cpp
===
--- clang-tidy/modernize/MakeSharedCheck.cpp
+++ clang-tidy/modernize/MakeSharedCheck.cpp
@@ -27,6 +27,10 @@
  qualType().bind(PointerType);
 }
 
+bool MakeSharedCheck::isVersionSupported(const clang::LangOptions &LangOpts) 
const {
+   return LangOpts.CPlusPlus11;
+}
+
 } // namespace modernize
 } // namespace tidy
 } // namespace clang


Index: clang-tidy/modernize/MakeUniqueCheck.h
===
--- clang-tidy/modernize/MakeUniqueCheck.h
+++ clang-tidy/modernize/MakeUniqueCheck.h
@@ -31,6 +31,8 @@
 
 protected:
   SmartPtrTypeMatcher getSmartPointerTypeMatcher() const override;
+
+  bool isVersionSupported(const clang::LangOptions &LangOpts) const override;
 };
 
 } // namespace modernize
Index: clang-tidy/modernize/MakeUniqueCheck.cpp
===
--- clang-tidy/modernize/MakeUniqueCheck.cpp
+++ clang-tidy/modernize/MakeUniqueCheck.cpp
@@ -36,6 +36,10 @@
 equalsBoundNode(PointerType;
 }
 
+bool MakeUniqueCheck::isVersionSupported(const clang::LangOptions &LangOpts) const {
+   return LangOpts.CPlusPlus14;
+}
+
 } // namespace modernize
 } // namespace tidy
 } // namespace clang
Index: clang-tidy/modernize/MakeSmartPtrCheck.h
===
--- clang-tidy/modernize/MakeSmartPtrCheck.h
+++ cla