Provide a way to selectively enable assertions in release mode

- Throwing an assertion exception for proper stack unwinding, making
  sure destructors are called

- On in Debug mode, in Release, enable via:

      cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_ASSERTIONS=ON

Current problem that I'm seeing is that some code is not catching
exceptions or worse silently swallowing them. Would like to check the
whole pipeline before merging this in.
This commit is contained in:
Daniel J. Hofmann
2016-01-20 12:41:33 +01:00
committed by Patrick Niklaus
parent 17f8e65808
commit 502aedb33e
3 changed files with 56 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
#include "util/assert.hpp"
#include <sstream>
namespace
{
// We throw to guarantee for stack-unwinding and therefore our destructors being called.
void assertion_failed_msg_helper(
char const *expr, char const *msg, char const *function, char const *file, long line)
{
std::ostringstream fmt;
fmt << file << ":" << line << "\nin: " << function << ": " << expr << "\n" << msg;
throw osrm::util::assertionError{fmt.str().c_str()};
}
}
// Boost.Assert only declares the following two functions and let's us define them here.
namespace boost
{
void assertion_failed(char const *expr, char const *function, char const *file, long line)
{
::assertion_failed_msg_helper(expr, "", function, file, line);
}
void assertion_failed_msg(
char const *expr, char const *msg, char const *function, char const *file, long line)
{
::assertion_failed_msg_helper(expr, msg, function, file, line);
}
}