[Lldb-commits] [lldb] 52a250e - [NFC] Replace `expectedToStdOptional` with `expectedToOptional` (#191359)
via lldb-commits
lldb-commits at lists.llvm.org
Mon Apr 13 07:39:46 PDT 2026
Author: Juan Manuel Martinez CaamaƱo
Date: 2026-04-13T16:39:41+02:00
New Revision: 52a250ea1b8d6b34da4e437d89dda246d5e87e6f
URL: https://github.com/llvm/llvm-project/commit/52a250ea1b8d6b34da4e437d89dda246d5e87e6f
DIFF: https://github.com/llvm/llvm-project/commit/52a250ea1b8d6b34da4e437d89dda246d5e87e6f.diff
LOG: [NFC] Replace `expectedToStdOptional` with `expectedToOptional` (#191359)
Both implementations are currently equivalent. This is likely a leftover
from the past, when `llvm::Optional` existed.
Added:
Modified:
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
lldb/source/Symbol/Variable.cpp
lldb/source/ValueObject/ValueObject.cpp
llvm/include/llvm/Support/Error.h
llvm/tools/llvm-readobj/ELFDumper.cpp
Removed:
################################################################################
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 9c5fdea8d5443..e63d247c01d11 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -6355,8 +6355,8 @@ llvm::Expected<CompilerType> TypeSystemClang::GetChildCompilerTypeAtIndex(
if (omit_empty_base_classes) {
CompilerType base_class_clang_type = GetType(
getASTContext().getObjCInterfaceType(superclass_interface_decl));
- if (llvm::expectedToStdOptional(base_class_clang_type.GetNumChildren(
- omit_empty_base_classes, exe_ctx))
+ if (llvm::expectedToOptional(base_class_clang_type.GetNumChildren(
+ omit_empty_base_classes, exe_ctx))
.value_or(0) > 0) {
if (idx == 0) {
clang::QualType ivar_qual_type(getASTContext().getObjCInterfaceType(
diff --git a/lldb/source/Symbol/Variable.cpp b/lldb/source/Symbol/Variable.cpp
index 172da9465b16b..336861afbf4bc 100644
--- a/lldb/source/Symbol/Variable.cpp
+++ b/lldb/source/Symbol/Variable.cpp
@@ -578,7 +578,7 @@ static void PrivateAutoComplete(
case eTypeClassObjCObjectPointer:
case eTypeClassPointer: {
bool omit_empty_base_classes = true;
- if (llvm::expectedToStdOptional(
+ if (llvm::expectedToOptional(
compiler_type.GetNumChildren(omit_empty_base_classes, nullptr))
.value_or(0))
request.AddCompletion((prefix_path + "->").str());
diff --git a/lldb/source/ValueObject/ValueObject.cpp b/lldb/source/ValueObject/ValueObject.cpp
index 37210055af6e9..6a12a2e45b2e1 100644
--- a/lldb/source/ValueObject/ValueObject.cpp
+++ b/lldb/source/ValueObject/ValueObject.cpp
@@ -2522,7 +2522,7 @@ ValueObjectSP ValueObject::GetValueForExpressionPath_Impl(
child_valobj_sp = root->GetSyntheticArrayMember(index, true);
if (!child_valobj_sp)
if (root->HasSyntheticValue() &&
- llvm::expectedToStdOptional(
+ llvm::expectedToOptional(
root->GetSyntheticValue()->GetNumChildren())
.value_or(0) > index)
child_valobj_sp =
diff --git a/llvm/include/llvm/Support/Error.h b/llvm/include/llvm/Support/Error.h
index 536bebf5a3ea6..3511a4e080641 100644
--- a/llvm/include/llvm/Support/Error.h
+++ b/llvm/include/llvm/Support/Error.h
@@ -1107,13 +1107,13 @@ inline void consumeError(Error Err) {
handleAllErrors(std::move(Err), [](const ErrorInfoBase &) {});
}
-/// Convert an Expected to an Optional without doing anything. This method
+/// Convert an Expected to an std::optional without doing anything. This method
/// should be used only where an error can be considered a reasonable and
/// expected return value.
///
/// Uses of this method are potentially indicative of problems: perhaps the
/// error should be propagated further, or the error-producer should just
-/// return an Optional in the first place.
+/// return an std::optional in the first place.
template <typename T> std::optional<T> expectedToOptional(Expected<T> &&E) {
if (E)
return std::move(*E);
@@ -1121,13 +1121,6 @@ template <typename T> std::optional<T> expectedToOptional(Expected<T> &&E) {
return std::nullopt;
}
-template <typename T> std::optional<T> expectedToStdOptional(Expected<T> &&E) {
- if (E)
- return std::move(*E);
- consumeError(E.takeError());
- return std::nullopt;
-}
-
/// Helper for converting an Error to a bool.
///
/// This method returns true if Err is in an error state, or false if it is
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index aff02dd69a90e..80ef7b91bf06f 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -6362,7 +6362,7 @@ static void processNotesHelper(
for (const typename ELFT::Shdr &S : Sections) {
if (S.sh_type != SHT_NOTE)
continue;
- StartNotesFn(expectedToStdOptional(Obj.getSectionName(S)), S.sh_offset,
+ StartNotesFn(expectedToOptional(Obj.getSectionName(S)), S.sh_offset,
S.sh_size, S.sh_addralign);
Error Err = Error::success();
size_t I = 0;
More information about the lldb-commits
mailing list