From b86942cca4b8f14d34ab290b28767235165fddca Mon Sep 17 00:00:00 2001 From: "Michael J. Spencer" Date: Thu, 21 May 2015 23:15:00 +0000 Subject: [PATCH] [Support] Fix ErrorOr equality operator. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237970 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/ErrorOr.h | 4 ++-- unittests/Support/ErrorOrTest.cpp | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/llvm/Support/ErrorOr.h b/include/llvm/Support/ErrorOr.h index 3577a12cec3..589404f9b4e 100644 --- a/include/llvm/Support/ErrorOr.h +++ b/include/llvm/Support/ErrorOr.h @@ -281,8 +281,8 @@ template typename std::enable_if::value || std::is_error_condition_enum::value, bool>::type -operator==(ErrorOr &Err, E Code) { - return std::error_code(Err) == Code; +operator==(const ErrorOr &Err, E Code) { + return Err.getError() == Code; } } // end namespace llvm diff --git a/unittests/Support/ErrorOrTest.cpp b/unittests/Support/ErrorOrTest.cpp index 82bbe090960..5e8d442a703 100644 --- a/unittests/Support/ErrorOrTest.cpp +++ b/unittests/Support/ErrorOrTest.cpp @@ -66,6 +66,11 @@ TEST(ErrorOr, Covariant) { ErrorOr> b4(b3); } +TEST(ErrorOr, Comparison) { + ErrorOr x(std::errc::no_such_file_or_directory); + EXPECT_EQ(x, std::errc::no_such_file_or_directory); +} + // ErrorOr x(nullptr); // ErrorOr> y = x; // invalid conversion static_assert( -- 2.34.1