Don't convert object_error's enum to and from int.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 18 Jun 2013 13:30:31 +0000 (13:30 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 18 Jun 2013 13:30:31 +0000 (13:30 +0000)
This allows the compiler to see the enum and warn about it. While in here,
fix a switch to not use a default and fix style violations.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184186 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Object/Error.h
lib/Object/Error.cpp

index fbaf71c17b8efef4f5cd7f87c758083c944e7d23..32b834f21543fe804ad8e305cf215d41843c5acd 100644 (file)
@@ -22,17 +22,16 @@ namespace object {
 const error_category &object_category();
 
 struct object_error {
-enum _ {
-  success = 0,
-  invalid_file_type,
-  parse_failed,
-  unexpected_eof
-};
-  _ v_;
-
-  object_error(_ v) : v_(v) {}
-  explicit object_error(int v) : v_(_(v)) {}
-  operator int() const {return v_;}
+  enum Impl {
+    success = 0,
+    invalid_file_type,
+    parse_failed,
+    unexpected_eof
+  };
+  Impl V;
+
+  object_error(Impl V) : V(V) {}
+  operator Impl() const { return V; }
 };
 
 inline error_code make_error_code(object_error e) {
@@ -43,7 +42,8 @@ inline error_code make_error_code(object_error e) {
 
 template <> struct is_error_code_enum<object::object_error> : true_type { };
 
-template <> struct is_error_code_enum<object::object_error::_> : true_type { };
+template <> struct is_error_code_enum<object::object_error::Impl> : true_type {
+};
 
 } // end namespace llvm.
 
index 25946257ab5aeb2e4e9ea3af761a982474373a1f..7005a72d68b93e1590e767037f1e374fd52b91ac 100644 (file)
@@ -31,7 +31,8 @@ const char *_object_error_category::name() const {
 }
 
 std::string _object_error_category::message(int ev) const {
-  switch (ev) {
+  object_error::Impl E = static_cast<object_error::Impl>(ev);
+  switch (E) {
   case object_error::success: return "Success";
   case object_error::invalid_file_type:
     return "The file was not recognized as a valid object file";
@@ -39,10 +40,9 @@ std::string _object_error_category::message(int ev) const {
     return "Invalid data was encountered while parsing the file";
   case object_error::unexpected_eof:
     return "The end of the file was unexpectedly encountered";
-  default:
-    llvm_unreachable("An enumerator of object_error does not have a message "
-                     "defined.");
   }
+  llvm_unreachable("An enumerator of object_error does not have a message "
+                   "defined.");
 }
 
 error_condition _object_error_category::default_error_condition(int ev) const {