<div dir="ltr">The intent of this code is to allow handling of three distinct cases:<br>  1. a valid ClangTidyOptions instance<div>  2. an error with a message</div><div>  3. no error and no ClangTidyOptions, so the code just goes on looking for a configuration file without displaying an error</div><div><br></div><div>Case 3 could be handled by introducing a separate return-by-reference boolean flag or something like that, but here I preferred to use a valid state of the ErrorOr class: HasError + std::error_code containing 0 (success). If this looks confusing, I can add a comment describing this case.<br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 4, 2014 at 12:24 PM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Tue, Nov 4, 2014 at 12:23 PM, Justin Bogner <span dir="ltr"><<a href="mailto:mail@justinbogner.com" target="_blank">mail@justinbogner.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> writes:<br>
>     This is totally wrong. ErrorOr's implicit bool conversion is true iff<br>
>     there is an error,<br>
><br>
> Doesn't look like it:<br>
><br>
> ErrorOr.h:<br>
>   /// \brief Return false if there is an error.<br>
>   LLVM_EXPLICIT operator bool() const {<br>
>     return !HasError;<br>
>   }<br>
<br>
</span>Oops, I misinterpreted "An implicit conversion to bool provides a way to<br>
check if there was an error." - I'll probably clarify that RSN. In any<br>
case, isn't the added check here redundant then?<br></blockquote><div><br></div></span><div>Yep, looks redundant to me.</div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Maybe it would avoid confusion to use this (fairly common) pattern:<br>
<span><br>
  llvm::ErrorOr<ClangTidyOptions> ParsedOptions =<br>
      ConfigHandler.second((*Text)->getBuffer());<br>
</span>  if (std::error_code EC = ParsedOptions.getError()) {<br></blockquote></span><div><br>Agreed, this seems fairly canonical.<br> </div><span class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
    // ...<br>
<div><div>  }<br>
<br>
><br>
>     so !ParsedOptions implies !ParsedOptions.getError().<br>
><br>
>     I think you want:<br>
><br>
>       llvm::ErrorOr<ClangTidyOptions> ParsedOptions =<br>
>           ConfigHandler.second((*Text)->getBuffer());<br>
>       if (ParsedOptions) {<br>
>         llvm::errs() << "Error parsing " << ConfigFile << ": "<br>
>                      << ParsedOptions.getError().message() << "\n";<br>
>         ...<br>
><br>
>     This obviously changes the behaviour, but the current behaviour doesn't<br>
>     make sense.<br>
><br>
>     >        continue;<br>
>     >      }<br>
>     ><br>
>     ><br>
>     ><br>
>     > _______________________________________________<br>
>     > cfe-commits mailing list<br>
>     > <a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
>     > <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
>     _______________________________________________<br>
>     cfe-commits mailing list<br>
>     <a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
>     <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></span></div></div></div></blockquote></div><br>
</div></div></div>