From 32eb7071a156017a51c7db00e9eb610dd8cb0697 Mon Sep 17 00:00:00 2001 From: Duncan Date: Sat, 2 May 2020 09:09:12 +0100 Subject: [PATCH] Fix #11550: Use std::nullopt instead of empty brace (#11595) This is technically a gcc bug from the looks of it but since std::nullopt is slightly easier to read I've gone through the codebase and used that over empty braces. In addition noticed a mistake on the scripting viewport get widgetIndex function where it would return an incorrect widgetIndex. --- src/openrct2-ui/scripting/CustomWindow.cpp | 4 ++-- src/openrct2-ui/scripting/ScViewport.hpp | 2 +- src/openrct2/interface/Screenshot.cpp | 4 ++-- src/openrct2/network/ServerList.cpp | 2 +- src/openrct2/peep/Peep.cpp | 2 +- src/openrct2/rct2/S6Exporter.cpp | 2 +- src/openrct2/ride/Vehicle.cpp | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/openrct2-ui/scripting/CustomWindow.cpp b/src/openrct2-ui/scripting/CustomWindow.cpp index 87c9912e2c..e3689d0349 100644 --- a/src/openrct2-ui/scripting/CustomWindow.cpp +++ b/src/openrct2-ui/scripting/CustomWindow.cpp @@ -650,7 +650,7 @@ namespace OpenRCT2::Ui::Windows } widgetIndex++; } - return 0; + return std::nullopt; } static void window_custom_update_viewport(rct_window* w) @@ -978,7 +978,7 @@ namespace OpenRCT2::Ui::Windows } } } - return {}; + return std::nullopt; } } // namespace OpenRCT2::Ui::Windows diff --git a/src/openrct2-ui/scripting/ScViewport.hpp b/src/openrct2-ui/scripting/ScViewport.hpp index 4fee253028..2e85806a3d 100644 --- a/src/openrct2-ui/scripting/ScViewport.hpp +++ b/src/openrct2-ui/scripting/ScViewport.hpp @@ -299,7 +299,7 @@ namespace OpenRCT2::Scripting } } } - return {}; + return std::nullopt; } }; } // namespace OpenRCT2::Scripting diff --git a/src/openrct2/interface/Screenshot.cpp b/src/openrct2/interface/Screenshot.cpp index 73f8fdc04a..a27fcd15db 100644 --- a/src/openrct2/interface/Screenshot.cpp +++ b/src/openrct2/interface/Screenshot.cpp @@ -141,7 +141,7 @@ static std::optional screenshot_get_next_path() if (!platform_ensure_directory_exists(screenshotDirectory.c_str())) { log_error("Unable to save screenshots in OpenRCT2 screenshot directory."); - return {}; + return std::nullopt; } auto parkName = screenshot_get_park_name(); @@ -165,7 +165,7 @@ static std::optional screenshot_get_next_path() } log_error("You have too many saved screenshots saved at exactly the same date and time."); - return {}; + return std::nullopt; }; std::string screenshot_dump_png(rct_drawpixelinfo* dpi) diff --git a/src/openrct2/network/ServerList.cpp b/src/openrct2/network/ServerList.cpp index b24a95f257..156d897943 100644 --- a/src/openrct2/network/ServerList.cpp +++ b/src/openrct2/network/ServerList.cpp @@ -92,7 +92,7 @@ std::optional ServerListEntry::FromJson(const json_t* server) if (name == nullptr || version == nullptr) { log_verbose("Cowardly refusing to add server without name or version specified."); - return {}; + return std::nullopt; } else { diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index 6dc6c606a0..a089d1afd8 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -610,7 +610,7 @@ std::optional Peep::UpdateAction(int16_t& xy_distance) { if (xy_distance <= destination_tolerance) { - return {}; + return std::nullopt; } int32_t nextDirection = 0; if (x_delta < y_delta) diff --git a/src/openrct2/rct2/S6Exporter.cpp b/src/openrct2/rct2/S6Exporter.cpp index b675e93a36..11fd4bebd7 100644 --- a/src/openrct2/rct2/S6Exporter.cpp +++ b/src/openrct2/rct2/S6Exporter.cpp @@ -1622,7 +1622,7 @@ std::optional S6Exporter::AllocateUserString(const std::string_view& v _userStrings.emplace_back(value); return static_cast(USER_STRING_START + nextId); } - return {}; + return std::nullopt; } static std::string GetTruncatedRCT2String(const std::string_view& src) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 59968f2137..781c443cc2 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -2210,7 +2210,7 @@ static std::optional ride_get_train_index_from_vehicle(Ride* ride, uin } else if (trainIndex >= std::size(ride->vehicles)) { - return {}; + return std::nullopt; } } return { trainIndex };