[cfe-dev] [llvm-dev] Should functions returning bool return true or false on success?
Matthias Braun via cfe-dev
cfe-dev at lists.llvm.org
Mon Sep 17 15:51:46 PDT 2018
- I personally prefer return `true` on success
- I'm pretty sure we have both in LLVM
- I think the 2nd version is more common in LLVM (though this is just my gut feeling and my be biased from the areas I work on).
I'd mainly try to stay consistent with the code you find in the area of LLVM you are working on...
- Matthias
> On Sep 17, 2018, at 10:57 AM, Nico Weber via llvm-dev <llvm-dev at lists.llvm.org> wrote:
>
> Hi,
>
> in https://reviews.llvm.org/D52143 <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+success>
> http://llvm-cs.pcc.me.uk/?q=true+on+error <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 :-)
>
> Apologies for the bike-sheddy topic.
>
> Nico
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180917/2b60475f/attachment.html>
More information about the cfe-dev
mailing list