hokein created this revision. Herald added subscribers: xazax.hun, JDevlieghere.
The check doesn't fully support smart-ptr usages inside macros, which may cause incorrect fixes, or even crashes, ignore them for now. https://reviews.llvm.org/D36264 Files: clang-tidy/modernize/MakeSmartPtrCheck.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 @@ -336,3 +336,14 @@ // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use std::make_unique instead // CHECK-FIXES: *Q = std::make_unique<int>(); } + +#define DEFINE(...) __VA_ARGS__ +template<typename T> +void g2(std::unique_ptr<Foo> *t) { + DEFINE(auto p = std::unique_ptr<Foo>(new Foo); t->reset(new Foo);); +} +void macro() { + std::unique_ptr<Foo> *t; + g2<bar::Bar>(t); +} +#undef DEFINE Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp =================================================================== --- clang-tidy/modernize/MakeSmartPtrCheck.cpp +++ clang-tidy/modernize/MakeSmartPtrCheck.cpp @@ -111,9 +111,9 @@ if (New->getNumPlacementArgs() != 0) return; - if (Construct) + if (Construct && !Construct->getLocation().isMacroID()) checkConstruct(SM, Construct, Type, New); - else if (Reset) + else if (Reset && !Reset->getExprLoc().isMacroID()) checkReset(SM, Reset, New); }
Index: test/clang-tidy/modernize-make-unique.cpp =================================================================== --- test/clang-tidy/modernize-make-unique.cpp +++ test/clang-tidy/modernize-make-unique.cpp @@ -336,3 +336,14 @@ // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use std::make_unique instead // CHECK-FIXES: *Q = std::make_unique<int>(); } + +#define DEFINE(...) __VA_ARGS__ +template<typename T> +void g2(std::unique_ptr<Foo> *t) { + DEFINE(auto p = std::unique_ptr<Foo>(new Foo); t->reset(new Foo);); +} +void macro() { + std::unique_ptr<Foo> *t; + g2<bar::Bar>(t); +} +#undef DEFINE Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp =================================================================== --- clang-tidy/modernize/MakeSmartPtrCheck.cpp +++ clang-tidy/modernize/MakeSmartPtrCheck.cpp @@ -111,9 +111,9 @@ if (New->getNumPlacementArgs() != 0) return; - if (Construct) + if (Construct && !Construct->getLocation().isMacroID()) checkConstruct(SM, Construct, Type, New); - else if (Reset) + else if (Reset && !Reset->getExprLoc().isMacroID()) checkReset(SM, Reset, New); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits