From e3ab83e770535cd65ea19b51094b4d65347c7995 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 22 Jan 2002 13:38:52 +0000 Subject: [PATCH 01/30] Smart pointer enhancements, initial commit [SVN r12439] --- include/boost/assert.hpp | 52 +++++++++++++++++++++++++++ include/boost/current_function.hpp | 56 ++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 include/boost/assert.hpp create mode 100644 include/boost/current_function.hpp diff --git a/include/boost/assert.hpp b/include/boost/assert.hpp new file mode 100644 index 0000000..3a501dc --- /dev/null +++ b/include/boost/assert.hpp @@ -0,0 +1,52 @@ +#ifndef BOOST_ASSERT_HPP_INCLUDED +#define BOOST_ASSERT_HPP_INCLUDED + +#if _MSC_VER >= 1020 +#pragma once +#endif + +// +// boost/assert.hpp +// +// Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd. +// +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. +// This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. +// + +// +// When BOOST_DEBUG is not defined, it defaults to 0 (off) +// for backward compatibility with programs that do not +// define a boost_error handler +// +// After a reasonable transition period, the default can be +// changed to something more appropriate. +// + +#ifndef BOOST_DEBUG +#define BOOST_DEBUG 0 +#endif + +bool boost_error(char const * expr, char const * func, char const * file, long line); + +#if BOOST_DEBUG + +#include +#include + +#ifndef BOOST_ASSERT + +# define BOOST_ASSERT(expr) ((expr) || !boost_error(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__) || (assert(expr), true)) + +#endif // #ifndef BOOST_ASSERT + +#else // #if BOOST_DEBUG + +#undef BOOST_ASSERT +#define BOOST_ASSERT(expr) ((void)0) + +#endif // #ifdef BOOST_DEBUG + +#endif // #ifndef BOOST_ASSERT_HPP_INCLUDED diff --git a/include/boost/current_function.hpp b/include/boost/current_function.hpp new file mode 100644 index 0000000..e44e26b --- /dev/null +++ b/include/boost/current_function.hpp @@ -0,0 +1,56 @@ +#ifndef BOOST_CURRENT_FUNCTION_HPP_INCLUDED +#define BOOST_CURRENT_FUNCTION_HPP_INCLUDED + +#if _MSC_VER >= 1020 +#pragma once +#endif + +// +// boost/current_function.hpp - BOOST_CURRENT_FUNCTION +// +// Copyright (c) 2002 Peter Dimov and Multi Media Ltd. +// +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. +// This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. +// + +namespace boost +{ + +namespace detail +{ + +void current_function_helper() +{ + +#if defined(__GNUC__) + +# define BOOST_CURRENT_FUNCTION __PRETTY_FUNCTION__ + +#elif defined(__FUNCSIG__) + +# define BOOST_CURRENT_FUNCTION __FUNCSIG__ + +#elif defined(__BORLANDC__) + +# define BOOST_CURRENT_FUNCTION __FUNC__ + +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901) + +# define BOOST_CURRENT_FUNCTION __func__ + +#else + +# define BOOST_CURRENT_FUNCTION "(unknown)" + +#endif + +} + +} // namespace detail + +} // namespace boost + +#endif // #ifndef BOOST_CURRENT_FUNCTION_HPP_INCLUDED From 70fd9789be2202a50a22fa1a9fe97b978a80efc0 Mon Sep 17 00:00:00 2001 From: Darin Adler Date: Tue, 22 Jan 2002 18:28:33 +0000 Subject: [PATCH 02/30] Tweak comments. Include and only when needed. [SVN r12446] --- include/boost/assert.hpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/include/boost/assert.hpp b/include/boost/assert.hpp index 3a501dc..645404d 100644 --- a/include/boost/assert.hpp +++ b/include/boost/assert.hpp @@ -18,26 +18,26 @@ // // When BOOST_DEBUG is not defined, it defaults to 0 (off) -// for backward compatibility with programs that do not -// define a boost_error handler +// for compatibility with programs that do not expect asserts +// in the smart pointer class templates. // -// After a reasonable transition period, the default can be -// changed to something more appropriate. +// This default may be changed after an initial transition period. // #ifndef BOOST_DEBUG #define BOOST_DEBUG 0 #endif -bool boost_error(char const * expr, char const * func, char const * file, long line); - #if BOOST_DEBUG -#include #include #ifndef BOOST_ASSERT +#include + +bool boost_error(char const * expr, char const * func, char const * file, long line); + # define BOOST_ASSERT(expr) ((expr) || !boost_error(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__) || (assert(expr), true)) #endif // #ifndef BOOST_ASSERT @@ -47,6 +47,6 @@ bool boost_error(char const * expr, char const * func, char const * file, long l #undef BOOST_ASSERT #define BOOST_ASSERT(expr) ((void)0) -#endif // #ifdef BOOST_DEBUG +#endif // #if BOOST_DEBUG #endif // #ifndef BOOST_ASSERT_HPP_INCLUDED From 92f489c14c75d2b8251eaef20d53eb1c1efd73c3 Mon Sep 17 00:00:00 2001 From: Darin Adler Date: Thu, 24 Jan 2002 19:15:30 +0000 Subject: [PATCH 03/30] Mark inline to avoid warning with "require prototypes" on. [SVN r12490] --- include/boost/current_function.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/current_function.hpp b/include/boost/current_function.hpp index e44e26b..6d52404 100644 --- a/include/boost/current_function.hpp +++ b/include/boost/current_function.hpp @@ -22,7 +22,7 @@ namespace boost namespace detail { -void current_function_helper() +inline void current_function_helper() { #if defined(__GNUC__) From 66baadce559054dd9ad21c09c9c333b04c4075da Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 25 Jan 2002 13:54:30 +0000 Subject: [PATCH 04/30] Added tests for the new smart pointers. [SVN r12500] --- assert_test.cpp | 33 +++++++++++++++++++++++++++++++++ current_function_test.cpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 assert_test.cpp create mode 100644 current_function_test.cpp diff --git a/assert_test.cpp b/assert_test.cpp new file mode 100644 index 0000000..5813e25 --- /dev/null +++ b/assert_test.cpp @@ -0,0 +1,33 @@ +#if defined(_MSC_VER) && !defined(__ICL) +#pragma warning(disable: 4786) // identifier truncated in debug info +#pragma warning(disable: 4710) // function not inlined +#pragma warning(disable: 4711) // function selected for automatic inline expansion +#pragma warning(disable: 4514) // unreferenced inline removed +#endif + +// +// assert_test.cpp - a test for boost/assert.hpp +// +// Copyright (c) 2002 Peter Dimov and Multi Media Ltd. +// +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. +// This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. +// + +#define BOOST_DEBUG 1 + +#include +#include + +bool boost_error(char const * expr, char const * func, char const * file, long line) +{ + std::printf("%s(%ld): Assertion '%s' failed in function '%s'\n", file, line, expr, func); + return true; // fail w/ standard assert() +} + +int main() +{ + BOOST_ASSERT(0 == 1); +} diff --git a/current_function_test.cpp b/current_function_test.cpp new file mode 100644 index 0000000..620a45e --- /dev/null +++ b/current_function_test.cpp @@ -0,0 +1,32 @@ +#if defined(_MSC_VER) && !defined(__ICL) +#pragma warning(disable: 4786) // identifier truncated in debug info +#pragma warning(disable: 4710) // function not inlined +#pragma warning(disable: 4711) // function selected for automatic inline expansion +#pragma warning(disable: 4514) // unreferenced inline removed +#endif + +// +// current_function_test.cpp - a test for boost/current_function.hpp +// +// Copyright (c) 2002 Peter Dimov and Multi Media Ltd. +// +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. +// This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. +// + +#include +#include + +void message(char const * file, long line, char const * func, char const * msg) +{ + std::printf("%s(%ld): %s in function '%s'\n", file, line, msg, func); +} + +#define MESSAGE(msg) message(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION, msg) + +int main() +{ + MESSAGE("assertion failed"); +} From a4645917d754991cbdcd97cd1fe6a3f21d6304e5 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 14 Nov 2002 14:41:25 +0000 Subject: [PATCH 05/30] BOOST_CURRENT_FUNCTION documentation added. [SVN r16236] --- current_function.html | 38 ++++++++++++++++++++++++++++++ include/boost/current_function.hpp | 2 ++ 2 files changed, 40 insertions(+) create mode 100644 current_function.html diff --git a/current_function.html b/current_function.html new file mode 100644 index 0000000..158cd4e --- /dev/null +++ b/current_function.html @@ -0,0 +1,38 @@ + + + + Boost: current_function.hpp documentation + + + + + + + + + + + +
+ c++boost.gif (8819 bytes) + +

current_function.hpp

+
 
+

+ The header <boost/current_function.hpp> defines a single + macro, BOOST_CURRENT_FUNCTION, similar to the + C99 macro __func__. +

+

BOOST_CURRENT_FUNCTION expands to a string literal containing + the (fully qualified, if possible) name of the enclosing function. If there is + no enclosing function, the behavior is undefined.

+

Some compilers do not provide a way to obtain the name of the current enclosing + function. On such compilers, the string literal has an unspecified value.

+

+
+ Copyright © 2002 by Peter Dimov. Permission to copy, use, modify, sell and + distribute this document is granted provided this copyright notice appears in + all copies. This document is provided "as is" without express or implied + warranty, and with no claim as to its suitability for any purpose.

+ + diff --git a/include/boost/current_function.hpp b/include/boost/current_function.hpp index 6d52404..0b2841a 100644 --- a/include/boost/current_function.hpp +++ b/include/boost/current_function.hpp @@ -15,6 +15,8 @@ // This software is provided "as is" without express or implied // warranty, and with no claim as to its suitability for any purpose. // +// http://www.boost.org/libs/utility/current_function.html +// namespace boost { From 41dc437de1b1b90196628e0788af572944152574 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 14 Nov 2002 16:09:29 +0000 Subject: [PATCH 06/30] New BOOST_ASSERT, including documentation. [SVN r16240] --- assert.html | 57 ++++++++++++++++++++++++ assert_test.cpp | 96 +++++++++++++++++++++++++++++++++++----- include/boost/assert.hpp | 46 +++++++------------ 3 files changed, 156 insertions(+), 43 deletions(-) create mode 100644 assert.html diff --git a/assert.html b/assert.html new file mode 100644 index 0000000..d34ce36 --- /dev/null +++ b/assert.html @@ -0,0 +1,57 @@ + + + + Boost: assert.hpp documentation + + + + + + + + + + + +
+ c++boost.gif (8819 bytes) + +

assert.hpp

+
 
+

+ The header <boost/assert.hpp> defines the macro BOOST_ASSERT, + which is similar to the standard assert macro defined in <cassert>. + The macro is intended to be used in Boost libraries. +

+

By default, BOOST_ASSERT(expr) is equivalent to assert(expr).

+

When the macro BOOST_DISABLE_ASSERTS is defined when <boost/assert.hpp> + is included, BOOST_ASSERT(expr) is defined as ((void)0). This + allows users to selectively disable BOOST_ASSERT without + affecting the definition of the standard assert.

+

When the macro BOOST_ENABLE_ASSERT_HANDLER is defined when <boost/assert.hpp> + is included, BOOST_ASSERT(expr) evaluates expr and, if the + result is false, evaluates the expression

+

::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, + __FILE__, __LINE__)

+

assertion_failed is declared in <boost/assert.hpp> + as

+
+namespace boost
+{
+
+void assertion_failed(char const * expr, char const * function, char const * file, long line);
+
+}
+
+

but it is never defined. The user is expected to supply an appropriate + definition.

+

As is the case with <cassert>, <boost/assert.hpp> + can be included multiple times in a single translation unit. BOOST_ASSERT + will be redefined each time as specified above.

+


+ Copyright © 2002 by Peter Dimov. Permission to copy, use, modify, sell and + distribute this document is granted provided this copyright notice appears in + all copies. This document is provided "as is" without express or implied + warranty, and with no claim as to its suitability for any purpose.

+ + diff --git a/assert_test.cpp b/assert_test.cpp index 5813e25..3a7f892 100644 --- a/assert_test.cpp +++ b/assert_test.cpp @@ -1,10 +1,3 @@ -#if defined(_MSC_VER) && !defined(__ICL) -#pragma warning(disable: 4786) // identifier truncated in debug info -#pragma warning(disable: 4710) // function not inlined -#pragma warning(disable: 4711) // function selected for automatic inline expansion -#pragma warning(disable: 4514) // unreferenced inline removed -#endif - // // assert_test.cpp - a test for boost/assert.hpp // @@ -16,18 +9,97 @@ // warranty, and with no claim as to its suitability for any purpose. // -#define BOOST_DEBUG 1 +#include +#include + +void test_default() +{ + int x = 1; + + BOOST_ASSERT(1); + BOOST_ASSERT(x); + BOOST_ASSERT(x == 1); + BOOST_ASSERT(&x); +} + +#define BOOST_DISABLE_ASSERTS +#include + +void test_disabled() +{ + int x = 1; + + BOOST_ASSERT(1); + BOOST_ASSERT(x); + BOOST_ASSERT(x == 1); + BOOST_ASSERT(&x); + + BOOST_ASSERT(0); + BOOST_ASSERT(!x); + BOOST_ASSERT(x == 0); + + void * p = 0; + + BOOST_ASSERT(p); + + // supress warnings + p = &x; + p = &p; +} + +#undef BOOST_DISABLE_ASSERTS + +#define BOOST_ENABLE_ASSERT_HANDLER #include #include -bool boost_error(char const * expr, char const * func, char const * file, long line) +int handler_invoked = 0; + +void boost::assertion_failed(char const * expr, char const * function, char const * file, long line) { - std::printf("%s(%ld): Assertion '%s' failed in function '%s'\n", file, line, expr, func); - return true; // fail w/ standard assert() + std::printf("Expression: %s\nFunction: %s\nFile: %s\nLine: %ld\n\n", expr, function, file, line); + ++handler_invoked; } +struct X +{ + static void f() + { + BOOST_ASSERT(0); + } +}; + +void test_handler() +{ + int x = 1; + + BOOST_ASSERT(1); + BOOST_ASSERT(x); + BOOST_ASSERT(x == 1); + BOOST_ASSERT(&x); + + BOOST_ASSERT(0); + BOOST_ASSERT(!x); + BOOST_ASSERT(x == 0); + + void * p = 0; + + BOOST_ASSERT(p); + + X::f(); + + BOOST_ASSERT(handler_invoked == 5); + BOOST_TEST(handler_invoked == 5); +} + +#undef BOOST_ENABLE_ASSERT_HANDLER + int main() { - BOOST_ASSERT(0 == 1); + test_default(); + test_disabled(); + test_handler(); + + return boost::report_errors(); } diff --git a/include/boost/assert.hpp b/include/boost/assert.hpp index 645404d..c288a1f 100644 --- a/include/boost/assert.hpp +++ b/include/boost/assert.hpp @@ -1,12 +1,5 @@ -#ifndef BOOST_ASSERT_HPP_INCLUDED -#define BOOST_ASSERT_HPP_INCLUDED - -#if _MSC_VER >= 1020 -#pragma once -#endif - // -// boost/assert.hpp +// boost/assert.hpp - BOOST_ASSERT(expr) // // Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd. // @@ -15,38 +8,29 @@ // This software is provided "as is" without express or implied // warranty, and with no claim as to its suitability for any purpose. // - -// -// When BOOST_DEBUG is not defined, it defaults to 0 (off) -// for compatibility with programs that do not expect asserts -// in the smart pointer class templates. -// -// This default may be changed after an initial transition period. +// Note: There are no include guards. This is intentional. // -#ifndef BOOST_DEBUG -#define BOOST_DEBUG 0 -#endif +#undef BOOST_ASSERT -#if BOOST_DEBUG +#if defined(BOOST_DISABLE_ASSERTS) -#include +# define BOOST_ASSERT(expr) ((void)0) -#ifndef BOOST_ASSERT +#elif defined(BOOST_ENABLE_ASSERT_HANDLER) #include -bool boost_error(char const * expr, char const * func, char const * file, long line); +namespace boost +{ -# define BOOST_ASSERT(expr) ((expr) || !boost_error(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__) || (assert(expr), true)) +void assertion_failed(char const * expr, char const * function, char const * file, long line); // user defined -#endif // #ifndef BOOST_ASSERT +} // namespace boost -#else // #if BOOST_DEBUG +#define BOOST_ASSERT(expr) ((expr)? ((void)0): ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) -#undef BOOST_ASSERT -#define BOOST_ASSERT(expr) ((void)0) - -#endif // #if BOOST_DEBUG - -#endif // #ifndef BOOST_ASSERT_HPP_INCLUDED +#else +# include +# define BOOST_ASSERT(expr) assert(expr) +#endif From 8b3775a148ee32c8b21980d3cb0eabe75f7130d3 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 15 Nov 2002 19:44:18 +0000 Subject: [PATCH 07/30] Metrowerks support (Bertolt Mildner) [SVN r16263] --- include/boost/current_function.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/current_function.hpp b/include/boost/current_function.hpp index 0b2841a..2cfd604 100644 --- a/include/boost/current_function.hpp +++ b/include/boost/current_function.hpp @@ -27,7 +27,7 @@ namespace detail inline void current_function_helper() { -#if defined(__GNUC__) +#if defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) # define BOOST_CURRENT_FUNCTION __PRETTY_FUNCTION__ From 694783127b73e3f66856f812d4c5e5cfcbcb8dc9 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 28 Nov 2002 13:32:44 +0000 Subject: [PATCH 08/30] Fix: Comeau with bcc32 as backend defines __BORLANDC__ as 1. [SVN r16455] --- include/boost/current_function.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/current_function.hpp b/include/boost/current_function.hpp index 2cfd604..66cb729 100644 --- a/include/boost/current_function.hpp +++ b/include/boost/current_function.hpp @@ -35,7 +35,7 @@ inline void current_function_helper() # define BOOST_CURRENT_FUNCTION __FUNCSIG__ -#elif defined(__BORLANDC__) +#elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x550) # define BOOST_CURRENT_FUNCTION __FUNC__ From a234c7dc84291e19cdc2f499bbb63451781a03e0 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Mon, 23 Dec 2002 02:43:12 +0000 Subject: [PATCH 09/30] Add /libs/lib-name to comment [SVN r16685] --- include/boost/assert.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/boost/assert.hpp b/include/boost/assert.hpp index c288a1f..4680408 100644 --- a/include/boost/assert.hpp +++ b/include/boost/assert.hpp @@ -11,6 +11,9 @@ // Note: There are no include guards. This is intentional. // +// See http://www.boost.org/libs/utility for Documentation. + + #undef BOOST_ASSERT #if defined(BOOST_DISABLE_ASSERTS) From b8e53506cc689ffb51a70c22434a86197fa17ba4 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 24 Dec 2002 12:34:42 +0000 Subject: [PATCH 10/30] Doc link updated. [SVN r16699] --- include/boost/assert.hpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/boost/assert.hpp b/include/boost/assert.hpp index 4680408..754ebb9 100644 --- a/include/boost/assert.hpp +++ b/include/boost/assert.hpp @@ -10,9 +10,8 @@ // // Note: There are no include guards. This is intentional. // - -// See http://www.boost.org/libs/utility for Documentation. - +// See http://www.boost.org/libs/utility/assert.html for documentation. +// #undef BOOST_ASSERT From fe022231afd247e9eeda5b91addbcf06ebb034e6 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 10 Feb 2003 16:25:41 +0000 Subject: [PATCH 11/30] __func__ is a predefined identifier, not a macro. [SVN r17308] --- current_function.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/current_function.html b/current_function.html index 158cd4e..e1b25d5 100644 --- a/current_function.html +++ b/current_function.html @@ -21,7 +21,7 @@

The header <boost/current_function.hpp> defines a single macro, BOOST_CURRENT_FUNCTION, similar to the - C99 macro __func__. + C99 predefined identifier __func__.

BOOST_CURRENT_FUNCTION expands to a string literal containing the (fully qualified, if possible) name of the enclosing function. If there is From 3ed6515a2a182d9b19903a13c50af81bf3f26068 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 23 May 2003 22:30:23 +0000 Subject: [PATCH 12/30] Intel support. [SVN r18520] --- include/boost/current_function.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/boost/current_function.hpp b/include/boost/current_function.hpp index 66cb729..732fb2d 100644 --- a/include/boost/current_function.hpp +++ b/include/boost/current_function.hpp @@ -27,7 +27,7 @@ namespace detail inline void current_function_helper() { -#if defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) +#if defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) || (defined(__ICC) && (__ICC >= 600)) # define BOOST_CURRENT_FUNCTION __PRETTY_FUNCTION__ @@ -35,6 +35,10 @@ inline void current_function_helper() # define BOOST_CURRENT_FUNCTION __FUNCSIG__ +#elif defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600) + +# define BOOST_CURRENT_FUNCTION __FUNCTION__ + #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x550) # define BOOST_CURRENT_FUNCTION __FUNC__ From 311ba57d5db476ef9633937d9061e9b9d39c6b72 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Wed, 28 May 2003 13:45:58 +0000 Subject: [PATCH 13/30] IBM C++ support added. [SVN r18587] --- include/boost/current_function.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/current_function.hpp b/include/boost/current_function.hpp index 732fb2d..516a394 100644 --- a/include/boost/current_function.hpp +++ b/include/boost/current_function.hpp @@ -35,7 +35,7 @@ inline void current_function_helper() # define BOOST_CURRENT_FUNCTION __FUNCSIG__ -#elif defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600) +#elif (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600)) || (defined(__IBMCPP__) && (__IBMCPP__ >= 500)) # define BOOST_CURRENT_FUNCTION __FUNCTION__ From 4bf34fe7fb0eb3ed39747396496528486b62fbe3 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 12 Jun 2003 17:09:24 +0000 Subject: [PATCH 14/30] -Wundef fixes. [SVN r18788] --- include/boost/current_function.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/current_function.hpp b/include/boost/current_function.hpp index 516a394..38aeab2 100644 --- a/include/boost/current_function.hpp +++ b/include/boost/current_function.hpp @@ -1,8 +1,8 @@ #ifndef BOOST_CURRENT_FUNCTION_HPP_INCLUDED #define BOOST_CURRENT_FUNCTION_HPP_INCLUDED -#if _MSC_VER >= 1020 -#pragma once +#if defined(_MSC_VER) && (_MSC_VER >= 1020) +# pragma once #endif // From 56b3a933f1a71afb060eed46d49318c826fbf0d2 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 28 Nov 2003 15:35:21 +0000 Subject: [PATCH 15/30] _MSC_VER use clarified. [SVN r20992] --- current_function_test.cpp | 4 +++- include/boost/current_function.hpp | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/current_function_test.cpp b/current_function_test.cpp index 620a45e..a724986 100644 --- a/current_function_test.cpp +++ b/current_function_test.cpp @@ -1,4 +1,6 @@ -#if defined(_MSC_VER) && !defined(__ICL) +#include + +#if defined(BOOST_MSVC) #pragma warning(disable: 4786) // identifier truncated in debug info #pragma warning(disable: 4710) // function not inlined #pragma warning(disable: 4711) // function selected for automatic inline expansion diff --git a/include/boost/current_function.hpp b/include/boost/current_function.hpp index 38aeab2..4aea5ef 100644 --- a/include/boost/current_function.hpp +++ b/include/boost/current_function.hpp @@ -1,6 +1,8 @@ #ifndef BOOST_CURRENT_FUNCTION_HPP_INCLUDED #define BOOST_CURRENT_FUNCTION_HPP_INCLUDED +// MS compatible compilers support #pragma once + #if defined(_MSC_VER) && (_MSC_VER >= 1020) # pragma once #endif From b3cbbcd15788918f63d9b0bbb59e3f323224b1b6 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Mon, 26 Jul 2004 00:32:12 +0000 Subject: [PATCH 16/30] Converted to Boost Software License, Version 1.0 [SVN r24055] --- assert_test.cpp | 7 +++---- current_function_test.cpp | 7 +++---- include/boost/assert.hpp | 7 +++---- include/boost/current_function.hpp | 7 +++---- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/assert_test.cpp b/assert_test.cpp index 3a7f892..24f9761 100644 --- a/assert_test.cpp +++ b/assert_test.cpp @@ -3,10 +3,9 @@ // // Copyright (c) 2002 Peter Dimov and Multi Media Ltd. // -// Permission to copy, use, modify, sell and distribute this software -// is granted provided this copyright notice appears in all copies. -// This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) // #include diff --git a/current_function_test.cpp b/current_function_test.cpp index a724986..7510948 100644 --- a/current_function_test.cpp +++ b/current_function_test.cpp @@ -12,10 +12,9 @@ // // Copyright (c) 2002 Peter Dimov and Multi Media Ltd. // -// Permission to copy, use, modify, sell and distribute this software -// is granted provided this copyright notice appears in all copies. -// This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) // #include diff --git a/include/boost/assert.hpp b/include/boost/assert.hpp index 754ebb9..3428efb 100644 --- a/include/boost/assert.hpp +++ b/include/boost/assert.hpp @@ -3,10 +3,9 @@ // // Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd. // -// Permission to copy, use, modify, sell and distribute this software -// is granted provided this copyright notice appears in all copies. -// This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) // // Note: There are no include guards. This is intentional. // diff --git a/include/boost/current_function.hpp b/include/boost/current_function.hpp index 4aea5ef..40e3abd 100644 --- a/include/boost/current_function.hpp +++ b/include/boost/current_function.hpp @@ -12,10 +12,9 @@ // // Copyright (c) 2002 Peter Dimov and Multi Media Ltd. // -// Permission to copy, use, modify, sell and distribute this software -// is granted provided this copyright notice appears in all copies. -// This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) // // http://www.boost.org/libs/utility/current_function.html // From 2186daa15f81e643415975e306b3c38eb89a4a5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20M=2E=20L=C3=B3pez=20Mu=C3=B1oz?= Date: Wed, 22 Sep 2004 17:18:06 +0000 Subject: [PATCH 17/30] taken care of BOOST_NO_STDC_NAMESPACE [SVN r25345] --- assert_test.cpp | 7 ++++++- current_function_test.cpp | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/assert_test.cpp b/assert_test.cpp index 24f9761..693adc4 100644 --- a/assert_test.cpp +++ b/assert_test.cpp @@ -51,13 +51,18 @@ void test_disabled() #define BOOST_ENABLE_ASSERT_HANDLER #include +#include #include int handler_invoked = 0; void boost::assertion_failed(char const * expr, char const * function, char const * file, long line) { - std::printf("Expression: %s\nFunction: %s\nFile: %s\nLine: %ld\n\n", expr, function, file, line); +#if !defined(BOOST_NO_STDC_NAMESPACE) + using std::printf; +#endif + + printf("Expression: %s\nFunction: %s\nFile: %s\nLine: %ld\n\n", expr, function, file, line); ++handler_invoked; } diff --git a/current_function_test.cpp b/current_function_test.cpp index 7510948..d5651ad 100644 --- a/current_function_test.cpp +++ b/current_function_test.cpp @@ -18,11 +18,16 @@ // #include +#include #include void message(char const * file, long line, char const * func, char const * msg) { - std::printf("%s(%ld): %s in function '%s'\n", file, line, msg, func); +#if !defined(BOOST_NO_STDC_NAMESPACE) + using std::printf; +#endif + + printf("%s(%ld): %s in function '%s'\n", file, line, msg, func); } #define MESSAGE(msg) message(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION, msg) From 8f21ef02b40cffc5b94f055ddeecad9df7911d65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20M=2E=20L=C3=B3pez=20Mu=C3=B1oz?= Date: Fri, 24 Sep 2004 06:17:26 +0000 Subject: [PATCH 18/30] added explicit return to main [SVN r25387] --- current_function_test.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/current_function_test.cpp b/current_function_test.cpp index d5651ad..1343901 100644 --- a/current_function_test.cpp +++ b/current_function_test.cpp @@ -35,4 +35,6 @@ void message(char const * file, long line, char const * func, char const * msg) int main() { MESSAGE("assertion failed"); + + return 0; } From 10bb5612a839048a416ce00c0692ed320c2166b5 Mon Sep 17 00:00:00 2001 From: Aleksey Gurtovoy Date: Tue, 5 Oct 2004 15:45:52 +0000 Subject: [PATCH 19/30] c++boost.gif -> boost.png replacement [SVN r25573] --- assert.html | 2 +- current_function.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/assert.html b/assert.html index d34ce36..617f212 100644 --- a/assert.html +++ b/assert.html @@ -8,7 +8,7 @@
- c++boost.gif (8819 bytes) + boost.png (6897 bytes)

assert.hpp

diff --git a/current_function.html b/current_function.html index e1b25d5..31633f8 100644 --- a/current_function.html +++ b/current_function.html @@ -8,7 +8,7 @@
- c++boost.gif (8819 bytes) + boost.png (6897 bytes)

current_function.hpp

From 63e020677a9368a7ffcf38780ed87c199fb503ca Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Mon, 21 Feb 2005 12:32:20 +0000 Subject: [PATCH 20/30] Add comment explaining use of assert.h [SVN r27473] --- include/boost/assert.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/assert.hpp b/include/boost/assert.hpp index 3428efb..5619f29 100644 --- a/include/boost/assert.hpp +++ b/include/boost/assert.hpp @@ -32,6 +32,6 @@ void assertion_failed(char const * expr, char const * function, char const * fil #define BOOST_ASSERT(expr) ((expr)? ((void)0): ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) #else -# include +# include // .h to support old libraries w/o - effect is the same # define BOOST_ASSERT(expr) assert(expr) #endif From f930c303fb398c32c22277795b06f09687b95241 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 25 Sep 2005 21:54:19 +0000 Subject: [PATCH 21/30] Made the Boost logo link to the home page [SVN r31112] --- assert.html | 5 ++--- current_function.html | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/assert.html b/assert.html index 617f212..a3dec66 100644 --- a/assert.html +++ b/assert.html @@ -7,10 +7,9 @@ - - diff --git a/current_function.html b/current_function.html index 31633f8..f383e3a 100644 --- a/current_function.html +++ b/current_function.html @@ -7,10 +7,9 @@
- boost.png (6897 bytes) + boost.png (6897 bytes) +

assert.hpp

- - From a11aaaa9d20d1bb5ed0137aa4b4cf09a0e70c486 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 9 Nov 2006 20:34:33 +0000 Subject: [PATCH 22/30] License/copyright edits [SVN r35958] --- assert.html | 7 +++---- current_function.html | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/assert.html b/assert.html index a3dec66..4381ae1 100644 --- a/assert.html +++ b/assert.html @@ -48,9 +48,8 @@ void assertion_failed(char const * expr, char const * function, char const * fil can be included multiple times in a single translation unit. BOOST_ASSERT will be redefined each time as specified above.


- Copyright © 2002 by Peter Dimov. Permission to copy, use, modify, sell and - distribute this document is granted provided this copyright notice appears in - all copies. This document is provided "as is" without express or implied - warranty, and with no claim as to its suitability for any purpose.

+ Copyright © 2002 by Peter Dimov. Distributed under the Boost Software License, Version + 1.0. See accompanying file LICENSE_1_0.txt or + copy at http://www.boost.org/LICENSE_1_0.txt.

diff --git a/current_function.html b/current_function.html index f383e3a..373eb22 100644 --- a/current_function.html +++ b/current_function.html @@ -29,9 +29,8 @@ function. On such compilers, the string literal has an unspecified value.


- Copyright © 2002 by Peter Dimov. Permission to copy, use, modify, sell and - distribute this document is granted provided this copyright notice appears in - all copies. This document is provided "as is" without express or implied - warranty, and with no claim as to its suitability for any purpose.

+ Copyright © 2002 by Peter Dimov. Distributed under the Boost Software License, Version + 1.0. See accompanying file LICENSE_1_0.txt or + copy at http://www.boost.org/LICENSE_1_0.txt.

From f504e95d1024e07754164a26feabfe06e2cc7aa2 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Sun, 25 Nov 2007 18:07:19 +0000 Subject: [PATCH 23/30] Full merge from trunk at revision 41356 of entire boost-root tree. [SVN r41369] --- include/boost/assert.hpp | 13 +++++++++++++ include/boost/current_function.hpp | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/include/boost/assert.hpp b/include/boost/assert.hpp index 5619f29..c227f17 100644 --- a/include/boost/assert.hpp +++ b/include/boost/assert.hpp @@ -2,6 +2,7 @@ // boost/assert.hpp - BOOST_ASSERT(expr) // // Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd. +// Copyright (c) 2007 Peter Dimov // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at @@ -35,3 +36,15 @@ void assertion_failed(char const * expr, char const * function, char const * fil # include // .h to support old libraries w/o - effect is the same # define BOOST_ASSERT(expr) assert(expr) #endif + +#undef BOOST_VERIFY + +#if defined(BOOST_DISABLE_ASSERTS) || ( !defined(BOOST_ENABLE_ASSERT_HANDLER) && defined(NDEBUG) ) + +# define BOOST_VERIFY(expr) ((void)(expr)) + +#else + +# define BOOST_VERIFY(expr) BOOST_ASSERT(expr) + +#endif diff --git a/include/boost/current_function.hpp b/include/boost/current_function.hpp index 40e3abd..aa5756e 100644 --- a/include/boost/current_function.hpp +++ b/include/boost/current_function.hpp @@ -32,6 +32,10 @@ inline void current_function_helper() # define BOOST_CURRENT_FUNCTION __PRETTY_FUNCTION__ +#elif defined(__DMC__) && (__DMC__ >= 0x810) + +# define BOOST_CURRENT_FUNCTION __PRETTY_FUNCTION__ + #elif defined(__FUNCSIG__) # define BOOST_CURRENT_FUNCTION __FUNCSIG__ From 4c30883005ec1ba8a94f048bff739e89e3edab66 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Sun, 25 Nov 2007 18:38:02 +0000 Subject: [PATCH 24/30] Full merge from trunk at revision 41356 of entire boost-root tree. [SVN r41370] --- assert.html | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/assert.html b/assert.html index 4381ae1..a970cef 100644 --- a/assert.html +++ b/assert.html @@ -47,9 +47,15 @@ void assertion_failed(char const * expr, char const * function, char const * fil

As is the case with <cassert>, <boost/assert.hpp> can be included multiple times in a single translation unit. BOOST_ASSERT will be redefined each time as specified above.

+

<boost/assert.hpp> also defines the macro BOOST_VERIFY. + It has exactly the same behavior as BOOST_ASSERT, except that + the expression that is passed to BOOST_VERIFY is always + evaluated. This is useful when the asserted expression has desirable side + effects; it can also help suppress warnings about unused variables when the + only use of the variable is inside an assertion.


- Copyright © 2002 by Peter Dimov. Distributed under the Boost Software License, Version - 1.0. See accompanying file LICENSE_1_0.txt or - copy at http://www.boost.org/LICENSE_1_0.txt.

+ Copyright © 2002, 2007 by Peter Dimov. Distributed under the Boost Software + License, Version 1.0. See accompanying file LICENSE_1_0.txt + or copy at http://www.boost.org/LICENSE_1_0.txt.

From 35be7b7c4e0cc44029c4dbf5cef716ec5a488ee8 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Sun, 25 Nov 2007 22:34:55 +0000 Subject: [PATCH 25/30] Pick up missing smart_ptr, utility, and type_traits files from full merge from trunk at revision 41356 of entire boost-root tree. [SVN r41386] --- verify_test.cpp | 126 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 verify_test.cpp diff --git a/verify_test.cpp b/verify_test.cpp new file mode 100644 index 0000000..3481636 --- /dev/null +++ b/verify_test.cpp @@ -0,0 +1,126 @@ +// +// verify_test.cpp - a test for BOOST_VERIFY +// +// Copyright (c) 2002 Peter Dimov and Multi Media Ltd. +// Copyright (c) 2007 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// + +#include + +#include + +int f( int & x ) +{ + return ++x; +} + +void test_default() +{ + int x = 1; + + BOOST_VERIFY( 1 ); + BOOST_VERIFY( x == 1 ); + BOOST_VERIFY( ++x ); + BOOST_VERIFY( f(x) ); + BOOST_VERIFY( &x ); + + BOOST_TEST( x == 3 ); +} + +#define BOOST_DISABLE_ASSERTS +#include + +void test_disabled() +{ + int x = 1; + + BOOST_VERIFY( 1 ); + BOOST_VERIFY( x == 1 ); + BOOST_VERIFY( ++x ); + BOOST_VERIFY( f(x) ); + BOOST_VERIFY( &x ); + + BOOST_TEST( x == 3 ); + + BOOST_VERIFY( 0 ); + BOOST_VERIFY( !x ); + BOOST_VERIFY( x == 0 ); + BOOST_VERIFY( !++x ); + BOOST_VERIFY( !f(x) ); + + BOOST_TEST( x == 5 ); + + void * p = 0; + BOOST_VERIFY( p ); +} + +#undef BOOST_DISABLE_ASSERTS + +#define BOOST_ENABLE_ASSERT_HANDLER +#include +#include +#include + +int handler_invoked = 0; + +void boost::assertion_failed(char const * expr, char const * function, char const * file, long line) +{ +#if !defined(BOOST_NO_STDC_NAMESPACE) + using std::printf; +#endif + + printf("Expression: %s\nFunction: %s\nFile: %s\nLine: %ld\n\n", expr, function, file, line); + ++handler_invoked; +} + +struct X +{ + static bool f() + { + BOOST_VERIFY( 0 ); + return false; + } +}; + +void test_handler() +{ + int x = 1; + + BOOST_VERIFY( 1 ); + BOOST_VERIFY( x == 1 ); + BOOST_VERIFY( ++x ); + BOOST_VERIFY( f(x) ); + BOOST_VERIFY( &x ); + + BOOST_TEST( x == 3 ); + + BOOST_VERIFY( 0 ); + BOOST_VERIFY( !x ); + BOOST_VERIFY( x == 0 ); + BOOST_VERIFY( !++x ); + BOOST_VERIFY( !f(x) ); + + BOOST_TEST( x == 5 ); + + void * p = 0; + BOOST_VERIFY( p ); + + BOOST_VERIFY( X::f() ); + + BOOST_TEST( handler_invoked == 8 ); +} + +#undef BOOST_ENABLE_ASSERT_HANDLER + +int main() +{ + test_default(); + test_disabled(); + test_handler(); + + return boost::report_errors(); +} From c43e938a1f4a47e693625afb7b2c1d228f2b0244 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Tue, 15 Feb 2011 14:54:16 +0000 Subject: [PATCH 26/30] Merge trunk BOOST_ASSERT_MSG additions [SVN r68912] --- assert.html | 74 ++++++++++++++++++++++++++++++++++++++++++------- assert_test.cpp | 44 +++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 10 deletions(-) diff --git a/assert.html b/assert.html index a970cef..5f3f6e7 100644 --- a/assert.html +++ b/assert.html @@ -17,36 +17,89 @@
- boost.png (6897 bytes) + boost.png (6897 bytes) +

current_function.hpp

 
+

+ BOOST_ASSERT
+ BOOST_ASSERT_MSG
+ BOOST_VERIFY

+ +

BOOST_ASSERT

The header <boost/assert.hpp> defines the macro BOOST_ASSERT, which is similar to the standard assert macro defined in <cassert>. - The macro is intended to be used in Boost libraries. + The macro is intended to be used in both Boost libraries and user + code.

By default, BOOST_ASSERT(expr) is equivalent to assert(expr).

-

When the macro BOOST_DISABLE_ASSERTS is defined when <boost/assert.hpp> +

If the macro BOOST_DISABLE_ASSERTS is defined when <boost/assert.hpp> is included, BOOST_ASSERT(expr) is defined as ((void)0). This allows users to selectively disable BOOST_ASSERT without affecting the definition of the standard assert.

-

When the macro BOOST_ENABLE_ASSERT_HANDLER is defined when <boost/assert.hpp> +

If the macro BOOST_ENABLE_ASSERT_HANDLER is defined when <boost/assert.hpp> is included, BOOST_ASSERT(expr) evaluates expr and, if the result is false, evaluates the expression

+

::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)

+

assertion_failed is declared in <boost/assert.hpp> as

-
-namespace boost
+		
+
namespace boost
 {
-
-void assertion_failed(char const * expr, char const * function, char const * file, long line);
-
+  void assertion_failed(char const * expr, char const * function, char const * file, long line);
 }
 
+

but it is never defined. The user is expected to supply an appropriate definition.

As is the case with <cassert>, <boost/assert.hpp> can be included multiple times in a single translation unit. BOOST_ASSERT will be redefined each time as specified above.

+ +

BOOST_ASSERT_MSG

+

+ The header <boost/assert.hpp> defines the macro BOOST_ASSERT_MSG, + which is similar to the standard assert macro defined in <cassert>, + but with an additional macro parameter supplying an error message. The macro is intended to be used in both Boost libraries + and user code. +

+

BOOST_ASSERT_MSG(expr, msg) is equivalent to + ((void)0) if BOOST_DISABLE_ASSERTS or NDEBUG are + defined or expr evaluates to true. If those + macros and BOOST_ENABLE_ASSERT_HANDLER are not + defined, and expr evaluates to false, an error + message that includes #expr, msg, BOOST_CURRENT_FUNCTION, + __FILE__, and __LINE__ is sent to output stream + BOOST_ASSERT_MSG_OSTREAM + and std::abort() is called.

+

BOOST_ASSERT_MSG_OSTREAM defines the output stream. It defaults to std::cerr. + Integrated development environments (IDE's) like Microsoft Visual Studio + may produce easier to understand output if messages go to a different + stream, such as std::cout. Users may define BOOST_ASSERT_MSG_OSTREAM before including <boost/assert.hpp> + to specify a different output stream. 

+

If the macro BOOST_ENABLE_ASSERT_HANDLER is defined when <boost/assert.hpp> + is included, instead of sending a error message to an output + stream, this expression is evaluated

+
+

::boost::assertion_failed_msg(#expr, msg, BOOST_CURRENT_FUNCTION, + __FILE__, __LINE__)

+
+

assertion_failed_msg is declared in <boost/assert.hpp> + as

+
+
namespace boost
+{
+  void assertion_failed_msg(char const * expr, char const * msg, char const * function, char const * file, long line);
+}
+
+
+

but it is never defined. The user is expected to supply an appropriate + definition.

+

As is the case with <cassert>, <boost/assert.hpp> + can be included multiple times in a single translation unit. BOOST_ASSERT_MSG + will be redefined each time as specified above.

+ +

BOOST_VERIFY

<boost/assert.hpp> also defines the macro BOOST_VERIFY. It has exactly the same behavior as BOOST_ASSERT, except that the expression that is passed to BOOST_VERIFY is always @@ -54,8 +107,9 @@ void assertion_failed(char const * expr, char const * function, char const * fil effects; it can also help suppress warnings about unused variables when the only use of the variable is inside an assertion.


- Copyright © 2002, 2007 by Peter Dimov. Distributed under the Boost Software + Copyright © 2002, 2007 by Peter Dimov.  Copyright © 2011 + by Beman Dawes. Distributed under the Boost Software License, Version 1.0. See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.

- + \ No newline at end of file diff --git a/assert_test.cpp b/assert_test.cpp index 693adc4..26051ac 100644 --- a/assert_test.cpp +++ b/assert_test.cpp @@ -2,6 +2,7 @@ // assert_test.cpp - a test for boost/assert.hpp // // Copyright (c) 2002 Peter Dimov and Multi Media Ltd. +// Copyright (2) Beman Dawes 2011 // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at @@ -20,6 +21,11 @@ void test_default() BOOST_ASSERT(x); BOOST_ASSERT(x == 1); BOOST_ASSERT(&x); + + BOOST_ASSERT_MSG(1, "msg"); + BOOST_ASSERT_MSG(x, "msg"); + BOOST_ASSERT_MSG(x == 1, "msg"); + BOOST_ASSERT_MSG(&x, "msg"); } #define BOOST_DISABLE_ASSERTS @@ -34,13 +40,23 @@ void test_disabled() BOOST_ASSERT(x == 1); BOOST_ASSERT(&x); + BOOST_ASSERT_MSG(1, "msg"); + BOOST_ASSERT_MSG(x, "msg"); + BOOST_ASSERT_MSG(x == 1, "msg"); + BOOST_ASSERT_MSG(&x, "msg"); + BOOST_ASSERT(0); BOOST_ASSERT(!x); BOOST_ASSERT(x == 0); + BOOST_ASSERT_MSG(0, "msg"); + BOOST_ASSERT_MSG(!x, "msg"); + BOOST_ASSERT_MSG(x == 0, "msg"); + void * p = 0; BOOST_ASSERT(p); + BOOST_ASSERT_MSG(p, "msg"); // supress warnings p = &x; @@ -55,6 +71,7 @@ void test_disabled() #include int handler_invoked = 0; +int msg_handler_invoked = 0; void boost::assertion_failed(char const * expr, char const * function, char const * file, long line) { @@ -66,11 +83,24 @@ void boost::assertion_failed(char const * expr, char const * function, char cons ++handler_invoked; } +void boost::assertion_failed_msg(char const * expr, char const * msg, char const * function, + char const * file, long line) +{ +#if !defined(BOOST_NO_STDC_NAMESPACE) + using std::printf; +#endif + + printf("Expression: %s Message: %s\nFunction: %s\nFile: %s\nLine: %ld\n\n", + expr, msg, function, file, line); + ++msg_handler_invoked; +} + struct X { static void f() { BOOST_ASSERT(0); + BOOST_ASSERT_MSG(0, "msg f()"); } }; @@ -83,21 +113,35 @@ void test_handler() BOOST_ASSERT(x == 1); BOOST_ASSERT(&x); + BOOST_ASSERT_MSG(1, "msg2"); + BOOST_ASSERT_MSG(x, "msg3"); + BOOST_ASSERT_MSG(x == 1, "msg4"); + BOOST_ASSERT_MSG(&x, "msg5"); + BOOST_ASSERT(0); BOOST_ASSERT(!x); BOOST_ASSERT(x == 0); + BOOST_ASSERT_MSG(0,"msg 0"); + BOOST_ASSERT_MSG(!x, "msg !x"); + BOOST_ASSERT_MSG(x == 0, "msg x == 0"); + void * p = 0; BOOST_ASSERT(p); + BOOST_ASSERT_MSG(p, "msg p"); X::f(); BOOST_ASSERT(handler_invoked == 5); BOOST_TEST(handler_invoked == 5); + + BOOST_ASSERT_MSG(msg_handler_invoked == 5, "msg_handler_invoked count is wrong"); + BOOST_TEST(msg_handler_invoked == 5); } #undef BOOST_ENABLE_ASSERT_HANDLER +#undef BOOST_ENABLE_ASSERT_MSG_HANDLER int main() { From fc30c6231184e75c74b23b357bec7b4936aeebc9 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Tue, 15 Feb 2011 16:18:51 +0000 Subject: [PATCH 27/30] Repair failed merge [SVN r68914] --- include/boost/assert.hpp | 89 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 4 deletions(-) diff --git a/include/boost/assert.hpp b/include/boost/assert.hpp index c227f17..174f084 100644 --- a/include/boost/assert.hpp +++ b/include/boost/assert.hpp @@ -1,8 +1,11 @@ // // boost/assert.hpp - BOOST_ASSERT(expr) +// BOOST_ASSERT_MSG(expr, msg) +// BOOST_VERIFY(expr) // // Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd. // Copyright (c) 2007 Peter Dimov +// Copyright (c) Beman Dawes 2011 // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at @@ -13,6 +16,16 @@ // See http://www.boost.org/libs/utility/assert.html for documentation. // +// +// Stop inspect complaining about use of 'assert': +// +// boostinspect:naassert_macro +// + +//--------------------------------------------------------------------------------------// +// BOOST_ASSERT // +//--------------------------------------------------------------------------------------// + #undef BOOST_ASSERT #if defined(BOOST_DISABLE_ASSERTS) @@ -25,18 +38,86 @@ namespace boost { - -void assertion_failed(char const * expr, char const * function, char const * file, long line); // user defined - + void assertion_failed(char const * expr, + char const * function, char const * file, long line); // user defined } // namespace boost -#define BOOST_ASSERT(expr) ((expr)? ((void)0): ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) +#define BOOST_ASSERT(expr) ((expr) \ + ? ((void)0) \ + : ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) #else # include // .h to support old libraries w/o - effect is the same # define BOOST_ASSERT(expr) assert(expr) #endif +//--------------------------------------------------------------------------------------// +// BOOST_ASSERT_MSG // +//--------------------------------------------------------------------------------------// + +# undef BOOST_ASSERT_MSG + +#if defined(BOOST_DISABLE_ASSERTS) || defined(NDEBUG) + + #define BOOST_ASSERT_MSG(expr, msg) ((void)0) + +#elif defined(BOOST_ENABLE_ASSERT_HANDLER) + + #include + + namespace boost + { + void assertion_failed_msg(char const * expr, char const * msg, + char const * function, char const * file, long line); // user defined + } // namespace boost + + #define BOOST_ASSERT_MSG(expr, msg) ((expr) \ + ? ((void)0) \ + : ::boost::assertion_failed_msg(#expr, msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) + +#else + #ifndef BOOST_ASSERT_HPP + #define BOOST_ASSERT_HPP + #include + #include + #include + + // IDE's like Visual Studio perform better if output goes to std::cout or + // some other stream, so allow user to configure output stream: + #ifndef BOOST_ASSERT_MSG_OSTREAM + # define BOOST_ASSERT_MSG_OSTREAM std::cerr + #endif + + namespace boost + { + namespace assertion + { + namespace detail + { + inline void assertion_failed_msg(char const * expr, char const * msg, char const * function, + char const * file, long line) + { + BOOST_ASSERT_MSG_OSTREAM + << "***** Internal Program Error - assertion (" << expr << ") failed in " + << function << ":\n" + << file << '(' << line << "): " << msg << std::endl; + std::abort(); + } + } // detail + } // assertion + } // detail + #endif + + #define BOOST_ASSERT_MSG(expr, msg) ((expr) \ + ? ((void)0) \ + : ::boost::assertion::detail::assertion_failed_msg(#expr, msg, \ + BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) +#endif + +//--------------------------------------------------------------------------------------// +// BOOST_VERIFY // +//--------------------------------------------------------------------------------------// + #undef BOOST_VERIFY #if defined(BOOST_DISABLE_ASSERTS) || ( !defined(BOOST_ENABLE_ASSERT_HANDLER) && defined(NDEBUG) ) From 288d78668849ae0ca794815ea633cfce9a510519 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Mon, 10 Oct 2011 11:50:55 +0000 Subject: [PATCH 28/30] Merge Boost.Config changes from Trunk - numerous small bug fixes plus a new Cray C++ config. Fixes #5607. Fixes #5941. Fixes #5878. [SVN r74889] --- include/boost/current_function.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/boost/current_function.hpp b/include/boost/current_function.hpp index aa5756e..cb36e35 100644 --- a/include/boost/current_function.hpp +++ b/include/boost/current_function.hpp @@ -28,7 +28,7 @@ namespace detail inline void current_function_helper() { -#if defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) || (defined(__ICC) && (__ICC >= 600)) +#if defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) || (defined(__ICC) && (__ICC >= 600)) || defined(__ghs__) # define BOOST_CURRENT_FUNCTION __PRETTY_FUNCTION__ @@ -65,3 +65,4 @@ inline void current_function_helper() } // namespace boost #endif // #ifndef BOOST_CURRENT_FUNCTION_HPP_INCLUDED + From 81d0e84cc2b373fa4917b216af750fc3a344fdd7 Mon Sep 17 00:00:00 2001 From: "Vicente J. Botet Escriba" Date: Thu, 14 Mar 2013 17:35:42 +0000 Subject: [PATCH 29/30] Utility: merge [68982] to fix #5213. [SVN r83427] --- include/boost/assert.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/boost/assert.hpp b/include/boost/assert.hpp index 174f084..a233505 100644 --- a/include/boost/assert.hpp +++ b/include/boost/assert.hpp @@ -101,7 +101,12 @@ namespace boost << "***** Internal Program Error - assertion (" << expr << ") failed in " << function << ":\n" << file << '(' << line << "): " << msg << std::endl; - std::abort(); + #ifdef UNDER_CE + // The Windows CE CRT library does not have abort() so use exit(-1) instead. + std::exit(-1); + #else + std::abort(); + #endif } } // detail } // assertion From 2ba543cd72bc9072b856ca2576a8f1fb11d71f06 Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Sat, 20 Jul 2013 17:17:10 +0000 Subject: [PATCH 30/30] Merged recent changes from trunk. [SVN r85088] --- include/boost/assert.hpp | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/include/boost/assert.hpp b/include/boost/assert.hpp index a233505..ccc776a 100644 --- a/include/boost/assert.hpp +++ b/include/boost/assert.hpp @@ -34,6 +34,7 @@ #elif defined(BOOST_ENABLE_ASSERT_HANDLER) +#include #include namespace boost @@ -42,7 +43,7 @@ namespace boost char const * function, char const * file, long line); // user defined } // namespace boost -#define BOOST_ASSERT(expr) ((expr) \ +#define BOOST_ASSERT(expr) (BOOST_LIKELY(!!(expr)) \ ? ((void)0) \ : ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) @@ -63,6 +64,7 @@ namespace boost #elif defined(BOOST_ENABLE_ASSERT_HANDLER) + #include #include namespace boost @@ -71,7 +73,7 @@ namespace boost char const * function, char const * file, long line); // user defined } // namespace boost - #define BOOST_ASSERT_MSG(expr, msg) ((expr) \ + #define BOOST_ASSERT_MSG(expr, msg) (BOOST_LIKELY(!!(expr)) \ ? ((void)0) \ : ::boost::assertion_failed_msg(#expr, msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) @@ -80,6 +82,7 @@ namespace boost #define BOOST_ASSERT_HPP #include #include + #include #include // IDE's like Visual Studio perform better if output goes to std::cout or @@ -89,31 +92,33 @@ namespace boost #endif namespace boost - { - namespace assertion - { + { + namespace assertion + { namespace detail { - inline void assertion_failed_msg(char const * expr, char const * msg, char const * function, + // Note: The template is needed to make the function non-inline and avoid linking errors + template< typename CharT > + BOOST_NOINLINE void assertion_failed_msg(CharT const * expr, char const * msg, char const * function, char const * file, long line) { BOOST_ASSERT_MSG_OSTREAM << "***** Internal Program Error - assertion (" << expr << ") failed in " << function << ":\n" << file << '(' << line << "): " << msg << std::endl; - #ifdef UNDER_CE - // The Windows CE CRT library does not have abort() so use exit(-1) instead. - std::exit(-1); - #else - std::abort(); - #endif +#ifdef UNDER_CE + // The Windows CE CRT library does not have abort() so use exit(-1) instead. + std::exit(-1); +#else + std::abort(); +#endif } } // detail } // assertion } // detail #endif - #define BOOST_ASSERT_MSG(expr, msg) ((expr) \ + #define BOOST_ASSERT_MSG(expr, msg) (BOOST_LIKELY(!!(expr)) \ ? ((void)0) \ : ::boost::assertion::detail::assertion_failed_msg(#expr, msg, \ BOOST_CURRENT_FUNCTION, __FILE__, __LINE__))