@@ -63,15 +63,22 @@ and automatic location of the compilation database using source files paths.
63
63
#include "llvm/Support/CommandLine.h"
64
64
65
65
using namespace clang::tooling;
66
+ using namespace llvm;
66
67
67
68
// Apply a custom category to all command-line options so that they are the
68
69
// only ones displayed.
69
- static llvm: : cl: :OptionCategory MyToolCategory("my-tool options");
70
+ static cl::OptionCategory MyToolCategory("my-tool options");
70
71
71
72
int main(int argc, const char **argv) {
72
- // CommonOptionsParser constructor will parse arguments and create a
73
- // CompilationDatabase. In case of error it will terminate the program.
74
- CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
73
+ // CommonOptionsParser::create will parse arguments and create a
74
+ // CompilationDatabase.
75
+ auto ExpectedParser = CommonOptionsParser::create(argc, argv, MyToolCategory);
76
+ if (!ExpectedParser) {
77
+ // Fail gracefully for unsupported options.
78
+ llvm::errs() << ExpectedParser.takeError();
79
+ return 1;
80
+ }
81
+ CommonOptionsParser& OptionsParser = ExpectedParser.get();
75
82
76
83
// Use OptionsParser.getCompilations() and OptionsParser.getSourcePathList()
77
84
// to retrieve CompilationDatabase and the list of input file paths.
@@ -133,7 +140,12 @@ version of this example tool is also checked into the clang tree at
133
140
static cl::extrahelp MoreHelp("\n More help text...\n ");
134
141
135
142
int main(int argc, const char **argv) {
136
- CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
143
+ auto ExpectedParser = CommonOptionsParser::create(argc, argv, MyToolCategory);
144
+ if (!ExpectedParser) {
145
+ llvm::errs() << ExpectedParser.takeError();
146
+ return 1;
147
+ }
148
+ CommonOptionsParser& OptionsParser = ExpectedParser.get();
137
149
ClangTool Tool(OptionsParser.getCompilations(),
138
150
OptionsParser.getSourcePathList());
139
151
return Tool.run(newFrontendActionFactory<clang::SyntaxOnlyAction>().get());
0 commit comments