summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/Support/Error.h7
-rw-r--r--llvm/unittests/Support/ErrorTest.cpp6
2 files changed, 13 insertions, 0 deletions
diff --git a/llvm/include/llvm/Support/Error.h b/llvm/include/llvm/Support/Error.h
index 3eb254cbc51..f96e02ca790 100644
--- a/llvm/include/llvm/Support/Error.h
+++ b/llvm/include/llvm/Support/Error.h
@@ -143,6 +143,13 @@ public:
/// constructor, but should be preferred for readability where possible.
static Error success() { return Error(); }
+ /// Create a 'pre-checked' success value suitable for use as an out-parameter.
+ static Error errorForOutParameter() {
+ Error Err;
+ (void)!!Err;
+ return Err;
+ }
+
// Errors are not copy-constructable.
Error(const Error &Other) = delete;
diff --git a/llvm/unittests/Support/ErrorTest.cpp b/llvm/unittests/Support/ErrorTest.cpp
index 893bd6825bf..1a0dd441c1a 100644
--- a/llvm/unittests/Support/ErrorTest.cpp
+++ b/llvm/unittests/Support/ErrorTest.cpp
@@ -105,6 +105,12 @@ TEST(Error, UncheckedSuccess) {
}
#endif
+// Test that errors to be used as out parameters are implicitly checked (
+// and thus destruct quietly).
+TEST(Error, ErrorAsOutParameter) {
+ Error E = Error::errorForOutParameter();
+}
+
// Check that we abort on unhandled failure cases. (Force conversion to bool
// to make sure that we don't accidentally treat checked errors as handled).
// Test runs in debug mode only.
OpenPOWER on IntegriCloud