Browse Source

Use `std::size` instead of `sizeof(a) / sizeof(a[0])` pattern throughout the codebase.

Lukas Tenbrink 5 months ago
parent
commit
e34f1f504c

+ 3 - 1
core/error/error_list.cpp

@@ -30,6 +30,8 @@
 
 
 #include "error_list.h"
 #include "error_list.h"
 
 
+#include <iterator>
+
 const char *error_names[] = {
 const char *error_names[] = {
 	"OK", // OK
 	"OK", // OK
 	"Failed", // FAILED
 	"Failed", // FAILED
@@ -82,4 +84,4 @@ const char *error_names[] = {
 	"Printer on fire", // ERR_PRINTER_ON_FIRE
 	"Printer on fire", // ERR_PRINTER_ON_FIRE
 };
 };
 
 
-static_assert(sizeof(error_names) / sizeof(*error_names) == ERR_MAX);
+static_assert(std::size(error_names) == ERR_MAX);

+ 1 - 1
core/input/input_map.cpp

@@ -407,7 +407,7 @@ static const _BuiltinActionDisplayName _builtin_action_display_names[] = {
 };
 };
 
 
 String InputMap::get_builtin_display_name(const String &p_name) const {
 String InputMap::get_builtin_display_name(const String &p_name) const {
-	int len = sizeof(_builtin_action_display_names) / sizeof(_BuiltinActionDisplayName);
+	constexpr int len = std::size(_builtin_action_display_names);
 
 
 	for (int i = 0; i < len; i++) {
 	for (int i = 0; i < len; i++) {
 		if (_builtin_action_display_names[i].name == p_name) {
 		if (_builtin_action_display_names[i].name == p_name) {

+ 1 - 1
core/io/file_access.cpp

@@ -429,7 +429,7 @@ class CharBuffer {
 public:
 public:
 	_FORCE_INLINE_ CharBuffer() :
 	_FORCE_INLINE_ CharBuffer() :
 			buffer(stack_buffer),
 			buffer(stack_buffer),
-			capacity(sizeof(stack_buffer) / sizeof(char)) {
+			capacity(std::size(stack_buffer)) {
 	}
 	}
 
 
 	_FORCE_INLINE_ void push_back(char c) {
 	_FORCE_INLINE_ void push_back(char c) {

+ 1 - 1
core/io/resource_uid.cpp

@@ -46,7 +46,7 @@ String ResourceUID::get_cache_file() {
 }
 }
 
 
 static constexpr uint8_t uuid_characters[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', '0', '1', '2', '3', '4', '5', '6', '7', '8' };
 static constexpr uint8_t uuid_characters[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', '0', '1', '2', '3', '4', '5', '6', '7', '8' };
-static constexpr uint32_t uuid_characters_element_count = (sizeof(uuid_characters) / sizeof(*uuid_characters));
+static constexpr uint32_t uuid_characters_element_count = std::size(uuid_characters);
 static constexpr uint8_t max_uuid_number_length = 13; // Max 0x7FFFFFFFFFFFFFFF (uid://d4n4ub6itg400) size is 13 characters.
 static constexpr uint8_t max_uuid_number_length = 13; // Max 0x7FFFFFFFFFFFFFFF (uid://d4n4ub6itg400) size is 13 characters.
 
 
 String ResourceUID::id_to_text(ID p_id) const {
 String ResourceUID::id_to_text(ID p_id) const {

+ 1 - 1
core/math/color.cpp

@@ -439,7 +439,7 @@ int Color::find_named_color(const String &p_name) {
 }
 }
 
 
 int Color::get_named_color_count() {
 int Color::get_named_color_count() {
-	return sizeof(named_colors) / sizeof(NamedColor);
+	return std::size(named_colors);
 }
 }
 
 
 String Color::get_named_color_name(int p_idx) {
 String Color::get_named_color_name(int p_idx) {

+ 19 - 17
core/string/char_utils.h

@@ -35,23 +35,25 @@
 
 
 #include "char_range.inc"
 #include "char_range.inc"
 
 
-#define BSEARCH_CHAR_RANGE(m_array)                      \
-	int low = 0;                                         \
-	int high = sizeof(m_array) / sizeof(m_array[0]) - 1; \
-	int middle = (low + high) / 2;                       \
-                                                         \
-	while (low <= high) {                                \
-		if (p_char < m_array[middle].start) {            \
-			high = middle - 1;                           \
-		} else if (p_char > m_array[middle].end) {       \
-			low = middle + 1;                            \
-		} else {                                         \
-			return true;                                 \
-		}                                                \
-                                                         \
-		middle = (low + high) / 2;                       \
-	}                                                    \
-                                                         \
+#include <iterator>
+
+#define BSEARCH_CHAR_RANGE(m_array)                \
+	int low = 0;                                   \
+	int high = std::size(m_array) - 1;             \
+	int middle = (low + high) / 2;                 \
+                                                   \
+	while (low <= high) {                          \
+		if (p_char < m_array[middle].start) {      \
+			high = middle - 1;                     \
+		} else if (p_char > m_array[middle].end) { \
+			low = middle + 1;                      \
+		} else {                                   \
+			return true;                           \
+		}                                          \
+                                                   \
+		middle = (low + high) / 2;                 \
+	}                                              \
+                                                   \
 	return false
 	return false
 
 
 constexpr bool is_unicode_identifier_start(char32_t p_char) {
 constexpr bool is_unicode_identifier_start(char32_t p_char) {

+ 1 - 1
core/string/translation_domain.cpp

@@ -182,7 +182,7 @@ const char32_t *TranslationDomain::_get_accented_version(char32_t p_character) c
 		return nullptr;
 		return nullptr;
 	}
 	}
 
 
-	for (unsigned int i = 0; i < sizeof(_character_to_accented) / sizeof(_character_to_accented[0]); i++) {
+	for (unsigned int i = 0; i < std::size(_character_to_accented); i++) {
 		if (_character_to_accented[i].character == p_character) {
 		if (_character_to_accented[i].character == p_character) {
 			return _character_to_accented[i].accented_character;
 			return _character_to_accented[i].accented_character;
 		}
 		}

+ 1 - 1
drivers/d3d12/rendering_context_driver_d3d12.h

@@ -86,7 +86,7 @@
 
 
 using Microsoft::WRL::ComPtr;
 using Microsoft::WRL::ComPtr;
 
 
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
+#define ARRAY_SIZE(a) std::size(a)
 
 
 class RenderingContextDriverD3D12 : public RenderingContextDriver {
 class RenderingContextDriverD3D12 : public RenderingContextDriver {
 	ComPtr<ID3D12DeviceFactory> device_factory;
 	ComPtr<ID3D12DeviceFactory> device_factory;

+ 1 - 1
drivers/vulkan/rendering_device_driver_vulkan.cpp

@@ -45,7 +45,7 @@
 #include "thirdparty/swappy-frame-pacing/swappyVk.h"
 #include "thirdparty/swappy-frame-pacing/swappyVk.h"
 #endif
 #endif
 
 
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
+#define ARRAY_SIZE(a) std::size(a)
 
 
 #define PRINT_NATIVE_COMMANDS 0
 #define PRINT_NATIVE_COMMANDS 0
 
 

+ 1 - 1
editor/code_editor.cpp

@@ -1917,7 +1917,7 @@ CodeTextEditor::CodeTextEditor() {
 	zoom_button->set_text("100 %");
 	zoom_button->set_text("100 %");
 
 
 	PopupMenu *zoom_menu = zoom_button->get_popup();
 	PopupMenu *zoom_menu = zoom_button->get_popup();
-	int preset_count = sizeof(ZOOM_FACTOR_PRESETS) / sizeof(float);
+	constexpr int preset_count = std::size(ZOOM_FACTOR_PRESETS);
 
 
 	for (int i = 0; i < preset_count; i++) {
 	for (int i = 0; i < preset_count; i++) {
 		float z = ZOOM_FACTOR_PRESETS[i];
 		float z = ZOOM_FACTOR_PRESETS[i];

+ 1 - 1
editor/plugins/animation_state_machine_editor.cpp

@@ -929,7 +929,7 @@ void AnimationNodeStateMachineEditor::_connection_draw(const Vector2 &p_from, co
 		state_machine_draw->draw_line(p_from, p_from.lerp(p_to, p_fade_ratio), fade_line_color, 2);
 		state_machine_draw->draw_line(p_from, p_from.lerp(p_to, p_fade_ratio), fade_line_color, 2);
 	}
 	}
 
 
-	const int ICON_COUNT = sizeof(theme_cache.transition_icons) / sizeof(*theme_cache.transition_icons);
+	const int ICON_COUNT = std::size(theme_cache.transition_icons);
 	int icon_index = p_mode + (p_auto_advance ? ICON_COUNT / 2 : 0);
 	int icon_index = p_mode + (p_auto_advance ? ICON_COUNT / 2 : 0);
 	ERR_FAIL_COND(icon_index >= ICON_COUNT);
 	ERR_FAIL_COND(icon_index >= ICON_COUNT);
 	Ref<Texture2D> icon = theme_cache.transition_icons[icon_index];
 	Ref<Texture2D> icon = theme_cache.transition_icons[icon_index];

+ 1 - 1
editor/plugins/visual_shader_editor_plugin.cpp

@@ -89,7 +89,7 @@ static FloatConstantDef float_constant_defs[] = {
 	{ "Sqrt2", Math_SQRT2, TTRC("Sqrt2 constant (1.414214). Square root of 2.") }
 	{ "Sqrt2", Math_SQRT2, TTRC("Sqrt2 constant (1.414214). Square root of 2.") }
 };
 };
 
 
-const int MAX_FLOAT_CONST_DEFS = sizeof(float_constant_defs) / sizeof(FloatConstantDef);
+constexpr int MAX_FLOAT_CONST_DEFS = std::size(float_constant_defs);
 
 
 ///////////////////
 ///////////////////
 
 

+ 1 - 1
editor/themes/editor_fonts.cpp

@@ -159,7 +159,7 @@ void editor_register_fonts(const Ref<Theme> &p_theme) {
 	String noto_cjk_path;
 	String noto_cjk_path;
 	String noto_cjk_bold_path;
 	String noto_cjk_bold_path;
 	String var_suffix[] = { "HK", "KR", "SC", "TC", "JP" }; // Note: All Noto Sans CJK versions support all glyph variations, it should not match current locale.
 	String var_suffix[] = { "HK", "KR", "SC", "TC", "JP" }; // Note: All Noto Sans CJK versions support all glyph variations, it should not match current locale.
-	for (size_t i = 0; i < sizeof(var_suffix) / sizeof(String); i++) {
+	for (size_t i = 0; i < std::size(var_suffix); i++) {
 		if (noto_cjk_path.is_empty()) {
 		if (noto_cjk_path.is_empty()) {
 			noto_cjk_path = OS::get_singleton()->get_system_font_path("Noto Sans CJK " + var_suffix[i], 400, 100);
 			noto_cjk_path = OS::get_singleton()->get_system_font_path("Noto Sans CJK " + var_suffix[i], 400, 100);
 		}
 		}

+ 1 - 1
main/performance.cpp

@@ -152,7 +152,7 @@ String Performance::get_monitor_name(Monitor p_monitor) const {
 		PNAME("pipeline/compilations_draw"),
 		PNAME("pipeline/compilations_draw"),
 		PNAME("pipeline/compilations_specialization"),
 		PNAME("pipeline/compilations_specialization"),
 	};
 	};
-	static_assert((sizeof(names) / sizeof(const char *)) == MONITOR_MAX);
+	static_assert(std::size(names) == MONITOR_MAX);
 
 
 	return names[p_monitor];
 	return names[p_monitor];
 }
 }

+ 1 - 1
modules/gdscript/gdscript_parser.cpp

@@ -4129,7 +4129,7 @@ GDScriptParser::ParseRule *GDScriptParser::get_rule(GDScriptTokenizer::Token::Ty
 	};
 	};
 	/* clang-format on */
 	/* clang-format on */
 	// Avoid desync.
 	// Avoid desync.
-	static_assert(sizeof(rules) / sizeof(rules[0]) == GDScriptTokenizer::Token::TK_MAX, "Amount of parse rules don't match the amount of token types.");
+	static_assert(std::size(rules) == GDScriptTokenizer::Token::TK_MAX, "Amount of parse rules don't match the amount of token types.");
 
 
 	// Let's assume this is never invalid, since nothing generates a TK_MAX.
 	// Let's assume this is never invalid, since nothing generates a TK_MAX.
 	return &rules[p_token_type];
 	return &rules[p_token_type];

+ 1 - 1
modules/gdscript/gdscript_tokenizer.cpp

@@ -157,7 +157,7 @@ static const char *token_names[] = {
 };
 };
 
 
 // Avoid desync.
 // Avoid desync.
-static_assert(sizeof(token_names) / sizeof(token_names[0]) == GDScriptTokenizer::Token::TK_MAX, "Amount of token names don't match the amount of token types.");
+static_assert(std::size(token_names) == GDScriptTokenizer::Token::TK_MAX, "Amount of token names don't match the amount of token types.");
 
 
 const char *GDScriptTokenizer::Token::get_name() const {
 const char *GDScriptTokenizer::Token::get_name() const {
 	ERR_FAIL_INDEX_V_MSG(type, TK_MAX, "<error>", "Using token type out of the enum.");
 	ERR_FAIL_INDEX_V_MSG(type, TK_MAX, "<error>", "Using token type out of the enum.");

+ 1 - 1
modules/gdscript/gdscript_vm.cpp

@@ -387,7 +387,7 @@ void (*type_init_function_table[])(Variant *) = {
 		&&OPCODE_LINE,                                   \
 		&&OPCODE_LINE,                                   \
 		&&OPCODE_END                                     \
 		&&OPCODE_END                                     \
 	};                                                   \
 	};                                                   \
-	static_assert((sizeof(switch_table_ops) / sizeof(switch_table_ops[0]) == (OPCODE_END + 1)), "Opcodes in jump table aren't the same as opcodes in enum.");
+	static_assert(std::size(switch_table_ops) == (OPCODE_END + 1), "Opcodes in jump table aren't the same as opcodes in enum.");
 
 
 #define OPCODE(m_op) \
 #define OPCODE(m_op) \
 	m_op:
 	m_op:

+ 1 - 1
modules/gdscript/gdscript_warning.cpp

@@ -245,7 +245,7 @@ String GDScriptWarning::get_name_from_code(Code p_code) {
 #endif
 #endif
 	};
 	};
 
 
-	static_assert((sizeof(names) / sizeof(*names)) == WARNING_MAX, "Amount of warning types don't match the amount of warning names.");
+	static_assert(std::size(names) == WARNING_MAX, "Amount of warning types don't match the amount of warning names.");
 
 
 	return names[(int)p_code];
 	return names[(int)p_code];
 }
 }

+ 1 - 1
modules/gdscript/gdscript_warning.h

@@ -154,7 +154,7 @@ public:
 #endif
 #endif
 	};
 	};
 
 
-	static_assert((sizeof(default_warning_levels) / sizeof(default_warning_levels[0])) == WARNING_MAX, "Amount of default levels does not match the amount of warnings.");
+	static_assert(std::size(default_warning_levels) == WARNING_MAX, "Amount of default levels does not match the amount of warnings.");
 
 
 	Code code = WARNING_MAX;
 	Code code = WARNING_MAX;
 	int start_line = -1, end_line = -1;
 	int start_line = -1, end_line = -1;

+ 1 - 1
modules/mono/mono_gd/gd_mono.cpp

@@ -466,7 +466,7 @@ godot_plugins_initialize_fn initialize_coreclr_and_godot_plugins(bool &r_runtime
 	String tpa_list = make_tpa_list();
 	String tpa_list = make_tpa_list();
 	const char *prop_keys[] = { "TRUSTED_PLATFORM_ASSEMBLIES" };
 	const char *prop_keys[] = { "TRUSTED_PLATFORM_ASSEMBLIES" };
 	const char *prop_values[] = { tpa_list.utf8().get_data() };
 	const char *prop_values[] = { tpa_list.utf8().get_data() };
-	int nprops = sizeof(prop_keys) / sizeof(prop_keys[0]);
+	constexpr int nprops = std::size(prop_keys);
 
 
 	void *coreclr_handle = nullptr;
 	void *coreclr_handle = nullptr;
 	unsigned int domain_id = 0;
 	unsigned int domain_id = 0;

+ 1 - 1
platform/android/export/gradle_export_util.cpp

@@ -246,7 +246,7 @@ String _get_gles_tag() {
 String _get_screen_sizes_tag(const Ref<EditorExportPreset> &p_preset) {
 String _get_screen_sizes_tag(const Ref<EditorExportPreset> &p_preset) {
 	String manifest_screen_sizes = "    <supports-screens \n        tools:node=\"replace\"";
 	String manifest_screen_sizes = "    <supports-screens \n        tools:node=\"replace\"";
 	String sizes[] = { "small", "normal", "large", "xlarge" };
 	String sizes[] = { "small", "normal", "large", "xlarge" };
-	size_t num_sizes = sizeof(sizes) / sizeof(sizes[0]);
+	constexpr size_t num_sizes = std::size(sizes);
 	for (size_t i = 0; i < num_sizes; i++) {
 	for (size_t i = 0; i < num_sizes; i++) {
 		String feature_name = vformat("screen/support_%s", sizes[i]);
 		String feature_name = vformat("screen/support_%s", sizes[i]);
 		String feature_support = bool_to_string(p_preset->get(feature_name));
 		String feature_support = bool_to_string(p_preset->get(feature_name));

+ 8 - 8
platform/ios/export/export_plugin.cpp

@@ -351,7 +351,7 @@ void EditorExportPlatformIOS::get_export_options(List<ExportOption> *r_options)
 	r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/photolibrary_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need access to the photo library"), ""));
 	r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/photolibrary_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need access to the photo library"), ""));
 	r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/photolibrary_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
 	r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/photolibrary_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
 
 
-	for (uint64_t i = 0; i < sizeof(api_info) / sizeof(api_info[0]); ++i) {
+	for (uint64_t i = 0; i < std::size(api_info); ++i) {
 		String prop_name = vformat("privacy/%s_access_reasons", api_info[i].prop_name);
 		String prop_name = vformat("privacy/%s_access_reasons", api_info[i].prop_name);
 		String hint;
 		String hint;
 		for (int j = 0; j < api_info[i].prop_flag_value.size(); j++) {
 		for (int j = 0; j < api_info[i].prop_flag_value.size(); j++) {
@@ -368,13 +368,13 @@ void EditorExportPlatformIOS::get_export_options(List<ExportOption> *r_options)
 
 
 	{
 	{
 		String hint;
 		String hint;
-		for (uint64_t i = 0; i < sizeof(data_collect_purpose_info) / sizeof(data_collect_purpose_info[0]); ++i) {
+		for (uint64_t i = 0; i < std::size(data_collect_purpose_info); ++i) {
 			if (i != 0) {
 			if (i != 0) {
 				hint += ",";
 				hint += ",";
 			}
 			}
 			hint += vformat("%s:%d", data_collect_purpose_info[i].prop_name, (1 << i));
 			hint += vformat("%s:%d", data_collect_purpose_info[i].prop_name, (1 << i));
 		}
 		}
-		for (uint64_t i = 0; i < sizeof(data_collect_type_info) / sizeof(data_collect_type_info[0]); ++i) {
+		for (uint64_t i = 0; i < std::size(data_collect_type_info); ++i) {
 			r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/collected", data_collect_type_info[i].prop_name)), false));
 			r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/collected", data_collect_type_info[i].prop_name)), false));
 			r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/linked_to_user", data_collect_type_info[i].prop_name)), false));
 			r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/linked_to_user", data_collect_type_info[i].prop_name)), false));
 			r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/used_for_tracking", data_collect_type_info[i].prop_name)), false));
 			r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/used_for_tracking", data_collect_type_info[i].prop_name)), false));
@@ -387,7 +387,7 @@ void EditorExportPlatformIOS::get_export_options(List<ExportOption> *r_options)
 	r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/icon_1024x1024_tinted", PROPERTY_HINT_FILE, "*.svg,*.png,*.webp,*.jpg,*.jpeg"), ""));
 	r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/icon_1024x1024_tinted", PROPERTY_HINT_FILE, "*.svg,*.png,*.webp,*.jpg,*.jpeg"), ""));
 
 
 	HashSet<String> used_names;
 	HashSet<String> used_names;
-	for (uint64_t i = 0; i < sizeof(icon_infos) / sizeof(icon_infos[0]); ++i) {
+	for (uint64_t i = 0; i < std::size(icon_infos); ++i) {
 		if (!used_names.has(icon_infos[i].preset_key)) {
 		if (!used_names.has(icon_infos[i].preset_key)) {
 			used_names.insert(icon_infos[i].preset_key);
 			used_names.insert(icon_infos[i].preset_key);
 			r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, String(icon_infos[i].preset_key), PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
 			r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, String(icon_infos[i].preset_key), PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
@@ -765,7 +765,7 @@ void EditorExportPlatformIOS::_fix_config_file(const Ref<EditorExportPreset> &p_
 			strnew += lines[i].replace("$swift_runtime_build_phase", value) + "\n";
 			strnew += lines[i].replace("$swift_runtime_build_phase", value) + "\n";
 		} else if (lines[i].contains("$priv_collection")) {
 		} else if (lines[i].contains("$priv_collection")) {
 			bool section_opened = false;
 			bool section_opened = false;
-			for (uint64_t j = 0; j < sizeof(data_collect_type_info) / sizeof(data_collect_type_info[0]); ++j) {
+			for (uint64_t j = 0; j < std::size(data_collect_type_info); ++j) {
 				bool data_collected = p_preset->get(vformat("privacy/collected_data/%s/collected", data_collect_type_info[j].prop_name));
 				bool data_collected = p_preset->get(vformat("privacy/collected_data/%s/collected", data_collect_type_info[j].prop_name));
 				bool linked = p_preset->get(vformat("privacy/collected_data/%s/linked_to_user", data_collect_type_info[j].prop_name));
 				bool linked = p_preset->get(vformat("privacy/collected_data/%s/linked_to_user", data_collect_type_info[j].prop_name));
 				bool tracking = p_preset->get(vformat("privacy/collected_data/%s/used_for_tracking", data_collect_type_info[j].prop_name));
 				bool tracking = p_preset->get(vformat("privacy/collected_data/%s/used_for_tracking", data_collect_type_info[j].prop_name));
@@ -794,7 +794,7 @@ void EditorExportPlatformIOS::_fix_config_file(const Ref<EditorExportPreset> &p_
 					if (purposes != 0) {
 					if (purposes != 0) {
 						strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypePurposes</key>\n";
 						strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypePurposes</key>\n";
 						strnew += "\t\t\t\t<array>\n";
 						strnew += "\t\t\t\t<array>\n";
-						for (uint64_t k = 0; k < sizeof(data_collect_purpose_info) / sizeof(data_collect_purpose_info[0]); ++k) {
+						for (uint64_t k = 0; k < std::size(data_collect_purpose_info); ++k) {
 							if (purposes & (1 << k)) {
 							if (purposes & (1 << k)) {
 								strnew += vformat("\t\t\t\t\t<string>%s</string>\n", data_collect_purpose_info[k].type_name);
 								strnew += vformat("\t\t\t\t\t<string>%s</string>\n", data_collect_purpose_info[k].type_name);
 							}
 							}
@@ -826,7 +826,7 @@ void EditorExportPlatformIOS::_fix_config_file(const Ref<EditorExportPreset> &p_
 			}
 			}
 		} else if (lines[i].contains("$priv_api_types")) {
 		} else if (lines[i].contains("$priv_api_types")) {
 			strnew += "\t<array>\n";
 			strnew += "\t<array>\n";
-			for (uint64_t j = 0; j < sizeof(api_info) / sizeof(api_info[0]); ++j) {
+			for (uint64_t j = 0; j < std::size(api_info); ++j) {
 				int api_access = p_preset->get(vformat("privacy/%s_access_reasons", api_info[j].prop_name));
 				int api_access = p_preset->get(vformat("privacy/%s_access_reasons", api_info[j].prop_name));
 				if (api_access != 0) {
 				if (api_access != 0) {
 					strnew += "\t\t<dict>\n";
 					strnew += "\t\t<dict>\n";
@@ -946,7 +946,7 @@ Error EditorExportPlatformIOS::_export_icons(const Ref<EditorExportPreset> &p_pr
 	};
 	};
 
 
 	bool first_icon = true;
 	bool first_icon = true;
-	for (uint64_t i = 0; i < (sizeof(icon_infos) / sizeof(icon_infos[0])); ++i) {
+	for (uint64_t i = 0; i < std::size(icon_infos); ++i) {
 		for (int color_mode = ICON_NORMAL; color_mode < ICON_MAX; color_mode++) {
 		for (int color_mode = ICON_NORMAL; color_mode < ICON_MAX; color_mode++) {
 			IconInfo info = icon_infos[i];
 			IconInfo info = icon_infos[i];
 			int side_size = String(info.actual_size_side).to_int();
 			int side_size = String(info.actual_size_side).to_int();

+ 2 - 2
platform/linuxbsd/os_linuxbsd.cpp

@@ -74,7 +74,7 @@ void OS_LinuxBSD::alert(const String &p_alert, const String &p_title) {
 	String program;
 	String program;
 
 
 	for (int i = 0; i < path_elems.size(); i++) {
 	for (int i = 0; i < path_elems.size(); i++) {
-		for (uint64_t k = 0; k < sizeof(message_programs) / sizeof(char *); k++) {
+		for (uint64_t k = 0; k < std::size(message_programs); k++) {
 			String tested_path = path_elems[i].path_join(message_programs[k]);
 			String tested_path = path_elems[i].path_join(message_programs[k]);
 
 
 			if (FileAccess::exists(tested_path)) {
 			if (FileAccess::exists(tested_path)) {
@@ -751,7 +751,7 @@ Vector<String> OS_LinuxBSD::get_system_font_path_for_text(const String &p_font_n
 
 
 	Vector<String> ret;
 	Vector<String> ret;
 	static const char *allowed_formats[] = { "TrueType", "CFF" };
 	static const char *allowed_formats[] = { "TrueType", "CFF" };
-	for (size_t i = 0; i < sizeof(allowed_formats) / sizeof(const char *); i++) {
+	for (size_t i = 0; i < std::size(allowed_formats); i++) {
 		FcPattern *pattern = FcPatternCreate();
 		FcPattern *pattern = FcPatternCreate();
 		if (pattern) {
 		if (pattern) {
 			FcPatternAddBool(pattern, FC_SCALABLE, FcTrue);
 			FcPatternAddBool(pattern, FC_SCALABLE, FcTrue);

+ 1 - 1
platform/linuxbsd/x11/display_server_x11.cpp

@@ -3934,7 +3934,7 @@ Atom DisplayServerX11::_process_selection_request_target(Atom p_target, Window p
 				32,
 				32,
 				PropModeReplace,
 				PropModeReplace,
 				(unsigned char *)&data,
 				(unsigned char *)&data,
-				sizeof(data) / sizeof(data[0]));
+				std::size(data));
 		return p_property;
 		return p_property;
 	} else if (p_target == XInternAtom(x11_display, "SAVE_TARGETS", 0)) {
 	} else if (p_target == XInternAtom(x11_display, "SAVE_TARGETS", 0)) {
 		// Request to check if SAVE_TARGETS is supported, nothing special to do.
 		// Request to check if SAVE_TARGETS is supported, nothing special to do.

+ 5 - 5
platform/macos/export/export_plugin.cpp

@@ -561,13 +561,13 @@ void EditorExportPlatformMacOS::get_export_options(List<ExportOption> *r_options
 
 
 	{
 	{
 		String hint;
 		String hint;
-		for (uint64_t i = 0; i < sizeof(data_collect_purpose_info) / sizeof(data_collect_purpose_info[0]); ++i) {
+		for (uint64_t i = 0; i < std::size(data_collect_purpose_info); ++i) {
 			if (i != 0) {
 			if (i != 0) {
 				hint += ",";
 				hint += ",";
 			}
 			}
 			hint += vformat("%s:%d", data_collect_purpose_info[i].prop_name, (1 << i));
 			hint += vformat("%s:%d", data_collect_purpose_info[i].prop_name, (1 << i));
 		}
 		}
-		for (uint64_t i = 0; i < sizeof(data_collect_type_info) / sizeof(data_collect_type_info[0]); ++i) {
+		for (uint64_t i = 0; i < std::size(data_collect_type_info); ++i) {
 			r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/collected", data_collect_type_info[i].prop_name)), false));
 			r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/collected", data_collect_type_info[i].prop_name)), false));
 			r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/linked_to_user", data_collect_type_info[i].prop_name)), false));
 			r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/linked_to_user", data_collect_type_info[i].prop_name)), false));
 			r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/used_for_tracking", data_collect_type_info[i].prop_name)), false));
 			r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/used_for_tracking", data_collect_type_info[i].prop_name)), false));
@@ -671,7 +671,7 @@ void EditorExportPlatformMacOS::_make_icon(const Ref<EditorExportPreset> &p_pres
 		{ "is32", "s8mk", false, 16 } //16×16 24-bit RLE + 8-bit uncompressed mask
 		{ "is32", "s8mk", false, 16 } //16×16 24-bit RLE + 8-bit uncompressed mask
 	};
 	};
 
 
-	for (uint64_t i = 0; i < (sizeof(icon_infos) / sizeof(icon_infos[0])); ++i) {
+	for (uint64_t i = 0; i < std::size(icon_infos); ++i) {
 		Ref<Image> copy = p_icon->duplicate();
 		Ref<Image> copy = p_icon->duplicate();
 		copy->convert(Image::FORMAT_RGBA8);
 		copy->convert(Image::FORMAT_RGBA8);
 		copy->resize(icon_infos[i].size, icon_infos[i].size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
 		copy->resize(icon_infos[i].size, icon_infos[i].size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
@@ -743,7 +743,7 @@ void EditorExportPlatformMacOS::_fix_privacy_manifest(const Ref<EditorExportPres
 	for (int i = 0; i < lines.size(); i++) {
 	for (int i = 0; i < lines.size(); i++) {
 		if (lines[i].find("$priv_collection") != -1) {
 		if (lines[i].find("$priv_collection") != -1) {
 			bool section_opened = false;
 			bool section_opened = false;
-			for (uint64_t j = 0; j < sizeof(data_collect_type_info) / sizeof(data_collect_type_info[0]); ++j) {
+			for (uint64_t j = 0; j < std::size(data_collect_type_info); ++j) {
 				bool data_collected = p_preset->get(vformat("privacy/collected_data/%s/collected", data_collect_type_info[j].prop_name));
 				bool data_collected = p_preset->get(vformat("privacy/collected_data/%s/collected", data_collect_type_info[j].prop_name));
 				bool linked = p_preset->get(vformat("privacy/collected_data/%s/linked_to_user", data_collect_type_info[j].prop_name));
 				bool linked = p_preset->get(vformat("privacy/collected_data/%s/linked_to_user", data_collect_type_info[j].prop_name));
 				bool tracking = p_preset->get(vformat("privacy/collected_data/%s/used_for_tracking", data_collect_type_info[j].prop_name));
 				bool tracking = p_preset->get(vformat("privacy/collected_data/%s/used_for_tracking", data_collect_type_info[j].prop_name));
@@ -772,7 +772,7 @@ void EditorExportPlatformMacOS::_fix_privacy_manifest(const Ref<EditorExportPres
 					if (purposes != 0) {
 					if (purposes != 0) {
 						strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypePurposes</key>\n";
 						strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypePurposes</key>\n";
 						strnew += "\t\t\t\t<array>\n";
 						strnew += "\t\t\t\t<array>\n";
-						for (uint64_t k = 0; k < sizeof(data_collect_purpose_info) / sizeof(data_collect_purpose_info[0]); ++k) {
+						for (uint64_t k = 0; k < std::size(data_collect_purpose_info); ++k) {
 							if (purposes & (1 << k)) {
 							if (purposes & (1 << k)) {
 								strnew += vformat("\t\t\t\t\t<string>%s</string>\n", data_collect_purpose_info[k].type_name);
 								strnew += vformat("\t\t\t\t\t<string>%s</string>\n", data_collect_purpose_info[k].type_name);
 							}
 							}

+ 1 - 1
platform/macos/key_mapping_macos.mm

@@ -390,7 +390,7 @@ Key KeyMappingMacOS::remap_key(unsigned int p_key, unsigned int p_state, bool p_
 			LMGetKbdType(),
 			LMGetKbdType(),
 			kUCKeyTranslateNoDeadKeysBit,
 			kUCKeyTranslateNoDeadKeysBit,
 			&keys_down,
 			&keys_down,
-			sizeof(chars) / sizeof(chars[0]),
+			std::size(chars),
 			&real_length,
 			&real_length,
 			chars);
 			chars);
 
 

+ 4 - 4
platform/windows/export/export_plugin.cpp

@@ -96,7 +96,7 @@ Error EditorExportPlatformWindows::_process_icon(const Ref<EditorExportPreset> &
 		Ref<Image> src_image = _load_icon_or_splash_image(p_src_path, &err);
 		Ref<Image> src_image = _load_icon_or_splash_image(p_src_path, &err);
 		ERR_FAIL_COND_V(err != OK || src_image.is_null() || src_image->is_empty(), ERR_CANT_OPEN);
 		ERR_FAIL_COND_V(err != OK || src_image.is_null() || src_image->is_empty(), ERR_CANT_OPEN);
 
 
-		for (size_t i = 0; i < sizeof(icon_size) / sizeof(icon_size[0]); ++i) {
+		for (size_t i = 0; i < std::size(icon_size); ++i) {
 			int size = (icon_size[i] == 0) ? 256 : icon_size[i];
 			int size = (icon_size[i] == 0) ? 256 : icon_size[i];
 
 
 			Ref<Image> res_image = src_image->duplicate();
 			Ref<Image> res_image = src_image->duplicate();
@@ -107,7 +107,7 @@ Error EditorExportPlatformWindows::_process_icon(const Ref<EditorExportPreset> &
 	}
 	}
 
 
 	uint16_t valid_icon_count = 0;
 	uint16_t valid_icon_count = 0;
-	for (size_t i = 0; i < sizeof(icon_size) / sizeof(icon_size[0]); ++i) {
+	for (size_t i = 0; i < std::size(icon_size); ++i) {
 		if (images.has(icon_size[i])) {
 		if (images.has(icon_size[i])) {
 			valid_icon_count++;
 			valid_icon_count++;
 		} else {
 		} else {
@@ -129,7 +129,7 @@ Error EditorExportPlatformWindows::_process_icon(const Ref<EditorExportPreset> &
 
 
 	// Write ICONDIRENTRY.
 	// Write ICONDIRENTRY.
 	uint32_t img_offset = 6 + 16 * valid_icon_count;
 	uint32_t img_offset = 6 + 16 * valid_icon_count;
-	for (size_t i = 0; i < sizeof(icon_size) / sizeof(icon_size[0]); ++i) {
+	for (size_t i = 0; i < std::size(icon_size); ++i) {
 		if (images.has(icon_size[i])) {
 		if (images.has(icon_size[i])) {
 			const IconData &di = images[icon_size[i]];
 			const IconData &di = images[icon_size[i]];
 			fw->store_8(icon_size[i]); // Width in pixels.
 			fw->store_8(icon_size[i]); // Width in pixels.
@@ -146,7 +146,7 @@ Error EditorExportPlatformWindows::_process_icon(const Ref<EditorExportPreset> &
 	}
 	}
 
 
 	// Write image data.
 	// Write image data.
-	for (size_t i = 0; i < sizeof(icon_size) / sizeof(icon_size[0]); ++i) {
+	for (size_t i = 0; i < std::size(icon_size); ++i) {
 		if (images.has(icon_size[i])) {
 		if (images.has(icon_size[i])) {
 			const IconData &di = images[icon_size[i]];
 			const IconData &di = images[icon_size[i]];
 			fw->store_buffer(di.data.ptr(), di.data.size());
 			fw->store_buffer(di.data.ptr(), di.data.size());

+ 1 - 1
platform/windows/os_windows.cpp

@@ -774,7 +774,7 @@ bool OS_Windows::get_user_prefers_integrated_gpu() const {
 			GetCurrentApplicationUserModelIdPtr GetCurrentApplicationUserModelId = (GetCurrentApplicationUserModelIdPtr)GetProcAddress(kernel32, "GetCurrentApplicationUserModelId");
 			GetCurrentApplicationUserModelIdPtr GetCurrentApplicationUserModelId = (GetCurrentApplicationUserModelIdPtr)GetProcAddress(kernel32, "GetCurrentApplicationUserModelId");
 
 
 			if (GetCurrentApplicationUserModelId) {
 			if (GetCurrentApplicationUserModelId) {
-				UINT32 length = sizeof(value_name) / sizeof(value_name[0]);
+				UINT32 length = std::size(value_name);
 				LONG result = GetCurrentApplicationUserModelId(&length, value_name);
 				LONG result = GetCurrentApplicationUserModelId(&length, value_name);
 				if (result == ERROR_SUCCESS) {
 				if (result == ERROR_SUCCESS) {
 					is_packaged = true;
 					is_packaged = true;

+ 3 - 3
servers/rendering/shader_language.cpp

@@ -5244,7 +5244,7 @@ ShaderLanguage::DataType ShaderLanguage::get_scalar_type(DataType p_type) {
 		TYPE_VOID,
 		TYPE_VOID,
 	};
 	};
 
 
-	static_assert(sizeof(scalar_types) / sizeof(*scalar_types) == TYPE_MAX);
+	static_assert(std::size(scalar_types) == TYPE_MAX);
 
 
 	return scalar_types[p_type];
 	return scalar_types[p_type];
 }
 }
@@ -5286,7 +5286,7 @@ int ShaderLanguage::get_cardinality(DataType p_type) {
 		1,
 		1,
 	};
 	};
 
 
-	static_assert(sizeof(cardinality_table) / sizeof(*cardinality_table) == TYPE_MAX);
+	static_assert(std::size(cardinality_table) == TYPE_MAX);
 
 
 	return cardinality_table[p_type];
 	return cardinality_table[p_type];
 }
 }
@@ -11217,7 +11217,7 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_
 #ifdef DEBUG_ENABLED
 #ifdef DEBUG_ENABLED
 	// Adds context keywords.
 	// Adds context keywords.
 	if (keyword_completion_context != CF_UNSPECIFIED) {
 	if (keyword_completion_context != CF_UNSPECIFIED) {
-		int sz = sizeof(keyword_list) / sizeof(KeyWord);
+		constexpr int sz = std::size(keyword_list);
 		for (int i = 0; i < sz; i++) {
 		for (int i = 0; i < sz; i++) {
 			if (keyword_list[i].flags == CF_UNSPECIFIED) {
 			if (keyword_list[i].flags == CF_UNSPECIFIED) {
 				break; // Ignore hint keywords (parsed below).
 				break; // Ignore hint keywords (parsed below).

+ 1 - 1
servers/rendering/shader_warnings.cpp

@@ -97,7 +97,7 @@ String ShaderWarning::get_name_from_code(Code p_code) {
 		"MAGIC_POSITION_WRITE",
 		"MAGIC_POSITION_WRITE",
 	};
 	};
 
 
-	static_assert((sizeof(names) / sizeof(*names)) == WARNING_MAX, "Amount of warning types don't match the amount of warning names.");
+	static_assert(std::size(names) == WARNING_MAX, "Amount of warning types don't match the amount of warning names.");
 
 
 	return names[(int)p_code];
 	return names[(int)p_code];
 }
 }

+ 1 - 1
tests/core/string/test_string.h

@@ -1896,7 +1896,7 @@ TEST_CASE("[String] Is_*") {
 	static bool isflt[] = { true, true, true, false, true, true, false, false, false, false, false, false, false, true, true };
 	static bool isflt[] = { true, true, true, false, true, true, false, false, false, false, false, false, false, true, true };
 	static bool isaid[] = { false, false, false, false, false, false, false, false, true, true, false, false, false, false, false };
 	static bool isaid[] = { false, false, false, false, false, false, false, false, true, true, false, false, false, false, false };
 	static bool isuid[] = { false, false, false, false, false, false, false, false, true, true, false, false, true, false, false };
 	static bool isuid[] = { false, false, false, false, false, false, false, false, true, true, false, false, true, false, false };
-	for (unsigned int i = 0; i < sizeof(data) / sizeof(data[0]); i++) {
+	for (unsigned int i = 0; i < std::size(data); i++) {
 		String s = String::utf8(data[i]);
 		String s = String::utf8(data[i]);
 		CHECK(s.is_numeric() == isnum[i]);
 		CHECK(s.is_numeric() == isnum[i]);
 		CHECK(s.is_valid_int() == isint[i]);
 		CHECK(s.is_valid_int() == isint[i]);

+ 2 - 2
tests/core/test_crypto.h

@@ -60,8 +60,8 @@ PackedByteArray raw_to_pba(const uint8_t *arr, size_t len) {
 TEST_CASE("[Crypto] PackedByteArray constant time compare") {
 TEST_CASE("[Crypto] PackedByteArray constant time compare") {
 	const uint8_t hm1[] = { 144, 140, 176, 38, 88, 113, 101, 45, 71, 105, 10, 91, 248, 16, 117, 244, 189, 30, 238, 29, 219, 134, 82, 130, 212, 114, 161, 166, 188, 169, 200, 106 };
 	const uint8_t hm1[] = { 144, 140, 176, 38, 88, 113, 101, 45, 71, 105, 10, 91, 248, 16, 117, 244, 189, 30, 238, 29, 219, 134, 82, 130, 212, 114, 161, 166, 188, 169, 200, 106 };
 	const uint8_t hm2[] = { 80, 30, 144, 228, 108, 38, 188, 125, 150, 64, 165, 127, 221, 118, 144, 232, 45, 100, 15, 248, 193, 244, 245, 34, 116, 147, 132, 200, 110, 27, 38, 75 };
 	const uint8_t hm2[] = { 80, 30, 144, 228, 108, 38, 188, 125, 150, 64, 165, 127, 221, 118, 144, 232, 45, 100, 15, 248, 193, 244, 245, 34, 116, 147, 132, 200, 110, 27, 38, 75 };
-	PackedByteArray p1 = raw_to_pba(hm1, sizeof(hm1) / sizeof(hm1[0]));
-	PackedByteArray p2 = raw_to_pba(hm2, sizeof(hm2) / sizeof(hm2[0]));
+	PackedByteArray p1 = raw_to_pba(hm1, std::size(hm1));
+	PackedByteArray p2 = raw_to_pba(hm2, std::size(hm2));
 	_MockCrypto crypto;
 	_MockCrypto crypto;
 	bool equal = crypto.constant_time_compare(p1, p1);
 	bool equal = crypto.constant_time_compare(p1, p1);
 	CHECK(equal);
 	CHECK(equal);

+ 1 - 1
tests/servers/test_text_server.h

@@ -508,7 +508,7 @@ TEST_SUITE("[TextServer]") {
 						{ U"test\r test", { 0, 5, 5, 10 } },
 						{ U"test\r test", { 0, 5, 5, 10 } },
 						{ U"test\r test \r test", { 0, 5, 5, 12, 12, 17 } },
 						{ U"test\r test \r test", { 0, 5, 5, 12, 12, 17 } },
 					};
 					};
-					for (size_t j = 0; j < sizeof(cases) / sizeof(TestCase); j++) {
+					for (size_t j = 0; j < std::size(cases); j++) {
 						RID ctx = ts->create_shaped_text();
 						RID ctx = ts->create_shaped_text();
 						CHECK_FALSE_MESSAGE(ctx == RID(), "Creating text buffer failed.");
 						CHECK_FALSE_MESSAGE(ctx == RID(), "Creating text buffer failed.");
 						bool ok = ts->shaped_text_add_string(ctx, cases[j].text, font, 16);
 						bool ok = ts->shaped_text_add_string(ctx, cases[j].text, font, 16);