[libunwind] [docs] Minor fix to outdated example in LibTooling tutorial (PR #67262)
Ivan Ho via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 24 04:29:10 PDT 2023
https://github.com/hhkit created https://github.com/llvm/llvm-project/pull/67262
Came across this while using said tutorial.
I grabbed this example from [ASTMatchers tutorial](https://clang.llvm.org/docs/LibASTMatchersTutorial.html) for consistency, and it works with the latest LLVM version.
>From d9b18db1a38e6e9002582a34b510a3d3fdd4f996 Mon Sep 17 00:00:00 2001
From: hhkit <38537881+hhkit at users.noreply.github.com>
Date: Fri, 22 Sep 2023 05:17:39 +0800
Subject: [PATCH] [docs] Minor fix; outdated interface used
---
clang/docs/LibTooling.rst | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/clang/docs/LibTooling.rst b/clang/docs/LibTooling.rst
index df50dcebf9b83c7..e552ed81fe14edb 100644
--- a/clang/docs/LibTooling.rst
+++ b/clang/docs/LibTooling.rst
@@ -69,9 +69,17 @@ 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
+
+ // CommonOptionsParser::create will parse arguments and create a
// CompilationDatabase. In case of error it will terminate the program.
- CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
+ auto ExpectedParser = CommonOptionsParser::create(argc, argv, MyToolCategory);
+ if (!ExpectedParser) {
+ // Fail gracefully for unsupported options.
+ llvm::errs() << ExpectedParser.takeError();
+ return 1;
+ }
+
+ CommonOptionsParser& OptionsParser = ExpectedParser.get();
// Use OptionsParser.getCompilations() and OptionsParser.getSourcePathList()
// to retrieve CompilationDatabase and the list of input file paths.
@@ -133,7 +141,14 @@ version of this example tool is also checked into the clang tree at
static cl::extrahelp MoreHelp("\nMore help text...\n");
int main(int argc, const char **argv) {
- CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
+ auto ExpectedParser = CommonOptionsParser::create(argc, argv, MyToolCategory);
+ if (!ExpectedParser) {
+ // Fail gracefully for unsupported options.
+ llvm::errs() << ExpectedParser.takeError();
+ return 1;
+ }
+
+ CommonOptionsParser& OptionsParser = ExpectedParser.get();
ClangTool Tool(OptionsParser.getCompilations(),
OptionsParser.getSourcePathList());
return Tool.run(newFrontendActionFactory<clang::SyntaxOnlyAction>().get());
More information about the cfe-commits
mailing list