<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Sep 4, 2014 at 5:19 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:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5">On Thu, Sep 4, 2014 at 5:14 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span>On Thu, Sep 4, 2014 at 5:01 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:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span>On Wed, Sep 3, 2014 at 6:36 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br></span><span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi dblaikie,<br>
<br>
Add an optional output parameter to `can_write` to allow it to indicate why a file is not considered writable (along with a sample use from Clang where we currently produce stupid diagnostics saying `"can't open output file: Success"`).<br>
<br>
I'm not entirely sure this is the right design, and in particular it's a somewhat different interface from the other functions in this file. I also considered:<br>
<br>
  std::error_code can_write(const Twine &Path, bool &result);<br>
<br>
... which seems redundant because `result` is set to `true` iff the error code is `success`, and ...<br>
<br>
  std::error_code can_write(const Twine &Path);<br>
<br>
... which is terrible because `bool(can_write(Path))` is `true` iff the file is *not* writable, and ...<br>
<br>
  std::error_code cannot_write(const Twine &Path);<br>
<br>
... which is inconsistent with other functions near here and ugly.<br></blockquote><div><br></div></span><div>I'll just put this out there. No idea whether it's sane:<br><br>ErrorOr<void>? (not sure if the ErrorOr template supports void... I suppose it'd need a whole separate specialization)<br><br>(alternatively, struct Success {}; ErrorOr<Success>)</div></div></div></div></blockquote><div><br></div></span><div> ErrorOr<NoneType>? =)</div></div></div></div></blockquote><div><br></div></div></div><div>Or that, sure.</div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>I feel a little uncomfortable about using ErrorOr to represent a not-actually-an-error case.<br></div></div></div></div></blockquote></span><div><br>Yeah, I'm not entirely comfortable with it either, and I'm not convinced it's the least bad of the options here (nor that it's not the least bad... ).<br><br>You can't invert it and do bool return with an error_code out parameter can you (because error_code isn't default constructible)...  </div></div></div></div></blockquote><div> </div></div></div><div class="gmail_extra">You can! error_code default constructs to a success value; bool return with (optional) error_code out parameter is what the attached patch does.</div></div>