[docs] Use make_unique in FrontendAction example
authorNicolás Alvarez <nicolas.alvarez@gmail.com>
Tue, 20 Apr 2021 17:47:16 +0000 (13:47 -0400)
committerNico Weber <thakis@chromium.org>
Tue, 20 Apr 2021 17:47:16 +0000 (13:47 -0400)
The code example for "RecursiveASTVisitor based ASTFrontendActions"
was using unique_ptr<X>(new X) when creating the AST consumer; change
it to use make_unique instead. The main function of the same example
already used make_unique.

Differential Revision: https://reviews.llvm.org/D93185

clang/docs/RAVFrontendAction.rst

index e38276b..f6c4666 100644 (file)
@@ -27,8 +27,7 @@ unit.
       public:
         virtual std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(
           clang::CompilerInstance &Compiler, llvm::StringRef InFile) {
-          return std::unique_ptr<clang::ASTConsumer>(
-              new FindNamedClassConsumer);
+          return std::make_unique<FindNamedClassConsumer>();
         }
       };
 
@@ -114,8 +113,7 @@ freshly created FindNamedClassConsumer:
 
       virtual std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(
         clang::CompilerInstance &Compiler, llvm::StringRef InFile) {
-        return std::unique_ptr<clang::ASTConsumer>(
-            new FindNamedClassConsumer(&Compiler.getASTContext()));
+        return std::make_unique<FindNamedClassConsumer>(&Compiler.getASTContext());
       }
 
 Now that the ASTContext is available in the RecursiveASTVisitor, we can
@@ -189,8 +187,7 @@ Now we can combine all of the above into a small example program:
       public:
         virtual std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(
           clang::CompilerInstance &Compiler, llvm::StringRef InFile) {
-          return std::unique_ptr<clang::ASTConsumer>(
-              new FindNamedClassConsumer(&Compiler.getASTContext()));
+          return std::make_unique<FindNamedClassConsumer>(&Compiler.getASTContext());
         }
       };