(original) (raw)

IMO, bool is the wrong type to return here. We have an unambiguous alternative here specifically for this reason: llvm::Error/llvm::ErrorSuccess.

From: cfe-dev \[mailto:cfe-dev-bounces@lists.llvm.org\] On Behalf Of Philip Reames via cfe-dev
Sent: Monday, September 17, 2018 11:15 AM
To: Nico Weber ; llvm-dev ; cfe-dev
Subject: Re: \[cfe-dev\] \[llvm-dev\] Should functions returning bool return true or false on success?

my vote: true for success, false for failure

Philip

On 09/17/2018 10:57 AM, Nico Weber via llvm-dev 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:

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@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev