diff options
| -rw-r--r-- | llvm/include/llvm/Support/ErrorOr.h | 4 | ||||
| -rw-r--r-- | llvm/unittests/Support/ErrorOrTest.cpp | 5 |
2 files changed, 7 insertions, 2 deletions
diff --git a/llvm/include/llvm/Support/ErrorOr.h b/llvm/include/llvm/Support/ErrorOr.h index 3577a12cec3..589404f9b4e 100644 --- a/llvm/include/llvm/Support/ErrorOr.h +++ b/llvm/include/llvm/Support/ErrorOr.h @@ -281,8 +281,8 @@ template <class T, class E> typename std::enable_if<std::is_error_code_enum<E>::value || std::is_error_condition_enum<E>::value, bool>::type -operator==(ErrorOr<T> &Err, E Code) { - return std::error_code(Err) == Code; +operator==(const ErrorOr<T> &Err, E Code) { + return Err.getError() == Code; } } // end namespace llvm diff --git a/llvm/unittests/Support/ErrorOrTest.cpp b/llvm/unittests/Support/ErrorOrTest.cpp index 82bbe090960..5e8d442a703 100644 --- a/llvm/unittests/Support/ErrorOrTest.cpp +++ b/llvm/unittests/Support/ErrorOrTest.cpp @@ -66,6 +66,11 @@ TEST(ErrorOr, Covariant) { ErrorOr<std::unique_ptr<int>> b4(b3); } +TEST(ErrorOr, Comparison) { + ErrorOr<int> x(std::errc::no_such_file_or_directory); + EXPECT_EQ(x, std::errc::no_such_file_or_directory); +} + // ErrorOr<int*> x(nullptr); // ErrorOr<std::unique_ptr<int>> y = x; // invalid conversion static_assert( |

