[llvm] r224108 - Use unique_ptr to remove an explicit delete. Change return type to pass the unique_ptr to caller.

Craig Topper craig.topper at gmail.com
Thu Dec 11 23:52:17 PST 2014


Author: ctopper
Date: Fri Dec 12 01:52:16 2014
New Revision: 224108

URL: http://llvm.org/viewvc/llvm-project?rev=224108&view=rev
Log:
Use unique_ptr to remove an explicit delete. Change return type to pass the unique_ptr to caller.

Modified:
    llvm/trunk/tools/llvm-mc/llvm-mc.cpp

Modified: llvm/trunk/tools/llvm-mc/llvm-mc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=224108&r1=224107&r2=224108&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/llvm-mc.cpp (original)
+++ llvm/trunk/tools/llvm-mc/llvm-mc.cpp Fri Dec 12 01:52:16 2014
@@ -204,16 +204,15 @@ static const Target *GetTarget(const cha
   return TheTarget;
 }
 
-static tool_output_file *GetOutputStream() {
+static std::unique_ptr<tool_output_file> GetOutputStream() {
   if (OutputFilename == "")
     OutputFilename = "-";
 
   std::error_code EC;
-  tool_output_file *Out =
-      new tool_output_file(OutputFilename, EC, sys::fs::F_None);
+  auto Out = llvm::make_unique<tool_output_file>(OutputFilename, EC,
+                                                 sys::fs::F_None);
   if (EC) {
     errs() << EC.message() << '\n';
-    delete Out;
     return nullptr;
   }
 
@@ -435,7 +434,7 @@ int main(int argc, char **argv) {
     FeaturesStr = Features.getString();
   }
 
-  std::unique_ptr<tool_output_file> Out(GetOutputStream());
+  std::unique_ptr<tool_output_file> Out = GetOutputStream();
   if (!Out)
     return 1;
 





More information about the llvm-commits mailing list