 
            Module: ppl/ppl Branch: master Commit: 488490ab24f427266b6c305a0c48ecc42ddcf4d4 URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=488490ab24f42...
Author: Enea Zaffanella zaffanella@cs.unipr.it Date: Fri Apr 6 16:38:44 2012 +0200
Improved error message reporting for assertion failures.
---
src/assert.cc | 8 ++++++++ src/assert.hh | 38 +++++++++++++++++++++++++------------- 2 files changed, 33 insertions(+), 13 deletions(-)
diff --git a/src/assert.cc b/src/assert.cc index c9d756a..926539c 100644 --- a/src/assert.cc +++ b/src/assert.cc @@ -42,3 +42,11 @@ PPL::ppl_unreachable_msg(const char* msg, abort(); }
+void +PPL::ppl_assertion_failed(const char* assertion_text, + const char* file, unsigned int line, + const char* function) { + std::cerr << file << ":" << line << ": " << function + << ": Assertion `" << assertion_text << "' failed\n"; + abort(); +} diff --git a/src/assert.hh b/src/assert.hh index 35c2ef1..3039b77 100644 --- a/src/assert.hh +++ b/src/assert.hh @@ -36,6 +36,11 @@ site: http://bugseng.com/products/ppl/ . */ // The PPL_UNREACHABLE macro flags a program point as unreachable. #define PPL_UNREACHABLE PPL_UNREACHABLE_MSG("unreachable")
+// The PPL_ASSERTION_FAILED macro is used to output a message after +// an assertion failure and then cause program termination. +// (It is meant to be used only when assertions are turned on). +#define PPL_ASSERTION_FAILED(msg__) Parma_Polyhedra_Library:: \ + ppl_assertion_failed(msg__, __FILE__, __LINE__, __func__)
// Helper macro PPL_ASSERT_IMPL_: do not use it directly. #if defined(NDEBUG) @@ -43,7 +48,7 @@ site: http://bugseng.com/products/ppl/ . */ #else #define PPL_STRING_(s) #s #define PPL_ASSERT_IMPL_(cond__) \ - ((cond__) ? (void) 0 : PPL_UNREACHABLE_MSG(PPL_STRING_(cond__))) + ((cond__) ? (void) 0 : PPL_ASSERTION_FAILED(PPL_STRING_(cond__))) #endif
@@ -90,17 +95,18 @@ site: http://bugseng.com/products/ppl/ . */
namespace Parma_Polyhedra_Library {
-#ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS -//! Helper function causing program termination by calling \c abort. -#endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS) -void ppl_unreachable() #if PPL_CXX_SUPPORTS_ATTRIBUTE_WEAK - __attribute__((weak, noreturn)); +#define PPL_WEAK_NORETURN __attribute__((weak, noreturn)) #else - __attribute__((noreturn)); +#define PPL_WEAK_NORETURN __attribute__((noreturn)) #endif
#ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS +//! Helper function causing program termination by calling \c abort. +#endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS) +void ppl_unreachable() PPL_WEAK_NORETURN; + +#ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS /*! \brief Helper function printing message on \c std::cerr and causing program termination by calling \c abort. @@ -108,12 +114,18 @@ void ppl_unreachable() #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS) void ppl_unreachable_msg(const char* msg, const char* file, unsigned int line, - const char* function) -#if PPL_CXX_SUPPORTS_ATTRIBUTE_WEAK - __attribute__((weak, noreturn)); -#else - __attribute__((noreturn)); -#endif + const char* function) PPL_WEAK_NORETURN; + +#ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS +/*! \brief + Helper function printing an assertion failure message on \c std::cerr + and causing program termination by calling \c abort. +*/ +#endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS) +void ppl_assertion_failed(const char* assertion_text, + const char* file, unsigned int line, + const char* function) PPL_WEAK_NORETURN; +
#ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS /*! \brief