1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-19 13:40:49 +03:00

0024191: Static assert functionality should be added to Standard_Assert.hxx

Added Standard_STATIC_ASSERT macro for compile-time asserts.
The new macro is used in Standard_MMgrOpt and QANCollection.
This commit is contained in:
omy
2013-09-19 16:12:48 +04:00
committed by bugmaster
parent 0ebaa4dbc9
commit 8b381bc3a3
3 changed files with 34 additions and 36 deletions

View File

@@ -62,6 +62,13 @@
//!
//! The second argument (message) should be string constant ("...").
//!
//! The Standard_STATIC_ASSERT macro is to be used for compile time checks.
//! To use this macro, write:
//!
//! Standard_STATIC_ASSERT(const_expression);
//!
//! If const_expression is false, a compiler error occurs.
//!
//! The macros are formed as functions and require semicolon at the end.
// Stub function used to make macros complete C++ operator
@@ -155,6 +162,23 @@ inline void Standard_ASSERT_DO_NOTHING() {}
//! Raise debug message
#define Standard_ASSERT_INVOKE(theDesc) Standard_ASSERT_INVOKE_(always, theDesc)
//! Static assert --
//! empty default template
template <bool condition>
struct Standard_Static_Assert { };
//! Static assert -- specialization for condition being true
template <>
struct Standard_Static_Assert<true>
{
static void assert_ok() {}
};
//! Cause compiler error if argument is not constant expression or
//! evaluates to false
#define Standard_STATIC_ASSERT(theExpr) \
Standard_Static_Assert<theExpr>::assert_ok();
#endif // Standard_Assert_HeaderFile
#ifdef _MSC_VER

View File

@@ -20,7 +20,7 @@
#include <Standard_MMgrOpt.hxx>
#include <Standard_OutOfMemory.hxx>
#include <Standard_Assert.hxx>
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
@@ -192,11 +192,7 @@ Standard_MMgrOpt::Standard_MMgrOpt(const Standard_Boolean aClear,
const Standard_Size aThreshold)
{
// check basic assumption
if ( sizeof(Standard_Size) != sizeof(Standard_Address) )
{
cerr << "Fatal error: Open CASCADE Optimized Memory manager: this platform is not supported!" << endl;
exit(1);
}
Standard_STATIC_ASSERT(sizeof(Standard_Size) == sizeof(Standard_Address));
// clear buffer fields
myFreeListMax = 0;