[PATCH] D36452: [clang-tidy] Fix another crash in make-unique check.
This revision was automatically updated to reflect the committed changes. Closed by commit rL310496: [clang-tidy] Fix another crash in make-unique check. (authored by hokein). Repository: rL LLVM https://reviews.llvm.org/D36452 Files: clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp Index: clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp === --- clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp +++ clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp @@ -199,6 +199,13 @@ return; } + // There are some cases where we don't have operator ("." or "->") of the + // "reset" expression, e.g. call "reset()" method directly in the subclass of + // "std::unique_ptr<>". We skip these cases. + if (OperatorLoc.isInvalid()) { +return; + } + auto Diag = diag(ResetCallStart, "use %0 instead") << MakeSmartPtrFunctionName; Index: clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp === --- clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp +++ clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp @@ -415,3 +415,16 @@ g2(t); } #undef DEFINE + +class UniqueFoo : public std::unique_ptr { + public: + void foo() { +reset(new Foo); +this->reset(new Foo); +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use std::make_unique instead +// CHECK-FIXES: *this = std::make_unique(); +(*this).reset(new Foo); +// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use std::make_unique instead +// CHECK-FIXES: (*this) = std::make_unique(); + } +}; Index: clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp === --- clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp +++ clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp @@ -199,6 +199,13 @@ return; } + // There are some cases where we don't have operator ("." or "->") of the + // "reset" expression, e.g. call "reset()" method directly in the subclass of + // "std::unique_ptr<>". We skip these cases. + if (OperatorLoc.isInvalid()) { +return; + } + auto Diag = diag(ResetCallStart, "use %0 instead") << MakeSmartPtrFunctionName; Index: clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp === --- clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp +++ clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp @@ -415,3 +415,16 @@ g2(t); } #undef DEFINE + +class UniqueFoo : public std::unique_ptr { + public: + void foo() { +reset(new Foo); +this->reset(new Foo); +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use std::make_unique instead +// CHECK-FIXES: *this = std::make_unique(); +(*this).reset(new Foo); +// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use std::make_unique instead +// CHECK-FIXES: (*this) = std::make_unique(); + } +}; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D36452: [clang-tidy] Fix another crash in make-unique check.
alexfh accepted this revision. alexfh added a comment. This revision is now accepted and ready to land. Thank you for the fix! Looks good! Comment at: test/clang-tidy/modernize-make-unique.cpp:419 + +class UniqueFoo : public std::unique_ptr { + public: I suspected folks were doing weird stuff to cause this crash ;] https://reviews.llvm.org/D36452 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D36452: [clang-tidy] Fix another crash in make-unique check.
hokein created this revision. Herald added subscribers: xazax.hun, JDevlieghere. The crash happens when calling `reset` method without any preceding operation like "->" or ".", this could happen in a subclass of the "std::unique_ptr". https://reviews.llvm.org/D36452 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 @@ -415,3 +415,16 @@ g2(t); } #undef DEFINE + +class UniqueFoo : public std::unique_ptr { + public: + void foo() { +reset(new Foo); +this->reset(new Foo); +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use std::make_unique instead +// CHECK-FIXES: *this = std::make_unique(); +(*this).reset(new Foo); +// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use std::make_unique instead +// CHECK-FIXES: (*this) = std::make_unique(); + } +}; Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp === --- clang-tidy/modernize/MakeSmartPtrCheck.cpp +++ clang-tidy/modernize/MakeSmartPtrCheck.cpp @@ -199,6 +199,13 @@ return; } + // There are some cases where we don't have operator ("." or "->") of the + // "reset" expression, e.g. call "reset()" method directly in the subclass of + // "std::unique_ptr<>". We skip these cases. + if (OperatorLoc.isInvalid()) { +return; + } + auto Diag = diag(ResetCallStart, "use %0 instead") << MakeSmartPtrFunctionName; Index: test/clang-tidy/modernize-make-unique.cpp === --- test/clang-tidy/modernize-make-unique.cpp +++ test/clang-tidy/modernize-make-unique.cpp @@ -415,3 +415,16 @@ g2(t); } #undef DEFINE + +class UniqueFoo : public std::unique_ptr { + public: + void foo() { +reset(new Foo); +this->reset(new Foo); +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use std::make_unique instead +// CHECK-FIXES: *this = std::make_unique(); +(*this).reset(new Foo); +// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use std::make_unique instead +// CHECK-FIXES: (*this) = std::make_unique(); + } +}; Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp === --- clang-tidy/modernize/MakeSmartPtrCheck.cpp +++ clang-tidy/modernize/MakeSmartPtrCheck.cpp @@ -199,6 +199,13 @@ return; } + // There are some cases where we don't have operator ("." or "->") of the + // "reset" expression, e.g. call "reset()" method directly in the subclass of + // "std::unique_ptr<>". We skip these cases. + if (OperatorLoc.isInvalid()) { +return; + } + auto Diag = diag(ResetCallStart, "use %0 instead") << MakeSmartPtrFunctionName; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits