summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2016-04-25 19:21:57 +0000
committerLang Hames <lhames@gmail.com>2016-04-25 19:21:57 +0000
commit285639f803e85dc00f03575cf1944464af745385 (patch)
tree1aed0ff3c1b6e43c054810c3a4190781cba962d1 /llvm/unittests/Support
parent58ebc66e98ff3289b3fd8fcb7ffe21500a3f567d (diff)
downloadbcm5719-llvm-285639f803e85dc00f03575cf1944464af745385.tar.gz
bcm5719-llvm-285639f803e85dc00f03575cf1944464af745385.zip
[Support] Fix latent bugs in Expected and ExitOnError that were preventing them
from working with reference types. llvm-svn: 267448
Diffstat (limited to 'llvm/unittests/Support')
-rw-r--r--llvm/unittests/Support/ErrorTest.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/unittests/Support/ErrorTest.cpp b/llvm/unittests/Support/ErrorTest.cpp
index 6a1400aa540..f7e3b398c87 100644
--- a/llvm/unittests/Support/ErrorTest.cpp
+++ b/llvm/unittests/Support/ErrorTest.cpp
@@ -391,6 +391,10 @@ TEST(Error, ExitOnError) {
EXPECT_EQ(ExitOnErr(Expected<int>(7)), 7)
<< "exitOnError returned an invalid value for Expected";
+ int A = 7;
+ int &B = ExitOnErr(Expected<int&>(A));
+ EXPECT_EQ(&A, &B) << "ExitOnError failed to propagate reference";
+
// Exit tests.
EXPECT_EXIT(ExitOnErr(make_error<CustomError>(7)),
::testing::ExitedWithCode(1), "Error in tool:")
@@ -409,6 +413,16 @@ TEST(Error, CheckedExpectedInSuccessMode) {
EXPECT_EQ(*A, 7) << "Incorrect Expected non-error value";
}
+// Test Expected with reference type.
+TEST(Error, ExpectedWithReferenceType) {
+ int A = 7;
+ Expected<int&> B = A;
+ // 'Check' B.
+ (void)!!B;
+ int &C = *B;
+ EXPECT_EQ(&A, &C) << "Expected failed to propagate reference";
+}
+
// Test Unchecked Expected<T> in success mode.
// We expect this to blow up the same way Error would.
// Test runs in debug mode only.
OpenPOWER on IntegriCloud