mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-14 07:31:53 +00:00
[Support] Add Error::errorForOutParameter helper.
This helper method creates a pre-checked Error suitable for use as an out parameter in a constructor. This avoids the need to have the constructor check a known-good error before assigning to it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@264467 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
4b3682d24a
commit
d65658e8aa
@ -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;
|
||||
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user