From 310c1f50beb77fc5c6f9075029973161d4e51a4a Mon Sep 17 00:00:00 2001 From: FearlessTobi Date: Mon, 19 Feb 2024 16:00:46 +0100 Subject: scope_exit: Make constexpr Allows the use of the macro in constexpr-contexts. Also avoids some potential problems when nesting braces inside it. --- src/core/file_sys/fs_directory.h | 4 ++++ src/core/file_sys/fs_path_utility.h | 12 ++++++------ .../fssystem/fssystem_hierarchical_sha256_storage.cpp | 4 +++- src/core/file_sys/program_metadata.cpp | 4 +++- 4 files changed, 16 insertions(+), 8 deletions(-) (limited to 'src/core/file_sys') diff --git a/src/core/file_sys/fs_directory.h b/src/core/file_sys/fs_directory.h index 25c9cb18a..3f90abb8f 100644 --- a/src/core/file_sys/fs_directory.h +++ b/src/core/file_sys/fs_directory.h @@ -3,6 +3,10 @@ #pragma once +#include +#include "common/common_funcs.h" +#include "common/common_types.h" + namespace FileSys { constexpr inline size_t EntryNameLengthMax = 0x300; diff --git a/src/core/file_sys/fs_path_utility.h b/src/core/file_sys/fs_path_utility.h index e9011d065..5643141f9 100644 --- a/src/core/file_sys/fs_path_utility.h +++ b/src/core/file_sys/fs_path_utility.h @@ -447,7 +447,7 @@ public: char* replacement_path = nullptr; size_t replacement_path_size = 0; - SCOPE_EXIT({ + SCOPE_EXIT { if (replacement_path != nullptr) { if (std::is_constant_evaluated()) { delete[] replacement_path; @@ -455,7 +455,7 @@ public: Deallocate(replacement_path, replacement_path_size); } } - }); + }; // Perform path replacement, if necessary if (IsParentDirectoryPathReplacementNeeded(cur_path)) { @@ -1102,8 +1102,8 @@ public: R_SUCCEED(); } - static Result Normalize(char* dst, size_t dst_size, const char* path, size_t path_len, - const PathFlags& flags) { + static constexpr Result Normalize(char* dst, size_t dst_size, const char* path, size_t path_len, + const PathFlags& flags) { // Use StringTraits names for remainder of scope using namespace StringTraits; @@ -1199,7 +1199,7 @@ public: const size_t replaced_src_len = path_len - (src - path); char* replaced_src = nullptr; - SCOPE_EXIT({ + SCOPE_EXIT { if (replaced_src != nullptr) { if (std::is_constant_evaluated()) { delete[] replaced_src; @@ -1207,7 +1207,7 @@ public: Deallocate(replaced_src, replaced_src_len); } } - }); + }; if (std::is_constant_evaluated()) { replaced_src = new char[replaced_src_len]; diff --git a/src/core/file_sys/fssystem/fssystem_hierarchical_sha256_storage.cpp b/src/core/file_sys/fssystem/fssystem_hierarchical_sha256_storage.cpp index caea0b8f8..a68fd973c 100644 --- a/src/core/file_sys/fssystem/fssystem_hierarchical_sha256_storage.cpp +++ b/src/core/file_sys/fssystem/fssystem_hierarchical_sha256_storage.cpp @@ -36,7 +36,9 @@ Result HierarchicalSha256Storage::Initialize(VirtualFile* base_storages, s32 lay // Get the base storage size. m_base_storage_size = base_storages[2]->GetSize(); { - auto size_guard = SCOPE_GUARD({ m_base_storage_size = 0; }); + auto size_guard = SCOPE_GUARD { + m_base_storage_size = 0; + }; R_UNLESS(m_base_storage_size <= static_cast(HashSize) << m_log_size_ratio << m_log_size_ratio, ResultHierarchicalSha256BaseStorageTooLarge); diff --git a/src/core/file_sys/program_metadata.cpp b/src/core/file_sys/program_metadata.cpp index ae4e441c9..289969cc4 100644 --- a/src/core/file_sys/program_metadata.cpp +++ b/src/core/file_sys/program_metadata.cpp @@ -98,7 +98,9 @@ Loader::ResultStatus ProgramMetadata::Load(VirtualFile file) { Loader::ResultStatus ProgramMetadata::Reload(VirtualFile file) { const u64 original_program_id = aci_header.title_id; - SCOPE_EXIT({ aci_header.title_id = original_program_id; }); + SCOPE_EXIT { + aci_header.title_id = original_program_id; + }; return this->Load(file); } -- cgit v1.2.3