From 416f101111e06339387ac456c288cb5e60f41bc1 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Tue, 24 Sep 2024 23:01:45 -0700 Subject: [PATCH] [clang] Use std::optional::value_or (NFC) (#109894) --- clang/include/clang/AST/PropertiesBase.td | 2 +- clang/include/clang/Basic/FileManager.h | 2 +- clang/lib/APINotes/APINotesYAMLCompiler.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/AST/PropertiesBase.td b/clang/include/clang/AST/PropertiesBase.td index 9b934b20cf25..3057669e3758 100644 --- a/clang/include/clang/AST/PropertiesBase.td +++ b/clang/include/clang/AST/PropertiesBase.td @@ -39,7 +39,7 @@ class EnumPropertyType : PropertyType {} /// Supports optional values by using the null representation. class RefPropertyType : PropertyType { let PackOptional = - "value ? *value : nullptr"; + "value.value_or(nullptr)"; let UnpackOptional = "value ? std::optional<" # CXXName # ">(value) : std::nullopt"; } diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h index 527bbef24793..74029a91d1a6 100644 --- a/clang/include/clang/Basic/FileManager.h +++ b/clang/include/clang/Basic/FileManager.h @@ -293,7 +293,7 @@ public: bool RequiresNullTerminator = true, std::optional MaybeLimit = std::nullopt) const { return getBufferForFileImpl(Filename, - /*FileSize=*/(MaybeLimit ? *MaybeLimit : -1), + /*FileSize=*/MaybeLimit.value_or(-1), isVolatile, RequiresNullTerminator); } diff --git a/clang/lib/APINotes/APINotesYAMLCompiler.cpp b/clang/lib/APINotes/APINotesYAMLCompiler.cpp index 16fd59244086..f72a1d65b545 100644 --- a/clang/lib/APINotes/APINotesYAMLCompiler.cpp +++ b/clang/lib/APINotes/APINotesYAMLCompiler.cpp @@ -757,8 +757,8 @@ public: OutInfo.addTypeInfo(idx++, N); audited = Nullability.size() > 0 || ReturnNullability; if (audited) - OutInfo.addTypeInfo(0, ReturnNullability ? *ReturnNullability - : NullabilityKind::NonNull); + OutInfo.addTypeInfo(0, + ReturnNullability.value_or(NullabilityKind::NonNull)); if (!audited) return; OutInfo.NullabilityAudited = audited;