[llvm-dev] [cfe-dev] Should functions returning bool return true or false on success?

Alex Bradbury via llvm-dev llvm-dev at lists.llvm.org
Tue Sep 18 00:38:45 PDT 2018


On 17 September 2018 at 23:51, Matthias Braun via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
> - 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...

I agree that staying consistent with the surrounding code is most
important. I don't like the fact that AsmParser code often uses false
for success, but it would be substantially more confusing if
target-specific code did the opposite. It's tempting to fix this but
it would a be a disruptive change that causes some pain for
out-of-tree backends.

New code that doesn't need to match behaviour of existing functions
should IMHO use true for success and false for failure.

Best,

Alex


More information about the llvm-dev mailing list