[llvm-commits] [PATCH] System: Move system_error from KillTheDoctor.

Michael Spencer bigcheesegs at gmail.com
Tue Nov 16 10:23:08 PST 2010


On Tue, Nov 16, 2010 at 1:13 PM, Chris Lattner <clattner at apple.com> wrote:
>
> On Nov 16, 2010, at 12:25 AM, Michael Spencer wrote:
>
>> This is the first step in adding sane error handling support to LLVMSystem.
>>
>> The system API's will be shifted over to returning an error_code, and returning
>> other return values as out parameters to the function.
>
> Looks great to me, except:
>
> +++ b/lib/System/Unix/system_error.inc
> @@ -0,0 +1,34 @@
> +//===- llvm/System/Unix/system_error.cpp - Unix error_code ------*- C++ -*-===//
>
> Please be careful with file header comments (.cpp -> .inc).

I don't know why I have such a hard time seeing that. Even when I look
I don't see it ;/.

>> Code that needs to check error conditions will use the errc enum values which
>> are the same as the posix_errno defines (EBADF, E2BIG, etc...), and
>> are compatable
>> with the error codes in WinError.h due to some magic in system_error.
>>
>> An example would be:
>>
>> if ((error_code ec = KillEvil("Java")) != errc::success) {
>>  if (ec == kill_error::too_much_evil)
>>    std::terminate();
>>  errs() << ":O There was an error! " << ec.message();
>> }
>
> Why not just:
>
>
> if (error_code ec = KillEvil("Java")) {
>   handle_error(ec);
> }
>
> I thought that error_code is convertible to bool?
>
> -Chris

That works too.

- Michael Spencer




More information about the llvm-commits mailing list