[clang] 2da4cee - [docs] Use make_unique in FrontendAction example

Nico Weber via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 20 10:47:54 PDT 2021


Author: Nicolás Alvarez
Date: 2021-04-20T13:47:16-04:00
New Revision: 2da4ceec936e0e3ddb3028c35e97e99ab1de7484

URL: https://github.com/llvm/llvm-project/commit/2da4ceec936e0e3ddb3028c35e97e99ab1de7484
DIFF: https://github.com/llvm/llvm-project/commit/2da4ceec936e0e3ddb3028c35e97e99ab1de7484.diff

LOG: [docs] Use make_unique in FrontendAction example

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

Added: 
    

Modified: 
    clang/docs/RAVFrontendAction.rst

Removed: 
    


################################################################################
diff  --git a/clang/docs/RAVFrontendAction.rst b/clang/docs/RAVFrontendAction.rst
index e38276b43295..f6c46668fba3 100644
--- a/clang/docs/RAVFrontendAction.rst
+++ b/clang/docs/RAVFrontendAction.rst
@@ -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());
         }
       };
 


        


More information about the cfe-commits mailing list