brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.4 KiB · 7b96d01 Raw
74 lines · cpp
1// RUN: %check_clang_tidy -std=c++14-or-later %s modernize-make-unique %t -- \2// RUN:   -config="{CheckOptions: \3// RUN:             {modernize-make-unique.IgnoreDefaultInitialization: \4// RUN:              'false'}} \5// RUN:             }" \6// RUN:   -- -I %S/Inputs/smart-ptr7 8#include "initializer_list.h"9#include "unique_ptr.h"10// CHECK-FIXES: #include <memory>11 12void basic() {13  std::unique_ptr<int> P1 = std::unique_ptr<int>(new int());14  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use std::make_unique instead [modernize-make-unique]15  // CHECK-FIXES: std::unique_ptr<int> P1 = std::make_unique<int>();16  std::unique_ptr<int> P2 = std::unique_ptr<int>(new int);17  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use std::make_unique instead [modernize-make-unique]18  // CHECK-FIXES: std::unique_ptr<int> P2 = std::make_unique<int>();19 20  P1.reset(new int());21  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use std::make_unique instead [modernize-make-unique]22  // CHECK-FIXES: P1 = std::make_unique<int>();23  P2.reset(new int);24  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use std::make_unique instead [modernize-make-unique]25  // CHECK-FIXES: P2 = std::make_unique<int>();26 27  P1 = std::unique_ptr<int>(new int());28  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use std::make_unique instead [modernize-make-unique]29  // CHECK-FIXES: P1 = std::make_unique<int>();30  P2 = std::unique_ptr<int>(new int);31  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use std::make_unique instead [modernize-make-unique]32  // CHECK-FIXES: P2 = std::make_unique<int>();33 34  // With auto.35  auto P3 = std::unique_ptr<int>(new int());36  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use std::make_unique instead37  // CHECK-FIXES: auto P3 = std::make_unique<int>();38  auto P4 = std::unique_ptr<int>(new int);39  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use std::make_unique instead40  // CHECK-FIXES: auto P4 = std::make_unique<int>();41 42  std::unique_ptr<int> P5 = std::unique_ptr<int>((new int()));43  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use std::make_unique instead [modernize-make-unique]44  // CHECK-FIXES: std::unique_ptr<int> P5 = std::make_unique<int>();45  std::unique_ptr<int> P6 = std::unique_ptr<int>((new int));46  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use std::make_unique instead [modernize-make-unique]47  // CHECK-FIXES: std::unique_ptr<int> P6 = std::make_unique<int>();48 49  P5.reset((new int()));50  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use std::make_unique instead [modernize-make-unique]51  // CHECK-FIXES: P5 = std::make_unique<int>();52  P6.reset((new int));53  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use std::make_unique instead [modernize-make-unique]54  // CHECK-FIXES: P6 = std::make_unique<int>();55 56  std::unique_ptr<int[]> P7, P8;57  P7.reset(new int[5]());58  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use std::make_unique instead [modernize-make-unique]59  // CHECK-FIXES: P7 = std::make_unique<int[]>(5);60 61  P8.reset(new int[5]);62  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use std::make_unique instead [modernize-make-unique]63  // CHECK-FIXES: P8 = std::make_unique<int[]>(5);64 65  int Num = 3;66  P7.reset(new int[Num]);67  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use std::make_unique instead [modernize-make-unique]68  // CHECK-FIXES: P7 = std::make_unique<int[]>(Num);69 70  P8.reset(new int[Num]);71  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use std::make_unique instead [modernize-make-unique]72  // CHECK-FIXES: P8 = std::make_unique<int[]>(Num);73}74