Coding standard: return succ on failure?

Rafael EspĂ­ndola rafael.espindola at gmail.com
Fri Aug 2 07:16:21 PDT 2013


On 1 August 2013 16:25, Chandler Carruth <chandlerc at google.com> wrote:
> I have lobbied in the past for doing away with returning false on success. I
> continue to do so.
>
> There are parts of the Clang parser that do this consistently, but they are
> increasingly few and far between. I consistently see new code being written
> in both Clang and LLVM using false to mean failure and true to mean success,
> so I think we should just admit that this is the de-facto standard for new
> code going forward.
>
> That said, the last time I raised this question, Chris showed up to argue.
> ;]

ccing him :-)

One think I like with returning true on failure is that

bool doFooBar();

looks like just a special case of

error_code doFooBar();

for functions that don't need to report different types of errors. If
we change the convention to return false on error, error_code should
probably evaluate to false on errors too.

Cheers,
Rafael



More information about the llvm-commits mailing list