From b4fc5754fd3e39773562390fe11cea85ab7ea8bb Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Sat, 16 Nov 2024 23:48:43 +0100 Subject: [PATCH] Cleanup: avoid constructing std::string from nullptr This probably never in practice in these cases. Constructing a `std::string` from nullptr is invalid. Starting with C++23, the `nullptr_t` is even explicitly deleted. --- source/blender/blenkernel/intern/key.cc | 2 +- source/blender/editors/space_node/node_draw.cc | 7 ++++--- source/blender/nodes/NOD_node_declaration.hh | 7 ++++--- source/blender/nodes/intern/node_declaration.cc | 3 ++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/source/blender/blenkernel/intern/key.cc b/source/blender/blenkernel/intern/key.cc index e530ccf3879..659543bc41e 100644 --- a/source/blender/blenkernel/intern/key.cc +++ b/source/blender/blenkernel/intern/key.cc @@ -1958,7 +1958,7 @@ void BKE_keyblock_copy_settings(KeyBlock *kb_dst, const KeyBlock *kb_src) std::optional BKE_keyblock_curval_rnapath_get(const Key *key, const KeyBlock *kb) { if (ELEM(nullptr, key, kb)) { - return nullptr; + return std::nullopt; } PointerRNA ptr = RNA_pointer_create((ID *)&key->id, &RNA_ShapeKey, (KeyBlock *)kb); PropertyRNA *prop = RNA_struct_find_property(&ptr, "value"); diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index a4552daae89..d6396b2fc89 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -231,14 +231,15 @@ static const char *node_socket_get_translation_context(const bNodeSocket &socket return nullptr; } - blender::StringRefNull translation_context = socket.runtime->declaration->translation_context; + const std::optional &translation_context = + socket.runtime->declaration->translation_context; /* Default context. */ - if (translation_context.is_empty()) { + if (!translation_context.has_value()) { return nullptr; } - return translation_context.data(); + return translation_context->c_str(); } static void node_socket_add_tooltip_in_node_editor(const bNodeSocket &sock, uiLayout &layout); diff --git a/source/blender/nodes/NOD_node_declaration.hh b/source/blender/nodes/NOD_node_declaration.hh index 07edf840997..98345440c73 100644 --- a/source/blender/nodes/NOD_node_declaration.hh +++ b/source/blender/nodes/NOD_node_declaration.hh @@ -173,7 +173,7 @@ class SocketDeclaration : public ItemDeclaration { std::string short_label; std::string identifier; std::string description; - std::string translation_context; + std::optional translation_context; /** Defined by whether the socket is part of the node's input or * output socket declaration list. Included here for convenience. */ eNodeSocketInOut in_out; @@ -284,7 +284,8 @@ class BaseSocketDeclarationBuilder { BaseSocketDeclarationBuilder &description(std::string value = ""); - BaseSocketDeclarationBuilder &translation_context(std::string value = BLT_I18NCONTEXT_DEFAULT); + BaseSocketDeclarationBuilder &translation_context( + std::optional value = std::nullopt); BaseSocketDeclarationBuilder &no_muted_links(bool value = true); @@ -437,7 +438,7 @@ class PanelDeclaration : public ItemDeclaration { int identifier; std::string name; std::string description; - std::string translation_context; + std::optional translation_context; bool default_collapsed = false; Vector items; /** Index in the list of panels on the node. */ diff --git a/source/blender/nodes/intern/node_declaration.cc b/source/blender/nodes/intern/node_declaration.cc index 3ca4826d258..3a86124f9f3 100644 --- a/source/blender/nodes/intern/node_declaration.cc +++ b/source/blender/nodes/intern/node_declaration.cc @@ -586,7 +586,8 @@ BaseSocketDeclarationBuilder &BaseSocketDeclarationBuilder::description(std::str return *this; } -BaseSocketDeclarationBuilder &BaseSocketDeclarationBuilder::translation_context(std::string value) +BaseSocketDeclarationBuilder &BaseSocketDeclarationBuilder::translation_context( + std::optional value) { decl_base_->translation_context = std::move(value); return *this;