VirtualBox

Changeset 30253 in vbox for trunk/include


Ignore:
Timestamp:
Jun 16, 2010 2:18:53 PM (15 years ago)
Author:
vboxsync
Message:

iprt/assert.h: Use static_assert with g++ when available. Added AssertCompileNS for working around restrictions C++0x imposes on the expression.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/assert.h

    r30246 r30253  
    275275/** @def RTASSERT_HAVE_STATIC_ASSERT
    276276 * Indicates that the compiler implements static_assert(expr, msg).
    277  * @todo Does any GCC version support static_assert?
    278  * @     Yes, as of gcc-4.3 with 'g++ -std=c++0x' but only in g++, not gcc!
    279277 */
    280278#ifdef _MSC_VER
     
    283281# endif
    284282#endif
     283#if defined(__GNUC__) && defined(__GXX_EXPERIMENTAL_CXX0X__)
     284# define RTASSERT_HAVE_STATIC_ASSERT
     285#endif
    285286#ifdef DOXYGEN_RUNNING
    286287# define RTASSERT_HAVE_STATIC_ASSERT
    287288#endif
    288289
     290/** @def AssertCompileNS
     291 * Asserts that a compile-time expression is true. If it's not break the build.
     292 *
     293 * This differs from AssertCompile in that it accepts some more expressions
     294 * than what C++0x allows - NS = Non-standard.
     295 *
     296 * @param   expr    Expression which should be true.
     297 */
     298#ifdef __GNUC__
     299# define AssertCompileNS(expr)  extern int RTASSERTVAR[1] __attribute__((unused)), RTASSERTVAR[(expr) ? 1 : 0] __attribute__((unused))
     300#else
     301# define AssertCompileNS(expr)  typedef int RTASSERTTYPE[(expr) ? 1 : 0]
     302#endif
     303
    289304/** @def AssertCompile
    290  * Asserts that a compile-time expression is true. If it's not break the build.
     305 * Asserts that a C++0x compile-time expression is true. If it's not break the
     306 * build.
    291307 * @param   expr    Expression which should be true.
    292308 */
    293309#ifdef RTASSERT_HAVE_STATIC_ASSERT
    294310# define AssertCompile(expr)    static_assert(!!(expr), #expr)
    295 #elif defined(__GNUC__)
    296 # define AssertCompile(expr)    extern int RTASSERTVAR[1] __attribute__((unused)), RTASSERTVAR[(expr) ? 1 : 0] __attribute__((unused))
    297 #else
    298 # define AssertCompile(expr)    typedef int RTASSERTTYPE[(expr) ? 1 : 0]
     311#else
     312# define AssertCompile(expr)    AssertCompileNS(expr)
    299313#endif
    300314
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette