[clang] [Clang][Docs] use CommonOptionsParser::create instead of protected constructor (NFC) (PR #70427)

Kohei Asano via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 27 02:21:29 PDT 2023


https://github.com/khei4 updated https://github.com/llvm/llvm-project/pull/70427

>From 1ae7edddc79a0e96fd4b142d09b0752aa3d9ff85 Mon Sep 17 00:00:00 2001
From: khei4 <kk.asano.luxy at gmail.com>
Date: Fri, 27 Oct 2023 17:46:34 +0900
Subject: [PATCH] use: create instead of protected Constructor

handle: expected
---
 clang/docs/LibTooling.rst | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/docs/LibTooling.rst b/clang/docs/LibTooling.rst
index df50dcebf9b83c7..73f7deb2dd87627 100644
--- a/clang/docs/LibTooling.rst
+++ b/clang/docs/LibTooling.rst
@@ -69,9 +69,16 @@ and automatic location of the compilation database using source files paths.
   static llvm::cl::OptionCategory MyToolCategory("my-tool options");
 
   int main(int argc, const char **argv) {
-    // CommonOptionsParser constructor will parse arguments and create a
-    // CompilationDatabase.  In case of error it will terminate the program.
-    CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
+    // CommonOptionsParser::create will parse arguments and create a
+    // CompilationDatabase. In case of error it will terminate the program.
+    llvm::Expected<CommonOptionsParser> Expected =
+        CommonOptionsParser::create(argc, argv, MyToolCategory);
+    if (!Expected)
+    {
+      llvm::errs() << Expected.takeError();
+      return 1;
+    }
+    CommonOptionsParser &OptionsParser = Expected.get();
 
     // Use OptionsParser.getCompilations() and OptionsParser.getSourcePathList()
     // to retrieve CompilationDatabase and the list of input file paths.



More information about the cfe-commits mailing list