// RUN: %check_clang_tidy -std=c++14-or-later %s modernize-make-unique %t -- \ // RUN: -config="{CheckOptions: \ // RUN: {modernize-make-unique.IgnoreDefaultInitialization: \ // RUN: 'false'}} \ // RUN: }" \ // RUN: -- -I %S/Inputs/smart-ptr #include "initializer_list.h" #include "unique_ptr.h" // CHECK-FIXES: #include void basic() { std::unique_ptr P1 = std::unique_ptr(new int()); // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use std::make_unique instead [modernize-make-unique] // CHECK-FIXES: std::unique_ptr P1 = std::make_unique(); std::unique_ptr P2 = std::unique_ptr(new int); // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use std::make_unique instead [modernize-make-unique] // CHECK-FIXES: std::unique_ptr P2 = std::make_unique(); P1.reset(new int()); // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use std::make_unique instead [modernize-make-unique] // CHECK-FIXES: P1 = std::make_unique(); P2.reset(new int); // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use std::make_unique instead [modernize-make-unique] // CHECK-FIXES: P2 = std::make_unique(); P1 = std::unique_ptr(new int()); // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use std::make_unique instead [modernize-make-unique] // CHECK-FIXES: P1 = std::make_unique(); P2 = std::unique_ptr(new int); // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use std::make_unique instead [modernize-make-unique] // CHECK-FIXES: P2 = std::make_unique(); // With auto. auto P3 = std::unique_ptr(new int()); // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use std::make_unique instead // CHECK-FIXES: auto P3 = std::make_unique(); auto P4 = std::unique_ptr(new int); // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use std::make_unique instead // CHECK-FIXES: auto P4 = std::make_unique(); std::unique_ptr P5 = std::unique_ptr((new int())); // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use std::make_unique instead [modernize-make-unique] // CHECK-FIXES: std::unique_ptr P5 = std::make_unique(); std::unique_ptr P6 = std::unique_ptr((new int)); // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use std::make_unique instead [modernize-make-unique] // CHECK-FIXES: std::unique_ptr P6 = std::make_unique(); P5.reset((new int())); // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use std::make_unique instead [modernize-make-unique] // CHECK-FIXES: P5 = std::make_unique(); P6.reset((new int)); // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use std::make_unique instead [modernize-make-unique] // CHECK-FIXES: P6 = std::make_unique(); std::unique_ptr P7, P8; P7.reset(new int[5]()); // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use std::make_unique instead [modernize-make-unique] // CHECK-FIXES: P7 = std::make_unique(5); P8.reset(new int[5]); // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use std::make_unique instead [modernize-make-unique] // CHECK-FIXES: P8 = std::make_unique(5); int Num = 3; P7.reset(new int[Num]); // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use std::make_unique instead [modernize-make-unique] // CHECK-FIXES: P7 = std::make_unique(Num); P8.reset(new int[Num]); // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use std::make_unique instead [modernize-make-unique] // CHECK-FIXES: P8 = std::make_unique(Num); }