[llvm] [docs] Minor fix to outdated example in LibTooling tutorial (PR #67262)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 24 04:30:10 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/67262.diff
1 Files Affected:
- (modified) clang/docs/LibTooling.rst (+18-3)
``````````diff
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());
``````````
</details>
https://github.com/llvm/llvm-project/pull/67262
More information about the llvm-commits
mailing list