Issue 97983
Summary "clang/docs/LibTooling.rst" example code causing crash when invalid paramter given
Labels clang
Assignees
Reporter nickhuang99
    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 call `handleAllErrors` 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.

 
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to