-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support BOOST_ASSERT in C++11 constexpr
- Loading branch information
Showing
3 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
// Copyright (c) 2007, 2014 Peter Dimov | ||
// Copyright (c) Beman Dawes 2011 | ||
// Copyright (c) 2015 Ion Gaztanaga | ||
// Copyright (c) 2025 Glen Joseph Fernandes ([email protected]) | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// See accompanying file LICENSE_1_0.txt or copy at | ||
|
@@ -29,6 +30,7 @@ | |
// BOOST_ASSERT, BOOST_ASSERT_MSG, BOOST_ASSERT_IS_VOID | ||
// | ||
|
||
#undef BOOST_CASSERT | ||
#undef BOOST_ASSERT | ||
#undef BOOST_ASSERT_MSG | ||
#undef BOOST_ASSERT_IS_VOID | ||
|
@@ -61,10 +63,17 @@ namespace boost | |
|
||
#else | ||
|
||
# include <boost/config.hpp> | ||
# include <assert.h> // .h to support old libraries w/o <cassert> - effect is the same | ||
|
||
# define BOOST_ASSERT(expr) assert(expr) | ||
# define BOOST_ASSERT_MSG(expr, msg) assert((expr)&&(msg)) | ||
#if defined(BOOST_GCC) && BOOST_GCC < 50000 | ||
# define BOOST_CASSERT(expr) (BOOST_LIKELY(!!(expr))? ((void)0): __assert_fail (#expr, __FILE__, __LINE__, "")) | ||
#else | ||
# define BOOST_CASSERT(expr) assert(expr) | ||
#endif | ||
|
||
# define BOOST_ASSERT(expr) BOOST_CASSERT(expr) | ||
# define BOOST_ASSERT_MSG(expr, msg) BOOST_CASSERT((expr)&&(msg)) | ||
#if defined(NDEBUG) | ||
# define BOOST_ASSERT_IS_VOID | ||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
Copyright 2025 Glen Joseph Fernandes | ||
([email protected]) | ||
Distributed under the Boost Software License, Version 1.0. | ||
(http://www.boost.org/LICENSE_1_0.txt) | ||
*/ | ||
#include <boost/config.hpp> | ||
#if !defined(BOOST_NO_CXX11_CONSTEXPR) | ||
#include <boost/core/lightweight_test.hpp> | ||
#undef NDEBUG | ||
#include <boost/assert.hpp> | ||
|
||
constexpr int subtract(int a, int b) | ||
{ | ||
return BOOST_ASSERT(a > b), a - b; | ||
} | ||
|
||
constexpr int divide(int a, int b) | ||
{ | ||
return BOOST_ASSERT_MSG(a > b, "text"), a / b; | ||
} | ||
|
||
void test_assert() | ||
{ | ||
constexpr int i = subtract(5, 1); | ||
(void)i; | ||
} | ||
|
||
void test_assert_msg() | ||
{ | ||
constexpr int i = divide(5, 1); | ||
(void)i; | ||
} | ||
#endif |