diff options
| author | Nick Lewycky <nicholas@mxc.ca> | 2016-02-09 04:47:58 +0000 |
|---|---|---|
| committer | Nick Lewycky <nicholas@mxc.ca> | 2016-02-09 04:47:58 +0000 |
| commit | e5fa25a094f040353891a953d0b35a89d75e5cb8 (patch) | |
| tree | d08f6700fb62e6e96bc591e185771d369203acef /llvm/unittests/Support/ErrorOrTest.cpp | |
| parent | 38fc9fe19732465eca9d6fabb1a2d51ad1e2cb93 (diff) | |
| download | llvm-e5fa25a094f040353891a953d0b35a89d75e5cb8.zip llvm-e5fa25a094f040353891a953d0b35a89d75e5cb8.tar.gz llvm-e5fa25a094f040353891a953d0b35a89d75e5cb8.tar.bz2 | |
Use std::forward to make ErrorOr<T> constructible from a value that has a user-defined conversion to T. No functionality change intended.
llvm-svn: 260196
Diffstat (limited to 'llvm/unittests/Support/ErrorOrTest.cpp')
| -rw-r--r-- | llvm/unittests/Support/ErrorOrTest.cpp | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/llvm/unittests/Support/ErrorOrTest.cpp b/llvm/unittests/Support/ErrorOrTest.cpp index 73d0e3f..87dcab7 100644 --- a/llvm/unittests/Support/ErrorOrTest.cpp +++ b/llvm/unittests/Support/ErrorOrTest.cpp @@ -16,7 +16,7 @@ using namespace llvm; namespace { -ErrorOr<int> t1() {return 1;} +ErrorOr<int> t1() { return 1; } ErrorOr<int> t2() { return errc::invalid_argument; } TEST(ErrorOr, SimpleValue) { @@ -71,6 +71,46 @@ TEST(ErrorOr, Comparison) { EXPECT_EQ(x, errc::no_such_file_or_directory); } +TEST(ErrorOr, ImplicitConversion) { + ErrorOr<std::string> x("string literal"); + EXPECT_TRUE(!!x); +} + +TEST(ErrorOr, ImplicitConversionCausesMove) { + struct Source {}; + struct Destination { + Destination(const Source&) {} + Destination(Source&&) = delete; + }; + Source s; + ErrorOr<Destination> x = s; + EXPECT_TRUE(!!x); +} + +TEST(ErrorOr, ImplicitConversionNoAmbiguity) { + struct CastsToErrorCode { + CastsToErrorCode() = default; + CastsToErrorCode(std::error_code) {} + operator std::error_code() { return errc::invalid_argument; } + } casts_to_error_code; + ErrorOr<CastsToErrorCode> x1(casts_to_error_code); + ErrorOr<CastsToErrorCode> x2 = casts_to_error_code; + ErrorOr<CastsToErrorCode> x3 = {casts_to_error_code}; + ErrorOr<CastsToErrorCode> x4{casts_to_error_code}; + ErrorOr<CastsToErrorCode> x5(errc::no_such_file_or_directory); + ErrorOr<CastsToErrorCode> x6 = errc::no_such_file_or_directory; + ErrorOr<CastsToErrorCode> x7 = {errc::no_such_file_or_directory}; + ErrorOr<CastsToErrorCode> x8{errc::no_such_file_or_directory}; + EXPECT_TRUE(!!x1); + EXPECT_TRUE(!!x2); + EXPECT_TRUE(!!x3); + EXPECT_TRUE(!!x4); + EXPECT_FALSE(x5); + EXPECT_FALSE(x6); + EXPECT_FALSE(x7); + EXPECT_FALSE(x8); +} + // ErrorOr<int*> x(nullptr); // ErrorOr<std::unique_ptr<int>> y = x; // invalid conversion static_assert( |
