[LLVMdev] Users of llvm::error_code all inherit from _do_message
Justin Bogner
mail at justinbogner.com
Fri Mar 14 14:52:28 PDT 2014
There are several libraries in LLVM that create their own `error_code`
categories, so that they can return errors in a consistent way and with
convenient messages.
To do this, these libraries create an error category type that inherits
from `_do_message` in system_error.h. There are a number of ways that
this is wrong:
1. From the name, it's quite clear that _do_message is an implementation
detail.
2. The only function defined in _do_message is specifically intended for
system errors that report via errno, which is not what the custom
categories are doing.
As far as I can tell, the custom categories are only inheriting from
_do_message is apparently to get around the fact that error_category's
constructor is private, and that _do_message is a friend class of
error_category.
If we want to continue using error_code the way we currently are, I
think the right thing to do here is to make error_category's constructor
protected and stop inheriting from _do_message. Would anyone object to
that?
More information about the llvm-dev
mailing list