This revision was automatically updated to reflect the committed changes. Closed by commit rCTE344733: [clang-tidy] Ignore a case where the fix of make_unique check introduces side⦠(authored by hokein, committed by ).
Changed prior to commit: https://reviews.llvm.org/D53377?vs=170012&id=170054#toc Repository: rL LLVM https://reviews.llvm.org/D53377 Files: clang-tidy/modernize/MakeSmartPtrCheck.cpp test/clang-tidy/modernize-make-unique.cpp Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp =================================================================== --- clang-tidy/modernize/MakeSmartPtrCheck.cpp +++ clang-tidy/modernize/MakeSmartPtrCheck.cpp @@ -121,6 +121,15 @@ if (New->getNumPlacementArgs() != 0) return; + // Be conservative for cases where we construct an array without any + // initalization. + // For example, + // P.reset(new int[5]) // check fix: P = make_unique<int []>(5) + // + // The fix of the check has side effect, it introduces default initialization + // which maybe unexpected and cause performance regression. + if (New->isArray() && !New->hasInitializer()) + return; if (Construct) checkConstruct(SM, Result.Context, Construct, Type, New); else if (Reset) Index: test/clang-tidy/modernize-make-unique.cpp =================================================================== --- test/clang-tidy/modernize-make-unique.cpp +++ test/clang-tidy/modernize-make-unique.cpp @@ -403,18 +403,15 @@ // CHECK-FIXES: FFs = std::make_unique<Foo[]>(Num2); std::unique_ptr<int[]> FI; - FI.reset(new int[5]); - // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: - // CHECK-FIXES: FI = std::make_unique<int[]>(5); - FI.reset(new int[5]()); + FI.reset(new int[5]()); // default initialization. // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: // CHECK-FIXES: FI = std::make_unique<int[]>(5); + + // The check doesn't give warnings and fixes for cases where the original new + // expresion doesn't do any initialization. + FI.reset(new int[5]); FI.reset(new int[Num]); - // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: - // CHECK-FIXES: FI = std::make_unique<int[]>(Num); FI.reset(new int[Num2]); - // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: - // CHECK-FIXES: FI = std::make_unique<int[]>(Num2); } void aliases() {
Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp =================================================================== --- clang-tidy/modernize/MakeSmartPtrCheck.cpp +++ clang-tidy/modernize/MakeSmartPtrCheck.cpp @@ -121,6 +121,15 @@ if (New->getNumPlacementArgs() != 0) return; + // Be conservative for cases where we construct an array without any + // initalization. + // For example, + // P.reset(new int[5]) // check fix: P = make_unique<int []>(5) + // + // The fix of the check has side effect, it introduces default initialization + // which maybe unexpected and cause performance regression. + if (New->isArray() && !New->hasInitializer()) + return; if (Construct) checkConstruct(SM, Result.Context, Construct, Type, New); else if (Reset) Index: test/clang-tidy/modernize-make-unique.cpp =================================================================== --- test/clang-tidy/modernize-make-unique.cpp +++ test/clang-tidy/modernize-make-unique.cpp @@ -403,18 +403,15 @@ // CHECK-FIXES: FFs = std::make_unique<Foo[]>(Num2); std::unique_ptr<int[]> FI; - FI.reset(new int[5]); - // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: - // CHECK-FIXES: FI = std::make_unique<int[]>(5); - FI.reset(new int[5]()); + FI.reset(new int[5]()); // default initialization. // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: // CHECK-FIXES: FI = std::make_unique<int[]>(5); + + // The check doesn't give warnings and fixes for cases where the original new + // expresion doesn't do any initialization. + FI.reset(new int[5]); FI.reset(new int[Num]); - // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: - // CHECK-FIXES: FI = std::make_unique<int[]>(Num); FI.reset(new int[Num2]); - // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: - // CHECK-FIXES: FI = std::make_unique<int[]>(Num2); } void aliases() {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits