[llvm] r270916 - [Error] Make ECError only constructible via errorCodeToError.

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Thu May 26 17:04:52 PDT 2016


Oh, of course - thanks for the explanation!

On Thu, May 26, 2016 at 2:40 PM, Lang Hames <lhames at gmail.com> wrote:

> Hi Dave,
>
> It's necessary I'm afraid. llvm::make_unique is operating under the same
> constraint as make_error: ECError's from-std::error_code constructor is now
> private. I've left the copy-constructor public though, so this works as is.
> Since ECError is a very simple class (just contains a std::error_code) I
> expect it should optimize away.
>
> An alternative would be to make this:
>
>   return Error(std::unique_ptr<ECError>(new ECError(EC)));
>
> But that doesn't remove the redundant reference to ECError.
>
> Cheers,
> Lang.
>
> On Thu, May 26, 2016 at 2:24 PM, David Blaikie <dblaikie at gmail.com> wrote:
>
>>
>>
>> On Thu, May 26, 2016 at 2:15 PM, Lang Hames via llvm-commits <
>> llvm-commits at lists.llvm.org> wrote:
>>
>>> Author: lhames
>>> Date: Thu May 26 16:15:58 2016
>>> New Revision: 270916
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=270916&view=rev
>>> Log:
>>> [Error] Make ECError only constructible via errorCodeToError.
>>>
>>> This enforces idiomatic usage of ECError removing the option to
>>> construct them
>>> using make_error.
>>>
>>>
>>> Modified:
>>>     llvm/trunk/include/llvm/Support/Error.h
>>>
>>> Modified: llvm/trunk/include/llvm/Support/Error.h
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Error.h?rev=270916&r1=270915&r2=270916&view=diff
>>>
>>> ==============================================================================
>>> --- llvm/trunk/include/llvm/Support/Error.h (original)
>>> +++ llvm/trunk/include/llvm/Support/Error.h Thu May 26 16:15:58 2016
>>> @@ -835,9 +835,8 @@ private:
>>>  /// (or Expected) and you want to call code that still returns
>>>  /// std::error_codes.
>>>  class ECError : public ErrorInfo<ECError> {
>>> +  friend Error errorCodeToError(std::error_code);
>>>  public:
>>> -  ECError() = default;
>>> -  ECError(std::error_code EC) : EC(EC) {}
>>>    void setErrorCode(std::error_code EC) { this->EC = EC; }
>>>    std::error_code convertToErrorCode() const override { return EC; }
>>>    void log(raw_ostream &OS) const override { OS << EC.message(); }
>>> @@ -846,6 +845,8 @@ public:
>>>    static char ID;
>>>
>>>  protected:
>>> +  ECError() = default;
>>> +  ECError(std::error_code EC) : EC(EC) {}
>>>    std::error_code EC;
>>>  };
>>>
>>> @@ -853,7 +854,7 @@ protected:
>>>  inline Error errorCodeToError(std::error_code EC) {
>>>    if (!EC)
>>>      return Error::success();
>>> -  return make_error<ECError>(EC);
>>> +  return Error(llvm::make_unique<ECError>(ECError(EC)));
>>>
>>
>> Do you have an extra "ECError" in there? Looks like it should be:
>>
>>   return Error(llvm::make_unique<ECError>(EC));
>>
>> ?
>>
>>
>>>  }
>>>
>>>  /// Helper for converting an ECError to a std::error_code.
>>>
>>>
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160526/bd187d10/attachment-0001.html>


More information about the llvm-commits mailing list