1
0
Fork 0

Make fatalMessageBox() end with std::abort() and declare it [[noreturn]]

Many places calling fatalMessageBox() assume it doesn't return, so make
it behave this way. See discussion around:

  https://sourceforge.net/p/flightgear/mailman/message/35766691/

for some context.
This commit is contained in:
Florent Rougon 2017-04-08 13:49:55 +02:00
parent 5040e6c7f0
commit 9e6a3ebc6b
3 changed files with 16 additions and 12 deletions

View file

@ -4,6 +4,8 @@
#include <simgear/simgear_config.h> #include <simgear/simgear_config.h>
#include <cstdlib>
#include "MessageBox.hxx" #include "MessageBox.hxx"
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
@ -146,16 +148,16 @@ MessageBoxResult modalMessageBox(const std::string& caption,
#endif #endif
} }
MessageBoxResult fatalMessageBox(const std::string& caption, [[noreturn]] void fatalMessageBox(const std::string& caption,
const std::string& msg, const std::string& msg,
const std::string& moreText) const std::string& moreText)
{ {
#if defined(SG_WINDOWS) #if defined(SG_WINDOWS)
return win32MessageBox(caption, msg, moreText); win32MessageBox(caption, msg, moreText);
#elif defined(SG_MAC) #elif defined(SG_MAC)
return cocoaFatalMessage(msg, moreText); cocoaFatalMessage(msg, moreText);
#elif defined(HAVE_QT) #elif defined(HAVE_QT)
return QtMessageBox(caption, msg, moreText, true); QtMessageBox(caption, msg, moreText, true);
#else #else
std::string s = "FATAL: "+ msg; std::string s = "FATAL: "+ msg;
if (!moreText.empty()) { if (!moreText.empty()) {
@ -169,8 +171,9 @@ MessageBoxResult fatalMessageBox(const std::string& caption,
dlg->setStringValue("text/label", s ); dlg->setStringValue("text/label", s );
_gui->showDialog("popup"); _gui->showDialog("popup");
} }
return MSG_BOX_OK;
#endif #endif
std::abort();
} }
} // of namespace flightgear } // of namespace flightgear

View file

@ -6,7 +6,7 @@
namespace flightgear namespace flightgear
{ {
enum MessageBoxResult enum MessageBoxResult
{ {
MSG_BOX_OK, MSG_BOX_OK,
MSG_BOX_YES, MSG_BOX_YES,
@ -17,10 +17,10 @@ MessageBoxResult modalMessageBox(const std::string& caption,
const std::string& msg, const std::string& msg,
const std::string& moreText = std::string()); const std::string& moreText = std::string());
MessageBoxResult fatalMessageBox(const std::string& caption, [[noreturn]] void fatalMessageBox(const std::string& caption,
const std::string& msg, const std::string& msg,
const std::string& moreText = std::string()); const std::string& moreText = std::string());
} // of namespace flightgear } // of namespace flightgear
#endif // of FG_GUI_MESSAGE_BOX_HXX #endif // of FG_GUI_MESSAGE_BOX_HXX

View file

@ -1,4 +1,5 @@
#include <string> #include <string>
#include <cstdlib>
#include <simgear/misc/sg_path.hxx> #include <simgear/misc/sg_path.hxx>
#include <simgear/structure/exception.hxx> #include <simgear/structure/exception.hxx>
@ -112,11 +113,11 @@ namespace flightgear
return MSG_BOX_OK; return MSG_BOX_OK;
} }
MessageBoxResult fatalMessageBox(const std::string& caption, [[noreturn]] void fatalMessageBox(const std::string& caption,
const std::string& msg, const std::string& msg,
const std::string& moreText) const std::string& moreText)
{ {
return MSG_BOX_OK; std::abort();
} }
} }