From c571f9ae79033f355564ea991f752c1c1c75a3da Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Tue, 25 Nov 2025 17:19:16 +1100 Subject: [PATCH] [orc-rt] Add ErrorAsOutParameter convenience constructor. Allows construction of ErrorAsOutParameters from Error references. --- orc-rt/include/orc-rt/Error.h | 2 ++ orc-rt/unittests/ErrorTest.cpp | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/orc-rt/include/orc-rt/Error.h b/orc-rt/include/orc-rt/Error.h index 48d9064440b6d..a316e1934f671 100644 --- a/orc-rt/include/orc-rt/Error.h +++ b/orc-rt/include/orc-rt/Error.h @@ -278,6 +278,8 @@ class ErrorAsOutParameter { (void)!!*Err; } + ErrorAsOutParameter(Error &Err) : Err(&Err) { (void)!!Err; } + ~ErrorAsOutParameter() { // Clear the checked bit. if (Err && !*Err) diff --git a/orc-rt/unittests/ErrorTest.cpp b/orc-rt/unittests/ErrorTest.cpp index 260b6afc2ae95..d80ada9529696 100644 --- a/orc-rt/unittests/ErrorTest.cpp +++ b/orc-rt/unittests/ErrorTest.cpp @@ -257,6 +257,15 @@ TEST(ErrorTest, ErrorAsOutParameterUnchecked) { << "ErrorAsOutParameter did not clear the checked flag on destruction."; } +// Test that we can construct an ErrorAsOutParameter from an Error&. +TEST(ErrorTest, ErrorAsOutParameterRefConstructor) { + Error E = Error::success(); + { + ErrorAsOutParameter _(E); // construct with Error&. + } + (void)!!E; +} + // Check 'Error::isA' method handling. TEST(ErrorTest, IsAHandling) { // Check 'isA' handling.