diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2015-04-10 14:11:52 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2015-04-10 14:11:52 +0000 |
commit | 269ec0f47067ed03f83680db116bc0231005fd52 (patch) | |
tree | 886800e37d08e25a768c52bdc5a52f1ffd9a796f /clang/lib/Frontend/CompilerInstance.cpp | |
parent | 8429681d5759005777475c0faf6d2149e40386ac (diff) | |
download | llvm-269ec0f47067ed03f83680db116bc0231005fd52.zip llvm-269ec0f47067ed03f83680db116bc0231005fd52.tar.gz llvm-269ec0f47067ed03f83680db116bc0231005fd52.tar.bz2 |
Use a std::unique_ptr to make it easier to see who owns the stream.
llvm-svn: 234597
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 3492bf1..70b3bc4 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -518,15 +518,14 @@ void CompilerInstance::createSema(TranslationUnitKind TUKind, // Output Files -void CompilerInstance::addOutputFile(const OutputFile &OutFile) { +void CompilerInstance::addOutputFile(OutputFile &&OutFile) { assert(OutFile.OS && "Attempt to add empty stream to output list!"); - OutputFiles.push_back(OutFile); + OutputFiles.push_back(std::move(OutFile)); } void CompilerInstance::clearOutputFiles(bool EraseFiles) { for (std::list<OutputFile>::iterator it = OutputFiles.begin(), ie = OutputFiles.end(); it != ie; ++it) { - delete it->OS; if (!it->TempFilename.empty()) { if (EraseFiles) { llvm::sys::fs::remove(it->TempFilename); @@ -561,9 +560,10 @@ CompilerInstance::createDefaultOutputFile(bool Binary, } llvm::raw_null_ostream *CompilerInstance::createNullOutputFile() { - llvm::raw_null_ostream *OS = new llvm::raw_null_ostream(); - addOutputFile(OutputFile("", "", OS)); - return OS; + auto OS = llvm::make_unique<llvm::raw_null_ostream>(); + llvm::raw_null_ostream *Ret = OS.get(); + addOutputFile(OutputFile("", "", std::move(OS))); + return Ret; } llvm::raw_fd_ostream * @@ -575,21 +575,22 @@ CompilerInstance::createOutputFile(StringRef OutputPath, bool CreateMissingDirectories) { std::string OutputPathName, TempPathName; std::error_code EC; - llvm::raw_fd_ostream *OS = createOutputFile( + std::unique_ptr<llvm::raw_fd_ostream> OS(createOutputFile( OutputPath, EC, Binary, RemoveFileOnSignal, InFile, Extension, - UseTemporary, CreateMissingDirectories, &OutputPathName, &TempPathName); + UseTemporary, CreateMissingDirectories, &OutputPathName, &TempPathName)); if (!OS) { getDiagnostics().Report(diag::err_fe_unable_to_open_output) << OutputPath << EC.message(); return nullptr; } + llvm::raw_fd_ostream *Ret = OS.get(); // Add the output file -- but don't try to remove "-", since this means we are // using stdin. addOutputFile(OutputFile((OutputPathName != "-") ? OutputPathName : "", - TempPathName, OS)); + TempPathName, std::move(OS))); - return OS; + return Ret; } llvm::raw_fd_ostream *CompilerInstance::createOutputFile( |