From 24cc0b01d4362a9dcb88a974f60f6f325a26b4b2 Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Sun, 18 Mar 2018 23:15:31 +1100 Subject: [PATCH] Used constexpr and noexcept keywords directly We can do this now since were bumping min compiler support. (cherry-picked from commit 8120843b2ef6ff2348d76e962d40d8f4d83d9ca6) --- src/editor/map/editor_map.hpp | 4 ++-- src/exceptions.hpp | 4 ++-- src/filesystem_boost.cpp | 4 ++-- src/formula/formula.hpp | 2 +- src/game_end_exceptions.hpp | 4 ++-- src/global.hpp | 17 ----------------- src/gui/widgets/grid.hpp | 4 ++-- src/gui/widgets/unit_preview_pane.cpp | 12 ++++++------ src/image_modifications.hpp | 2 +- src/lexical_cast.hpp | 2 +- src/libc_error.hpp | 4 ++-- src/log.cpp | 6 +++--- src/log.hpp | 4 ++-- src/lua_jailbreak_exception.cpp | 4 ++-- src/lua_jailbreak_exception.hpp | 6 +++--- src/sdl/rect.hpp | 3 +-- src/serialization/string_view.hpp | 2 +- src/utils/general.hpp | 2 +- src/utils/make_enum.hpp | 8 ++++---- src/utils/name_generator.hpp | 2 +- src/variable_info.cpp | 2 +- src/variable_info.hpp | 4 ++-- src/wml_exception.hpp | 2 +- 23 files changed, 43 insertions(+), 61 deletions(-) diff --git a/src/editor/map/editor_map.hpp b/src/editor/map/editor_map.hpp index f0eaa22f0a1..e790655e321 100644 --- a/src/editor/map/editor_map.hpp +++ b/src/editor/map/editor_map.hpp @@ -44,7 +44,7 @@ struct editor_map_load_exception : public editor_exception : editor_exception(msg), filename(fn) { } - ~editor_map_load_exception() NOEXCEPT {} + ~editor_map_load_exception() noexcept {} std::string filename; }; @@ -54,7 +54,7 @@ struct editor_map_save_exception : public editor_exception : editor_exception(msg) { } - ~editor_map_save_exception() NOEXCEPT {} + ~editor_map_save_exception() noexcept {} }; diff --git a/src/exceptions.hpp b/src/exceptions.hpp index 4bb209a8ff8..5565b079ed0 100644 --- a/src/exceptions.hpp +++ b/src/exceptions.hpp @@ -32,9 +32,9 @@ struct error : std::exception error() : message() {} error(const std::string &msg) : message(msg) {} - ~error() NOEXCEPT {} + ~error() noexcept {} - const char *what() const NOEXCEPT + const char *what() const noexcept { return message.c_str(); } diff --git a/src/filesystem_boost.cpp b/src/filesystem_boost.cpp index 3a03d1ddb19..3765a15a6d1 100644 --- a/src/filesystem_boost.cpp +++ b/src/filesystem_boost.cpp @@ -117,9 +117,9 @@ namespace { public: //Not used by boost filesystem - int do_encoding() const NOEXCEPT { return 0; } + int do_encoding() const noexcept { return 0; } //Not used by boost filesystem - bool do_always_noconv() const NOEXCEPT { return false; } + bool do_always_noconv() const noexcept { return false; } int do_length( std::mbstate_t& /*state*/, const char* /*from*/, const char* /*from_end*/, diff --git a/src/formula/formula.hpp b/src/formula/formula.hpp index 947fcd3627d..b4d97b5cfda 100644 --- a/src/formula/formula.hpp +++ b/src/formula/formula.hpp @@ -100,7 +100,7 @@ struct formula_error : public game::error formula_error(const std::string& type, const std::string& formula, const std::string& file, int line); - ~formula_error() NOEXCEPT {} + ~formula_error() noexcept {} std::string type; std::string formula; diff --git a/src/game_end_exceptions.hpp b/src/game_end_exceptions.hpp index 4f6d0865787..0966c0be326 100644 --- a/src/game_end_exceptions.hpp +++ b/src/game_end_exceptions.hpp @@ -50,7 +50,7 @@ public: , std::exception() { } - const char * what() const NOEXCEPT { return "return_to_play_side_exception"; } + const char * what() const noexcept { return "return_to_play_side_exception"; } private: IMPLEMENT_LUA_JAILBREAK_EXCEPTION(return_to_play_side_exception) @@ -67,7 +67,7 @@ public: , std::exception() { } - const char * what() const NOEXCEPT { return "quit_game_exception"; } + const char * what() const noexcept { return "quit_game_exception"; } private: IMPLEMENT_LUA_JAILBREAK_EXCEPTION(quit_game_exception) }; diff --git a/src/global.hpp b/src/global.hpp index 6508672c3cb..6ef35c7e741 100644 --- a/src/global.hpp +++ b/src/global.hpp @@ -50,12 +50,8 @@ #if _MSC_VER >= 1900 #define HAVE_REF_QUALIFIERS 1 #define HAVE_INHERITING_CTORS 1 -#define CONSTEXPR constexpr -#define NOEXCEPT noexcept #define NORETURN [[noreturn]] #else -#define CONSTEXPR -#define NOEXCEPT throw() #define NORETURN __declspec(noreturn) #endif // MSVC supports these starting in 2017? @@ -92,25 +88,12 @@ // Use GCC-style attribute because the __has_cpp_attribute feature-checking macro doesn't exist in clang 3.5 #define DEPRECATED(reason) __attribute__((deprecated(reason))) -#if __has_feature(cxx_constexpr) -#define CONSTEXPR constexpr -#else -#define CONSTEXPR -#endif - -#if __has_feature(cxx_noexcept) -#define NOEXCEPT noexcept -#else -#define NOEXCEPT throw() -#endif #endif #if defined(__GNUC__) && !defined(__clang__) // GCC 5 required for this #define HAVE_PUT_TIME (__GNUC__ >= 5) // GCC supports these from 4.8 up -#define CONSTEXPR constexpr -#define NOEXCEPT noexcept #define NORETURN [[noreturn]] #define HAVE_REF_QUALIFIERS 1 #define HAVE_INHERITING_CTORS 1 diff --git a/src/gui/widgets/grid.hpp b/src/gui/widgets/grid.hpp index 081b39f4b3e..89e9b4c2e96 100644 --- a/src/gui/widgets/grid.hpp +++ b/src/gui/widgets/grid.hpp @@ -344,14 +344,14 @@ private: * utilize a move constructor as long as a non-throwing one is provided. */ #if defined(_MSC_VER) && _MSC_VER <= 1800 // MSVC 2013 - child(child&& c) NOEXCEPT + child(child&& c) noexcept : flags_(c.flags_) , border_size_(c.border_size_) , widget_(std::move(c.widget_)) { } #else - child(child&&) NOEXCEPT = default; + child(child&&) noexcept = default; #endif /** Returns the best size for the cell. */ diff --git a/src/gui/widgets/unit_preview_pane.cpp b/src/gui/widgets/unit_preview_pane.cpp index 313903d839b..79478985823 100644 --- a/src/gui/widgets/unit_preview_pane.cpp +++ b/src/gui/widgets/unit_preview_pane.cpp @@ -120,10 +120,10 @@ static inline std::string get_hp_tooltip(const utils::string_map& res, const std const int res_def = 100 - get(resist.first, false); if(res_att == res_def) { - line << "" << utils::signed_percent(res_def) << ""; + line << "\t" << utils::signed_percent(res_def) << ""; } else { - line << "" << utils::signed_percent(res_att) << "" << "/" - << "" << utils::signed_percent(res_def) << ""; + line << "\t" << utils::signed_percent(res_att) << "" << "/" + << "" << utils::signed_percent(res_def) << ""; att_def_diff = true; } @@ -178,7 +178,7 @@ static inline std::string get_mp_tooltip(int total_movement, std::function"; + tooltip << "\t"; // A 5 MP margin; if the movement costs go above the unit's max moves + 5, we replace it with dashes. if(cannot_move && (moves > total_movement + 5)) { @@ -250,7 +250,7 @@ void unit_preview_pane::set_displayed_type(const unit_type& type) + ")"; } - mods += "~SCALE_INTO_SHARP(144,144)" + image_mods_; + mods += "~XBRZ(2)~SCALE_INTO_SHARP(144,144)" + image_mods_; icon_type_->set_label((type.icon().empty() ? type.image() : type.icon()) + mods); } @@ -394,7 +394,7 @@ void unit_preview_pane::set_displayed_unit(const unit& u) mods += "~BLIT(" + overlay + ")"; } - mods += "~SCALE_INTO_SHARP(144,144)" + image_mods_; + mods += "~XBRZ(2)~SCALE_INTO_SHARP(144,144)" + image_mods_; icon_type_->set_label(u.absolute_image() + mods); } diff --git a/src/image_modifications.hpp b/src/image_modifications.hpp index 59792b8fb76..5cc9a9d1163 100644 --- a/src/image_modifications.hpp +++ b/src/image_modifications.hpp @@ -84,7 +84,7 @@ public: */ imod_exception(const std::string& message); - ~imod_exception() NOEXCEPT {} + ~imod_exception() noexcept {} /** The error message regarding the failed operation. */ const std::string message; diff --git a/src/lexical_cast.hpp b/src/lexical_cast.hpp index 4f809d879df..6ea0482d227 100644 --- a/src/lexical_cast.hpp +++ b/src/lexical_cast.hpp @@ -116,7 +116,7 @@ inline To lexical_cast_default(From value, To fallback = To()) /** Thrown when a lexical_cast fails. */ struct bad_lexical_cast : std::exception { - const char* what() const NOEXCEPT + const char* what() const noexcept { return "bad_lexical_cast"; } diff --git a/src/libc_error.hpp b/src/libc_error.hpp index b99304ba75f..d799dcae39f 100644 --- a/src/libc_error.hpp +++ b/src/libc_error.hpp @@ -25,7 +25,7 @@ public: { } - virtual ~libc_error() NOEXCEPT + virtual ~libc_error() noexcept { } @@ -42,7 +42,7 @@ public: } /** Returns an explanatory string describing the exception. */ - const char* what() const NOEXCEPT + const char* what() const noexcept { return msg_.c_str(); } diff --git a/src/log.cpp b/src/log.cpp index 44488e1f267..0cbebf606e5 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -197,7 +197,7 @@ std::string get_timespan(const time_t& t) { return sout.str(); } -static void print_precise_timestamp(std::ostream & out) NOEXCEPT +static void print_precise_timestamp(std::ostream & out) noexcept { try { facet.put( @@ -238,7 +238,7 @@ std::ostream &logger::operator()(const log_domain& domain, bool show_names, bool } } -void scope_logger::do_log_entry(const log_domain& domain, const std::string& str) NOEXCEPT +void scope_logger::do_log_entry(const log_domain& domain, const std::string& str) noexcept { output_ = &debug()(domain, false, true); str_ = str; @@ -249,7 +249,7 @@ void scope_logger::do_log_entry(const log_domain& domain, const std::string& str ++indent; } -void scope_logger::do_log_exit() NOEXCEPT +void scope_logger::do_log_exit() noexcept { long ticks = 0; try { diff --git a/src/log.hpp b/src/log.hpp index 96c055d0bcb..36661e955e6 100644 --- a/src/log.hpp +++ b/src/log.hpp @@ -166,8 +166,8 @@ public: } void do_indent() const; private: - void do_log_entry(const log_domain& domain, const std::string& str) NOEXCEPT; - void do_log_exit() NOEXCEPT; + void do_log_entry(const log_domain& domain, const std::string& str) noexcept; + void do_log_exit() noexcept; }; /** diff --git a/src/lua_jailbreak_exception.cpp b/src/lua_jailbreak_exception.cpp index 96a9d153452..dac04be027e 100644 --- a/src/lua_jailbreak_exception.cpp +++ b/src/lua_jailbreak_exception.cpp @@ -18,7 +18,7 @@ lua_jailbreak_exception *lua_jailbreak_exception::jailbreak_exception = nullptr; -void lua_jailbreak_exception::store() const NOEXCEPT +void lua_jailbreak_exception::store() const noexcept { /* * It should not be possible to call this function with an exception still @@ -54,7 +54,7 @@ void lua_jailbreak_exception::rethrow() assert(false); } -void lua_jailbreak_exception::clear() NOEXCEPT +void lua_jailbreak_exception::clear() noexcept { delete jailbreak_exception; jailbreak_exception = nullptr; diff --git a/src/lua_jailbreak_exception.hpp b/src/lua_jailbreak_exception.hpp index 5c756802c26..0c8fc05f2c2 100644 --- a/src/lua_jailbreak_exception.hpp +++ b/src/lua_jailbreak_exception.hpp @@ -25,10 +25,10 @@ class lua_jailbreak_exception { public: - virtual ~lua_jailbreak_exception() NOEXCEPT {} + virtual ~lua_jailbreak_exception() noexcept {} /** Stores a copy the current exception to be rethrown. */ - void store() const NOEXCEPT; + void store() const noexcept; /** * Rethrows the stored exception. @@ -45,7 +45,7 @@ protected: private: /** Clears the current exception. */ - static void clear() NOEXCEPT; + static void clear() noexcept; /** * Creates a copy of the current exception. diff --git a/src/sdl/rect.hpp b/src/sdl/rect.hpp index 2ba9bc919ad..4a36be0febd 100644 --- a/src/sdl/rect.hpp +++ b/src/sdl/rect.hpp @@ -19,7 +19,6 @@ * Contains the SDL_Rect helper code. */ -#include "global.hpp" #include "utils.hpp" #include @@ -29,7 +28,7 @@ struct point; namespace sdl { -CONSTEXPR const SDL_Rect empty_rect { 0, 0, 0, 0 }; +constexpr const SDL_Rect empty_rect { 0, 0, 0, 0 }; /** * Creates an SDL_Rect with the given dimensions. diff --git a/src/serialization/string_view.hpp b/src/serialization/string_view.hpp index 36de8880544..ccbd75df41d 100644 --- a/src/serialization/string_view.hpp +++ b/src/serialization/string_view.hpp @@ -351,7 +351,7 @@ public: private: template size_type reverse_distance(r_iter first, r_iter last) const BOOST_NOEXCEPT { - // Portability note here: std::distance is not NOEXCEPT, but calling it with a string_view::reverse_iterator will not throw. + // Portability note here: std::distance is not noexcept, but calling it with a string_view::reverse_iterator will not throw. return len_ - 1 - std::distance(first, last); } diff --git a/src/utils/general.hpp b/src/utils/general.hpp index a6153321deb..8f326017db7 100644 --- a/src/utils/general.hpp +++ b/src/utils/general.hpp @@ -28,7 +28,7 @@ using std::clamp; #else // NOTE: remove once we have C++17 support and can use std::clamp template -CONSTEXPR const T& clamp(const T& value, const T& min, const T& max) +constexpr const T& clamp(const T& value, const T& min, const T& max) { return std::max(std::min(value, max), min); } diff --git a/src/utils/make_enum.hpp b/src/utils/make_enum.hpp index 113d8828c77..63775efa018 100644 --- a/src/utils/make_enum.hpp +++ b/src/utils/make_enum.hpp @@ -99,19 +99,19 @@ public: , bad_val(str) {} - virtual ~bad_enum_cast() NOEXCEPT {} + virtual ~bad_enum_cast() noexcept {} - const char * what() const NOEXCEPT + const char * what() const noexcept { return message.c_str(); } - const char * type() const NOEXCEPT + const char * type() const noexcept { return name.c_str(); } - const char * value() const NOEXCEPT + const char * value() const noexcept { return bad_val.c_str(); } diff --git a/src/utils/name_generator.hpp b/src/utils/name_generator.hpp index f68930ecda1..e246900d37f 100644 --- a/src/utils/name_generator.hpp +++ b/src/utils/name_generator.hpp @@ -23,7 +23,7 @@ class name_generator_invalid_exception : public std::exception { public: name_generator_invalid_exception(const char* errMessage):errMessage_(errMessage) {} - const char* what() const NOEXCEPT { return errMessage_; } + const char* what() const noexcept { return errMessage_; } private: const char* errMessage_; diff --git a/src/variable_info.cpp b/src/variable_info.cpp index fe420b401e5..43897592a4e 100644 --- a/src/variable_info.cpp +++ b/src/variable_info.cpp @@ -63,7 +63,7 @@ typename V::result_t apply_visitor(typename V::param_t state, T&&... args) using namespace variable_info_implementation; template -variable_info::variable_info(const std::string& varname, maybe_const_t& vars) NOEXCEPT +variable_info::variable_info(const std::string& varname, maybe_const_t& vars) noexcept : name_(varname) , state_(vars) , valid_(true) diff --git a/src/variable_info.hpp b/src/variable_info.hpp index 6daf1037a86..326e48ee76d 100644 --- a/src/variable_info.hpp +++ b/src/variable_info.hpp @@ -27,7 +27,7 @@ class invalid_variablename_exception : public std::exception public: invalid_variablename_exception() : std::exception() {} - const char* what() const NOEXCEPT + const char* what() const noexcept { return "invalid_variablename_exception"; } @@ -42,7 +42,7 @@ template class variable_info { public: - variable_info(const std::string& varname, maybe_const_t& vars) NOEXCEPT; + variable_info(const std::string& varname, maybe_const_t& vars) noexcept; std::string get_error_message() const; diff --git a/src/wml_exception.hpp b/src/wml_exception.hpp index 17eee0575f8..cedeb3bb784 100644 --- a/src/wml_exception.hpp +++ b/src/wml_exception.hpp @@ -98,7 +98,7 @@ struct wml_exception { } - ~wml_exception() NOEXCEPT {} + ~wml_exception() noexcept {} /** * The message for the user explaining what went wrong. This message can