[PATCH] Add ErrorOr<>::getOrDie() which uses report_fatal_error instead of assert.

Rafael Espíndola rafael.espindola at gmail.com
Fri Oct 10 06:23:02 PDT 2014

>> Sure, but I'm still not convinced this is worthwhile. The motivating
>> example was apparently http://reviews.llvm.org/D5602, which looks to me
>> like it wants to use this feature for something like this (**):
>>     Foo::Foo(ErrorOr<Whatever> X)
>>         : Whatever(extractOrDie(X, "the thing is broken") {}
>> This can save a couple of lines of code, but I would argue it's quite a
>> bit less clear than this:
>>     Foo::Foo(ErrorOr<Whatever> X) {
>>       if (X.hasError())
>>         report_fatal_error("the thing is broken");
>>       Whatever = *X;
>>     }
> Yes, I want to replace this kind of code with member initializers using
> getOrDie/extractOrDie with or without an error message. The reason is to
> reduce code duplication and keep the initialization in the initializer list.
> And I thought that this abstraction may be useful elsewhere. If not, I'll
> just end up putting extracOrDie in some clang-tidy header.

I think it will be useful, but we can start with clang-tidy and
refactor to an llvm header afterwards.


More information about the llvm-commits mailing list