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,8 +61,13 @@ Options.store(Opts, "IgnoreMacros", IgnoreMacros); } +bool MakeSmartPtrCheck::isLanguageVersionSupported( + const LangOptions &LangOpts) const { + return LangOpts.CPlusPlus11; +} + void MakeSmartPtrCheck::registerPPCallbacks(CompilerInstance &Compiler) { - if (getLangOpts().CPlusPlus11) { + if (isLanguageVersionSupported(getLangOpts())) { Inserter.reset(new utils::IncludeInserter( Compiler.getSourceManager(), Compiler.getLangOpts(), IncludeStyle)); Compiler.getPreprocessor().addPPCallbacks(Inserter->CreatePPCallbacks()); @@ -70,7 +75,7 @@ } void MakeSmartPtrCheck::registerMatchers(ast_matchers::MatchFinder *Finder) { - if (!getLangOpts().CPlusPlus11) + if (!isLanguageVersionSupported(getLangOpts())) return; // Calling make_smart_ptr from within a member function of a type with a 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: 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: 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-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-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.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"