From: David Blaikie Date: Sat, 9 Aug 2014 20:02:07 +0000 (+0000) Subject: Use std::unique_ptr to handle transient ownership of UnwrappedLine in ScopedLineState X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0b1f3f747f29dc2e20bf5af973c42b8fa08f7a72;p=clang Use std::unique_ptr to handle transient ownership of UnwrappedLine in ScopedLineState git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215294 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 1751173d11..9f355c930e 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -122,14 +122,13 @@ class ScopedLineState { public: ScopedLineState(UnwrappedLineParser &Parser, bool SwitchToPreprocessorLines = false) - : Parser(Parser) { - OriginalLines = Parser.CurrentLines; + : Parser(Parser), OriginalLines(Parser.CurrentLines) { if (SwitchToPreprocessorLines) Parser.CurrentLines = &Parser.PreprocessorDirectives; else if (!Parser.Line->Tokens.empty()) Parser.CurrentLines = &Parser.Line->Tokens.back().Children; - PreBlockLine = Parser.Line.release(); - Parser.Line.reset(new UnwrappedLine()); + PreBlockLine = std::move(Parser.Line); + Parser.Line = llvm::make_unique(); Parser.Line->Level = PreBlockLine->Level; Parser.Line->InPPDirective = PreBlockLine->InPPDirective; } @@ -139,7 +138,7 @@ public: Parser.addUnwrappedLine(); } assert(Parser.Line->Tokens.empty()); - Parser.Line.reset(PreBlockLine); + Parser.Line = std::move(PreBlockLine); if (Parser.CurrentLines == &Parser.PreprocessorDirectives) Parser.MustBreakBeforeNextToken = true; Parser.CurrentLines = OriginalLines; @@ -148,7 +147,7 @@ public: private: UnwrappedLineParser &Parser; - UnwrappedLine *PreBlockLine; + std::unique_ptr PreBlockLine; SmallVectorImpl *OriginalLines; };