Use an enum class.

llvm-svn: 210623
This commit is contained in:
Rafael Espindola 2014-06-11 01:22:20 +00:00
parent 8076cab0ce
commit 933c9509da
2 changed files with 13 additions and 22 deletions

View File

@ -29,8 +29,8 @@ const char *_readobj_error_category::name() const {
return "llvm.readobj"; return "llvm.readobj";
} }
std::string _readobj_error_category::message(int ev) const { std::string _readobj_error_category::message(int EV) const {
switch (ev) { switch (static_cast<readobj_error>(EV)) {
case readobj_error::success: return "Success"; case readobj_error::success: return "Success";
case readobj_error::file_not_found: case readobj_error::file_not_found:
return "No such file."; return "No such file.";
@ -42,14 +42,13 @@ std::string _readobj_error_category::message(int ev) const {
return "Unsupported object file format."; return "Unsupported object file format.";
case readobj_error::unknown_symbol: case readobj_error::unknown_symbol:
return "Unknown symbol."; return "Unknown symbol.";
default:
llvm_unreachable("An enumerator of readobj_error does not have a message "
"defined.");
} }
llvm_unreachable("An enumerator of readobj_error does not have a message "
"defined.");
} }
error_condition _readobj_error_category::default_error_condition(int ev) const { error_condition _readobj_error_category::default_error_condition(int EV) const {
if (ev == readobj_error::success) if (static_cast<readobj_error>(EV) == readobj_error::success)
return error_condition(); return error_condition();
return errc::invalid_argument; return errc::invalid_argument;
} }

View File

@ -20,20 +20,13 @@ namespace llvm {
const error_category &readobj_category(); const error_category &readobj_category();
struct readobj_error { enum class readobj_error {
enum _ { success = 0,
success = 0, file_not_found,
file_not_found, unsupported_file_format,
unsupported_file_format, unrecognized_file_format,
unrecognized_file_format, unsupported_obj_file_format,
unsupported_obj_file_format, unknown_symbol
unknown_symbol
};
_ v_;
readobj_error(_ v) : v_(v) {}
explicit readobj_error(int v) : v_(_(v)) {}
operator int() const {return v_;}
}; };
inline error_code make_error_code(readobj_error e) { inline error_code make_error_code(readobj_error e) {
@ -41,7 +34,6 @@ inline error_code make_error_code(readobj_error e) {
} }
template <> struct is_error_code_enum<readobj_error> : std::true_type { }; template <> struct is_error_code_enum<readobj_error> : std::true_type { };
template <> struct is_error_code_enum<readobj_error::_> : std::true_type { };
} // namespace llvm } // namespace llvm