[llvm] [orc-rt] Fix unused Expected::isFailureOfType, add testcase. (PR #207105)
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 1 18:03:31 PDT 2026
https://github.com/lhames created https://github.com/llvm/llvm-project/pull/207105
Expected::isFailureOfType method template was calling a non-existant Error::isFailureOfType method, but didn't trigger any compile errors as isFailureOfType was unused. This commit fixes isFailureOfType and adds a testcase to exercise it.
>From 51a0a257c5c528ca4e83afe30b3626c24d644623 Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at gmail.com>
Date: Thu, 2 Jul 2026 10:53:37 +1000
Subject: [PATCH] [orc-rt] Fix unused Expected::isFailureOfType, add testcase.
Expected::isFailureOfType method template was calling a non-existant
Error::isFailureOfType method, but didn't trigger any compile errors as
isFailureOfType was unused. This commit fixes isFailureOfType and adds a
testcase to exercise it.
---
orc-rt/include/orc-rt/Error.h | 2 +-
orc-rt/unittests/ErrorTest.cpp | 22 ++++++++++++++++++++++
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/orc-rt/include/orc-rt/Error.h b/orc-rt/include/orc-rt/Error.h
index 92cbd22d12ecc..eecd836dc58d6 100644
--- a/orc-rt/include/orc-rt/Error.h
+++ b/orc-rt/include/orc-rt/Error.h
@@ -437,7 +437,7 @@ template <typename T> class ORC_RT_NODISCARD Expected {
/// Returns true if this Expected value holds an Error of type error_type.
template <typename ErrT> bool isFailureOfType() const {
- return HasError && (*getErrorStorage())->template isFailureOfType<ErrT>();
+ return HasError && (*getErrorStorage())->template isA<ErrT>();
}
/// Take ownership of the stored error.
diff --git a/orc-rt/unittests/ErrorTest.cpp b/orc-rt/unittests/ErrorTest.cpp
index 3da138c1c4ca8..2ba9ff5ca9abd 100644
--- a/orc-rt/unittests/ErrorTest.cpp
+++ b/orc-rt/unittests/ErrorTest.cpp
@@ -370,6 +370,28 @@ TEST(ErrorTest, ExpectedInFailureMode) {
consumeError(std::move(E));
}
+// Check Expected<T>::isFailureOfType classifies success and failure values
+// correctly, including polymorphic matches through the RTTI hierarchy.
+TEST(ErrorTest, ExpectedIsFailureOfType) {
+ // Success value: isFailureOfType returns false for any type.
+ Expected<int> Success(42);
+ EXPECT_FALSE(Success.isFailureOfType<CustomError>());
+ EXPECT_FALSE(Success.isFailureOfType<CustomSubError>());
+ EXPECT_TRUE(!!Success);
+
+ // Failure with base type: matches only the base type.
+ Expected<int> WithBase = make_error<CustomError>(42);
+ EXPECT_TRUE(WithBase.isFailureOfType<CustomError>());
+ EXPECT_FALSE(WithBase.isFailureOfType<CustomSubError>());
+ consumeError(WithBase.takeError());
+
+ // Failure with derived type: matches both derived and base via isA.
+ Expected<int> WithDerived = make_error<CustomSubError>(43, "sub");
+ EXPECT_TRUE(WithDerived.isFailureOfType<CustomError>());
+ EXPECT_TRUE(WithDerived.isFailureOfType<CustomSubError>());
+ consumeError(WithDerived.takeError());
+}
+
// Check that an Expected instance with an error value doesn't allow access to
// operator*.
// Test runs in debug mode only.
More information about the llvm-commits
mailing list