"clang/docs/LibTooling.rst" example code causing crash when invalid paramter given #97983
Labels
clang
Clang issues not falling into any other category
documentation
good first issue
https://github.com/llvm/llvm-project/contribute
For people new to clang like myself, the first tutorial is very essential to learn. That is why those example code from tutorial clang/docs/LibTooling.rst should be very solid. Unfortunately a basic error handling always causes core dump which seems scary to a rookie developer.
The following snippet causes core dump when command line parameter is invalid because Error returned from
ExpectedParser.takeError()
unhandled.auto ExpectedParser = CommonOptionsParser::create(argc, argv, MyToolCategory);
if (!ExpectedParser) {
llvm::errs() << ExpectedParser.takeError();
return 1;
}
`
A simple fix like this
toString(ExpectedParser.takeError());
can fix this because
toString
will callhandleAllErrors
before formatting string result.It maybe seems trivial, but I believe the Hello World is giving very important impression for all new ones to clang.
The text was updated successfully, but these errors were encountered: