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

Chris Lattner clattner at apple.com
Tue Nov 16 10:13:11 PST 2010


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).

> 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



More information about the llvm-commits mailing list