[cfe-dev] Should functions returning bool return true or false on success?
Hans Wennborg via cfe-dev
cfe-dev at lists.llvm.org
Tue Sep 18 01:07:52 PDT 2018
On Mon, Sep 17, 2018 at 7:57 PM, Nico Weber via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
> Hi,
>
> in https://reviews.llvm.org/D52143 there's some uncertainty if LLVM code
> prefers
>
> if (!Function())
> // Call to function failed, deal with it
>
> or
>
> if (Function())
> // Call to function failed, deal with it
>
> (Note that this is about functions returning bool, not int.)
>
> Folks on that review feel that returning true on success is probably what we
> want, but it's not documented anywhere and we do have both forms in the
> codebase.
>
> True on success seems more common:
> http://llvm-cs.pcc.me.uk/?q=true+on+success
> http://llvm-cs.pcc.me.uk/?q=true+on+error
>
> Does anyone have a pointer to previous on-list discussion on this? If not,
> this thread could be the place where we sort this out once and for all :-)
I don't remember on-list discussions about this, but I'd be curious to
learn about the background.
In particular, true-on-error seems pervasive in our various parsers,
both in Clang and LLVM. Is this some parser writing convention that's
also used outside LLVM, or why do we do this?
Cheers,
Hans
More information about the cfe-dev
mailing list