[llvm] [orc-rt] Add ErrorAsOutParameter convenience constructor. (PR #169467)

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 24 23:24:57 PST 2025


https://github.com/lhames created https://github.com/llvm/llvm-project/pull/169467

Allows construction of ErrorAsOutParameters from Error references.

>From c571f9ae79033f355564ea991f752c1c1c75a3da Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at gmail.com>
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<T>' method handling.
 TEST(ErrorTest, IsAHandling) {
   // Check 'isA' handling.



More information about the llvm-commits mailing list