assert_msg.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (c) 2001-2013 Hartmut Kaiser
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #if !defined(BOOST_SPIRIT_ASSERT_MSG_JUN_23_2009_0836AM)
  6. #define BOOST_SPIRIT_ASSERT_MSG_JUN_23_2009_0836AM
  7. #if defined(_MSC_VER)
  8. #pragma once
  9. #endif
  10. #include <boost/config.hpp>
  11. // Work around the MPL problem in BOOST_MPL_ASSERT_MSG generating
  12. // multiple definition linker errors for certain compilers (VC++ 8).
  13. // BOOST_SPIRIT_DONT_USE_MPL_ASSERT_MSG can also be defined by user.
  14. #if !defined(BOOST_SPIRIT_DONT_USE_MPL_ASSERT_MSG)
  15. # if defined(BOOST_MSVC) && BOOST_MSVC < 1500
  16. # define BOOST_SPIRIT_DONT_USE_MPL_ASSERT_MSG 1
  17. # endif
  18. #endif
  19. #if !defined(BOOST_NO_CXX11_STATIC_ASSERT) || BOOST_SPIRIT_DONT_USE_MPL_ASSERT_MSG != 0
  20. #include <boost/static_assert.hpp>
  21. #define BOOST_SPIRIT_ASSERT_MSG(Cond, Msg, Types) \
  22. BOOST_STATIC_ASSERT_MSG(Cond, # Msg)
  23. #else
  24. #include <boost/mpl/assert.hpp>
  25. #define BOOST_SPIRIT_ASSERT_MSG(Cond, Msg, Types) \
  26. BOOST_MPL_ASSERT_MSG(Cond, Msg, Types)
  27. #endif
  28. #define BOOST_SPIRIT_ASSERT_MATCH(Domain, Expr) \
  29. BOOST_SPIRIT_ASSERT_MSG(( \
  30. boost::spirit::traits::matches< Domain, Expr >::value \
  31. ), error_invalid_expression, (Expr))
  32. // GCC 4.7 will overeagerly instantiate static_asserts in template functions,
  33. // if the assert condition does not depend on template parameters
  34. // (see https://svn.boost.org/trac/boost/ticket/8381).
  35. // There are places where we want to use constant false as the condition in
  36. // template functions to indicate that these function overloads should never
  37. // be called. This allows to generate better error messages. To solve this
  38. // problem we make the condition dependent on the template argument and use
  39. // the following macro in such places.
  40. #include <boost/type_traits/is_same.hpp>
  41. #define BOOST_SPIRIT_ASSERT_FAIL(TemplateParam, Msg, Types) \
  42. BOOST_SPIRIT_ASSERT_MSG((!boost::is_same< \
  43. TemplateParam, TemplateParam >::value), Msg, Types)
  44. #endif