Mark lua_jailbreak_exception's derived classes and functions as final

The documentation for IMPLEMENT_LUA_JAILBREAK_EXCEPTION() says, "This
macro needs to be placed in the definition of the most derived class,
which uses lua_jailbreak_exception as baseclass."  Storing exceptions
in constructors will require this to mean that classes that derive
from lua_jailbreak_exception must be treated as final, because of the
"assert(!jailbreak_exception);" in lua_jailbreak_exception::store().
Specifying overridden clone() and execute() functions as final in
IMPLEMENT_LUA_JAILBREAK_EXCEPTION() enforces this.

leavegame_wesnothd_error is derived from a class that derives from
lua_jailbreak_exception, so also fix this inheritance and a block that
might catch leavegame_wesnothd_error.
This commit is contained in:
P. J. McDermott 2024-01-21 07:39:55 -05:00 committed by Pentarctagon
parent 4b5c1696ee
commit a5b8b559af
11 changed files with 19 additions and 17 deletions

View file

@ -34,7 +34,7 @@ class config;
* Exception used to escape form the ai or ui code to playsingle_controller::play_side.
* Never thrown during replays.
*/
class return_to_play_side_exception : public lua_jailbreak_exception, public std::exception
class return_to_play_side_exception final : public lua_jailbreak_exception, public std::exception
{
public:
@ -49,7 +49,7 @@ private:
IMPLEMENT_LUA_JAILBREAK_EXCEPTION(return_to_play_side_exception)
};
class quit_game_exception
class quit_game_exception final
: public lua_jailbreak_exception
, public std::exception
{

View file

@ -33,7 +33,7 @@ namespace gui2::iteration
*
* Invalid means the initial state at_end() == true.
*/
class logic_error : public std::logic_error, public lua_jailbreak_exception
class logic_error final : public std::logic_error, public lua_jailbreak_exception
{
public:
explicit logic_error(const std::string& message)
@ -51,7 +51,7 @@ private:
*
* Invalid means the initial state at_end() == true.
*/
class range_error : public std::range_error, public lua_jailbreak_exception
class range_error final : public std::range_error, public lua_jailbreak_exception
{
public:
explicit range_error(const std::string& message)

View file

@ -63,7 +63,7 @@ class modification
public:
/** Exception thrown by the operator() when an error occurs. */
struct imod_exception
struct imod_exception final
: public lua_jailbreak_exception
{
/**

View file

@ -85,9 +85,9 @@ private:
*/
#define IMPLEMENT_LUA_JAILBREAK_EXCEPTION(type) \
\
virtual type* clone() const { return new type(*this); } \
virtual type* clone() const final { return new type(*this); } \
\
virtual void execute() \
virtual void execute() final \
{ \
type exception(dynamic_cast<type&>(*jailbreak_exception)); \
throw exception; \

View file

@ -38,7 +38,7 @@ namespace events
class mouse_handler;
}
struct fallback_ai_to_human_exception : public lua_jailbreak_exception
struct fallback_ai_to_human_exception final : public lua_jailbreak_exception
{
IMPLEMENT_LUA_JAILBREAK_EXCEPTION(fallback_ai_to_human_exception)
};

View file

@ -453,7 +453,7 @@ level_result::type playsingle_controller::play_scenario(const config& level)
savegame::savegame::YES_NO);
}
if(dynamic_cast<const ingame_wesnothd_error*>(&e)) {
if(dynamic_cast<const ingame_wesnothd_error*>(&e) || dynamic_cast<const leavegame_wesnothd_error*>(&e)) {
return level_result::type::quit;
} else {
throw;

View file

@ -29,7 +29,7 @@
class replay_controller;
class saved_game;
struct reset_gamestate_exception : public lua_jailbreak_exception, public std::exception
struct reset_gamestate_exception final : public lua_jailbreak_exception, public std::exception
{
reset_gamestate_exception(std::shared_ptr<config> l, std::shared_ptr<config> stats, bool s = true) : level(l), stats_(stats), start_replay(s) {}
std::shared_ptr<config> level;

View file

@ -80,7 +80,7 @@ struct load_game_metadata
* Exception used to signal that the user has decided to abortt a game,
* and to load another game instead.
*/
class load_game_exception
class load_game_exception final
: public lua_jailbreak_exception, public std::exception
{
public:

View file

@ -314,7 +314,7 @@ struct error : public game::error
};
/** Type that can be thrown as an exception to quit to desktop. */
class quit : public lua_jailbreak_exception
class quit final : public lua_jailbreak_exception
{
public:
quit()

View file

@ -46,7 +46,7 @@ struct wesnothd_rejected_client_error : public game::error
* This means we cannot continue with the game but we can stay connected to wesnothd and start a new game.
* TODO: find a short name
*/
struct ingame_wesnothd_error : public wesnothd_error, public lua_jailbreak_exception
struct ingame_wesnothd_error final : public wesnothd_error, public lua_jailbreak_exception
{
ingame_wesnothd_error(const std::string& error)
: wesnothd_error(error)
@ -56,19 +56,21 @@ struct ingame_wesnothd_error : public wesnothd_error, public lua_jailbreak_excep
IMPLEMENT_LUA_JAILBREAK_EXCEPTION(ingame_wesnothd_error)
};
struct leavegame_wesnothd_error : ingame_wesnothd_error
struct leavegame_wesnothd_error final : public wesnothd_error, public lua_jailbreak_exception
{
leavegame_wesnothd_error(const std::string& error)
: ingame_wesnothd_error(error)
: wesnothd_error(error)
{
}
IMPLEMENT_LUA_JAILBREAK_EXCEPTION(leavegame_wesnothd_error)
};
/**
* An error occurred inside the underlying network communication code (boost asio)
* TODO: find a short name
*/
struct wesnothd_connection_error : public wesnothd_error, public lua_jailbreak_exception
struct wesnothd_connection_error final : public wesnothd_error, public lua_jailbreak_exception
{
wesnothd_connection_error(const boost::system::error_code& error, const std::string& msg = "")
: wesnothd_error(error.message())

View file

@ -96,7 +96,7 @@
, const std::string& dev_message = "");
/** Helper class, don't construct this directly. */
struct wml_exception
struct wml_exception final
: public lua_jailbreak_exception
{
wml_exception(const std::string& user_msg, const std::string& dev_msg)