VirtualBox

Changeset 85086 in vbox for trunk/include


Ignore:
Timestamp:
Jul 7, 2020 5:01:10 PM (5 years ago)
Author:
vboxsync
Message:

iprt/cdefs.h: Make RT*DECL, DECLCALLBACK*, and DECLINLINE imply nothrow (either attribute or declspec). Introducing DECL_INLINE_THROW for inline functions throwing stuff. Renamed RT_NO_THROW* to RT_NOTHROW*. ++ bugref:9794

File:
1 edited

Legend:

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

    r85069 r85086  
    154154  != 1
    155155# error "Exactly one RT_ARCH_XXX macro shall be defined"
     156#endif
     157
     158/** @def RT_CPLUSPLUS_PREREQ
     159 * Require a minimum __cplusplus value, simplifying dealing with non-C++ code.
     160 *
     161 * @param   a_Min           The minimum version, e.g. 201100.
     162 */
     163#ifdef __cplusplus
     164# define RT_CPLUSPLUS_PREREQ(a_Min)      (__cplusplus >= (a_Min))
     165#else
     166# define RT_CPLUSPLUS_PREREQ(a_Min)      (0)
    156167#endif
    157168
     
    10721083#endif
    10731084
    1074 /** @def RT_NO_THROW_PROTO
     1085/** @def DECL_NOTHROW
     1086 * How to declare a function which does not throw C++ exceptions.
     1087 *
     1088 * @note This macro can be combined with other macros, for example
     1089 * @code
     1090 *   EMR3DECL(DECL_NOTHROW(void)) foo(void);
     1091 * @endcode
     1092 *
     1093 * @note GCC is currently restricted to 4.2+ given the ominous comments on
     1094 *       RT_NOTHROW_PROTO.
     1095 */
     1096#ifdef __cplusplus
     1097# ifdef _MSC_VER
     1098#  define DECL_NOTHROW(type)        __declspec(nothrow) type
     1099# elif RT_CLANG_PREREQ(6,0) || RT_GNUC_PREREQ(4,2)
     1100#  define DECL_NOTHROW(type)        __attribute__((__nothrow__)) type
     1101# else
     1102#  define DECL_NOTHROW(type)        type
     1103# endif
     1104#else
     1105# define DECL_NOTHROW(type)         type
     1106#endif
     1107
     1108/** @def DECL_NOTHROW_TYPEDEF
     1109 * How to declare a function which does not throw C++ exceptions.
     1110 *
     1111 * This only works with Clang at present, but it does makes a difference there.
     1112 */
     1113#if RT_CLANG_PREREQ(6,0)
     1114# define DECL_NOTHROW_TYPEDEF(type) __attribute__((__nothrow__)) type
     1115#else
     1116# define DECL_NOTHROW_TYPEDEF(type) type
     1117#endif
     1118
     1119/** @def DECL_NOTHROW_PFN
     1120 * How to declare a function which does not throw C++ exceptions.
     1121 *
     1122 * This only works with Clang at present, but it does makes a difference there.
     1123 */
     1124#if RT_CLANG_PREREQ(6,0)
     1125# define DECL_NOTHROW_PFN(type, cconv, name)    __attribute__((__nothrow__)) type (cconv * name)
     1126#elif defined(__IBMC__) || defined(__IBMCPP__)
     1127# define DECL_NOTHROW_PFN(type, cconv, name)    type (* cconv name)
     1128#else
     1129# define DECL_NOTHROW_PFN(type, cconv, name)    type (cconv * name)
     1130#endif
     1131
     1132/** @def RT_NOTHROW_PROTO
     1133 * Function does not throw any C++ exceptions, prototype edition.
     1134 *
    10751135 * How to express that a function doesn't throw C++ exceptions and the compiler
    10761136 * can thus save itself the bother of trying to catch any of them and generate
     
    10781138 * function prototypes (and implementation if C++).
    10791139 *
    1080  * @remarks May not work on C++ methods, mainly intented for C-style APIs.
     1140 * @note    This translates to 'noexcept' when compiling in newer C++ mode.
    10811141 *
    10821142 * @remarks The use of the nothrow attribute with GCC is because old compilers
    10831143 *          (4.1.1, 32-bit) leaking the nothrow into global space or something
    1084  *          when used with RTDECL or similar.  Using this forces use to have two
     1144 *          when used with RTDECL or similar.  Using this forces us to have two
    10851145 *          macros, as the nothrow attribute is not for the function definition.
    10861146 */
    1087 /** @def RT_NO_THROW_DEF
    1088  * The counter part to RT_NO_THROW_PROTO that is added to the function
     1147/** @def RT_NOTHROW_DEF
     1148 * Function does not throw any C++ exceptions, definition edition.
     1149 *
     1150 * The counter part to RT_NOTHROW_PROTO that is added to the function
    10891151 * definition.
    10901152 */
     
    10931155  || RT_CLANG_HAS_FEATURE(cxx_noexcept) \
    10941156  || (RT_GNUC_PREREQ(7, 0) && __cplusplus >= 201100)
    1095 #  define RT_NO_THROW_PROTO     noexcept
    1096 #  define RT_NO_THROW_DEF       noexcept
     1157#  define RT_NOTHROW_PROTO      noexcept
     1158#  define RT_NOTHROW_DEF        noexcept
    10971159# elif defined(__GNUC__)
    10981160#  if RT_GNUC_PREREQ(3, 3)
    1099 #   define RT_NO_THROW_PROTO    __attribute__((__nothrow__))
     1161#   define RT_NOTHROW_PROTO     __attribute__((__nothrow__))
    11001162#  else
    1101 #   define RT_NO_THROW_PROTO
     1163#   define RT_NOTHROW_PROTO
    11021164#  endif
    1103 #  define RT_NO_THROW_DEF       /* Would need a DECL_NO_THROW like __declspec(nothrow), which we wont do at this point. */
     1165#  define RT_NOTHROW_DEF        /* Would need a DECL_NO_THROW like __declspec(nothrow), which we wont do at this point. */
    11041166# else
    1105 #  define RT_NO_THROW_PROTO     throw()
    1106 #  define RT_NO_THROW_DEF       throw()
    1107 # endif
    1108 #else
    1109 # define RT_NO_THROW_PROTO
    1110 # define RT_NO_THROW_DEF
    1111 #endif
     1167#  define RT_NOTHROW_PROTO      throw()
     1168#  define RT_NOTHROW_DEF        throw()
     1169# endif
     1170#else
     1171# define RT_NOTHROW_PROTO
     1172# define RT_NOTHROW_DEF
     1173#endif
     1174/** @def RT_NOTHROW_PROTO
     1175 * @deprecated Use RT_NOTHROW_PROTO. */
     1176#define RT_NO_THROW_PROTO       RT_NOTHROW_PROTO
     1177/** @def RT_NOTHROW_DEF
     1178 * @deprecated Use RT_NOTHROW_DEF. */
     1179#define RT_NO_THROW_DEF         RT_NOTHROW_DEF
    11121180
    11131181/** @def RT_THROW
     
    11601228/** @def RT_NOEXCEPT
    11611229 * Wrapper for the C++11 noexcept keyword (only true form).
     1230 * @note use RT_NOTHROW instead.
    11621231 */
    11631232/** @def RT_NOEXCEPT_EX
     
    11651234 */
    11661235#ifdef __cplusplus
    1167 # if RT_MSC_PREREQ_EX(RT_MSC_VER_VS2015, 0)
     1236# if (RT_MSC_PREREQ_EX(RT_MSC_VER_VS2015, 0) && defined(RT_EXCEPTIONS_ENABLED)) \
     1237  || RT_CLANG_HAS_FEATURE(cxx_noexcept) \
     1238  || (RT_GNUC_PREREQ(7, 0) && __cplusplus >= 201100)
    11681239#  define RT_NOEXCEPT           noexcept
    11691240#  define RT_NOEXCEPT_EX(expr)  noexcept(expr)
    1170 # elif RT_GNUC_PREREQ(7, 0)
    1171 #  if __cplusplus >= 201100
    1172 #   define RT_NOEXCEPT          noexcept
    1173 #   define RT_NOEXCEPT_EX(expr) noexcept(expr)
    1174 #  else
    1175 #   define RT_NOEXCEPT
    1176 #   define RT_NOEXCEPT_EX(expr)
    1177 #  endif
    11781241# else
    11791242#  define RT_NOEXCEPT
     
    11891252 * Tell the compiler that we're falling through to the next case in a switch.
    11901253 * @sa RT_FALL_THRU  */
    1191 #if RT_GNUC_PREREQ(7, 0)
     1254#if RT_CLANG_PREREQ(4, 0) && RT_CPLUSPLUS_PREREQ(201100)
     1255# define RT_FALL_THROUGH()      [[clang::fallthrough]]
     1256#elif RT_GNUC_PREREQ(7, 0)
    11921257# define RT_FALL_THROUGH()      __attribute__((__fallthrough__))
    11931258#else
     
    12721337# define DECLEXPORT(type)       __declspec(dllexport) type
    12731338#elif defined(RT_USE_VISIBILITY_DEFAULT)
    1274 # define DECLEXPORT(type)      __attribute__((visibility("default"))) type
    1275 #else
    1276 # define DECLEXPORT(type)      type
     1339# define DECLEXPORT(type)       __attribute__((visibility("default"))) type
     1340#else
     1341# define DECLEXPORT(type)       type
    12771342#endif
    12781343
     
    13261391 * How to declare an internal assembly function.
    13271392 * @param   type    The return type of the function declaration.
     1393 * @note    DECL_NOTHROW is implied.
    13281394 */
    13291395#ifdef __cplusplus
    1330 # define DECLASM(type)           extern "C" type RTCALL
    1331 #else
    1332 # define DECLASM(type)           type RTCALL
     1396# define DECLASM(type)           extern "C" DECL_NOTHROW(type RTCALL)
     1397#else
     1398# define DECLASM(type)           DECL_NOTHROW(type RTCALL)
    13331399#endif
    13341400
     
    13371403 * @param   type    The return type of the function.
    13381404 */
    1339 #define DECLASMTYPE(type)       type RTCALL
     1405#define DECLASMTYPE(type)       DECL_NOTHROW(type RTCALL)
    13401406
    13411407/** @def RT_ASM_DECL_PRAGMA_WATCOM
     
    13451411 * 8086, 80186 or 80286 is selected as the target CPU. */
    13461412#if defined(__WATCOMC__) && ARCH_BITS == 16 && defined(RT_ARCH_X86)
    1347 # define RT_ASM_DECL_PRAGMA_WATCOM(type) type
     1413# define RT_ASM_DECL_PRAGMA_WATCOM(type)        type
    13481414# if defined(__SW_0) || defined(__SW_1) || defined(__SW_2)
    13491415#  define RT_ASM_DECL_PRAGMA_WATCOM_386(type)   DECLASM(type)
     
    13671433 */
    13681434#ifdef _MSC_VER
    1369 # define DECL_NO_RETURN(type)   __declspec(noreturn) type
     1435# define DECL_NO_RETURN(type)       __declspec(noreturn) type
    13701436#elif defined(__GNUC__)
    1371 # define DECL_NO_RETURN(type)   __attribute__((noreturn)) type
    1372 #else
    1373 # define DECL_NO_RETURN(type)   type
     1437# define DECL_NO_RETURN(type)       __attribute__((noreturn)) type
     1438#else
     1439# define DECL_NO_RETURN(type)       type
    13741440#endif
    13751441/** @deprecated Use DECL_NO_RETURN instead. */
    1376 #define DECLNORETURN(type) DECL_NO_RETURN(type)
     1442#define DECLNORETURN(type)          DECL_NO_RETURN(type)
    13771443
    13781444/** @def DECL_RETURNS_TWICE
     
    13841450 */
    13851451#if RT_GNUC_PREREQ(4, 1)
    1386 # define DECL_RETURNS_TWICE(type)  __attribute__((returns_twice)) type
     1452# define DECL_RETURNS_TWICE(type)   __attribute__((returns_twice)) type
    13871453# else
    13881454# define DECL_RETURNS_TWICE(type)   type
     
    13981464 */
    13991465#if defined(__GNUC__)
    1400 # define DECLWEAK(type)         type __attribute__((weak))
    1401 #else
    1402 # define DECLWEAK(type)         type
     1466# define DECLWEAK(type)             type __attribute__((weak))
     1467#else
     1468# define DECLWEAK(type)             type
    14031469#endif
    14041470
     
    14071473 * @param   type    The return type of the function declaration.
    14081474 */
    1409 #define DECLCALLBACK(type)      type RT_FAR_CODE RTCALL
     1475#ifdef _MSC_VER
     1476# define DECLCALLBACK(type)         type RT_FAR_CODE RTCALL
     1477#else
     1478# define DECLCALLBACK(type)         DECL_NOTHROW_TYPEDEF(type RT_FAR_CODE RTCALL)
     1479#endif
    14101480
    14111481/** @def DECLCALLBACKPTR
     
    14131483 * @param   type    The return type of the function declaration.
    14141484 * @param   name    The name of the variable member.
     1485 * @note    DECL_NOTHROW is implied, but not supported by all compilers yet.
    14151486 */
    14161487#if defined(__IBMC__) || defined(__IBMCPP__)
    14171488# define DECLCALLBACKPTR(type, name)    type (* RTCALL name)
    14181489#else
    1419 # define DECLCALLBACKPTR(type, name)    type (RT_FAR_CODE RTCALL * name)
     1490# define DECLCALLBACKPTR(type, name)    DECL_NOTHROW_PFN(type, RT_FAR_CODE RTCALL, name)
    14201491#endif
    14211492
     
    14241495 * @param   type    The return type of the function declaration.
    14251496 * @param   name    The name of the struct/union/class member.
     1497 * @note    DECL_NOTHROW is implied, but not supported by all compilers yet.
    14261498 */
    14271499#if defined(__IBMC__) || defined(__IBMCPP__)
    14281500# define DECLCALLBACKMEMBER(type, name) type (* RTCALL name)
    14291501#else
    1430 # define DECLCALLBACKMEMBER(type, name) type (RT_FAR_CODE RTCALL * name)
     1502# define DECLCALLBACKMEMBER(type, name) DECL_NOTHROW_PFN(type, RT_FAR_CODE RTCALL, name)
    14311503#endif
    14321504
     
    14361508 * @param   name    The name of the struct/union/class member.
    14371509 * @param   args    The argument list enclosed in parentheses.
     1510 * @note    DECL_NOTHROW is implied, but not supported by all compilers yet.
    14381511 */
    14391512#if defined(IN_RING3) || defined(DOXYGEN_RUNNING)
     
    14481521 * @param   name    The name of the struct/union/class member.
    14491522 * @param   args    The argument list enclosed in parentheses.
     1523 * @note    DECL_NOTHROW is implied, but not supported by all compilers yet.
    14501524 */
    14511525#if defined(IN_RC) || defined(DOXYGEN_RUNNING)
     
    14651539 * @param   name    The name of the struct/union/class member.
    14661540 * @param   args    The argument list enclosed in parentheses.
     1541 * @note    DECL_NOTHROW is implied, but not supported by all compilers yet.
    14671542 */
    14681543#if defined(IN_RING0) || defined(DOXYGEN_RUNNING)
     
    14731548
    14741549/** @def DECLINLINE
    1475  * How to declare a function as inline.
     1550 * How to declare a function as inline that does not throw any C++ exceptions.
    14761551 * @param   type    The return type of the function declaration.
    14771552 * @remarks Don't use this macro on C++ methods.
     1553 * @sa      DECL_INLINE_THROW
    14781554 */
    14791555#if defined(__GNUC__) && !defined(DOXYGEN_RUNNING)
    1480 # define DECLINLINE(type) static __inline__ type
     1556# define DECLINLINE(type)           DECL_NOTHROW(static __inline__ type)
    14811557#elif defined(__cplusplus) || defined(DOXYGEN_RUNNING)
    1482 # define DECLINLINE(type) static inline type
     1558# define DECLINLINE(type)           DECL_NOTHROW(static inline type)
    14831559#elif defined(_MSC_VER)
    1484 # define DECLINLINE(type) static _inline type
     1560# define DECLINLINE(type)           DECL_NOTHROW(static _inline type)
    14851561#elif defined(__IBMC__)
    1486 # define DECLINLINE(type) _Inline type
    1487 #else
    1488 # define DECLINLINE(type) inline type
    1489 #endif
    1490 
     1562# define DECLINLINE(type)           DECL_NOTHROW(_Inline type)
     1563#else
     1564# define DECLINLINE(type)           DECL_NOTHROW(inline type)
     1565#endif
     1566
     1567/** @def DECL_INLINE_THROW
     1568 * How to declare a function as inline that throws C++ exceptions.
     1569 * @param   type    The return type of the function declaration.
     1570 * @remarks Don't use this macro on C++ methods.
     1571 */
     1572#if defined(__GNUC__) && !defined(DOXYGEN_RUNNING)
     1573# define DECL_INLINE_THROW(type)    static __inline__ type
     1574#elif defined(__cplusplus) || defined(DOXYGEN_RUNNING)
     1575# define DECL_INLINE_THROW(type)    static inline type
     1576#elif defined(_MSC_VER)
     1577# define DECL_INLINE_THROW(type)    static _inline type
     1578#elif defined(__IBMC__)
     1579# define DECL_INLINE_THROW(type)    _Inline type
     1580#else
     1581# define DECL_INLINE_THROW(type)    inline type
     1582#endif
    14911583
    14921584/** @def DECL_FORCE_INLINE
     
    15381630 * @remarks This is only used inside IPRT.  Other APIs need to define their own
    15391631 *          XXXX_DECL macros for dealing with import/export/static visibility.
     1632 * @note    DECL_NOTHROW is implied.
    15401633 */
    15411634#ifdef IN_RT_R0
    15421635# ifdef IN_RT_STATIC
    1543 #  define RTR0DECL(type)    DECLHIDDEN(type) RTCALL
     1636#  define RTR0DECL(type)    DECLHIDDEN(DECL_NOTHROW(type)) RTCALL
    15441637# else
    1545 #  define RTR0DECL(type)    DECLEXPORT(type) RTCALL
    1546 # endif
    1547 #else
    1548 # define RTR0DECL(type)     DECLIMPORT(type) RTCALL
     1638#  define RTR0DECL(type)    DECLEXPORT(DECL_NOTHROW(type)) RTCALL
     1639# endif
     1640#else
     1641# define RTR0DECL(type)     DECLIMPORT(DECL_NOTHROW(type)) RTCALL
    15491642#endif
    15501643
     
    15581651 * @remarks This is only used inside IPRT.  Other APIs need to define their own
    15591652 *          XXXX_DECL macros for dealing with import/export/static visibility.
     1653 * @note    DECL_NOTHROW is implied.
    15601654 */
    15611655#ifdef IN_RT_R3
    15621656# ifdef IN_RT_STATIC
    1563 #  define RTR3DECL(type)    DECLHIDDEN(type) RTCALL
     1657#  define RTR3DECL(type)    DECLHIDDEN(DECL_NOTHROW(type)) RTCALL
    15641658# else
    1565 #  define RTR3DECL(type)    DECLEXPORT(type) RTCALL
    1566 # endif
    1567 #else
    1568 # define RTR3DECL(type)     DECLIMPORT(type) RTCALL
     1659#  define RTR3DECL(type)    DECLEXPORT(DECL_NOTHROW(type)) RTCALL
     1660# endif
     1661#else
     1662# define RTR3DECL(type)     DECLIMPORT(DECL_NOTHROW(type)) RTCALL
    15691663#endif
    15701664
     
    15781672 * @remarks This is only used inside IPRT.  Other APIs need to define their own
    15791673 *          XXXX_DECL macros for dealing with import/export/static visibility.
     1674 * @note    DECL_NOTHROW is implied.
    15801675 */
    15811676#ifdef IN_RT_RC
    15821677# ifdef IN_RT_STATIC
    1583 #  define RTRCDECL(type)    DECLHIDDEN(type) RTCALL
     1678#  define RTRCDECL(type)    DECLHIDDEN(DECL_NOTHROW(type)) RTCALL
    15841679# else
    1585 #  define RTRCDECL(type)    DECLEXPORT(type) RTCALL
    1586 # endif
    1587 #else
    1588 # define RTRCDECL(type)     DECLIMPORT(type) RTCALL
     1680#  define RTRCDECL(type)    DECLEXPORT(DECL_NOTHROW(type)) RTCALL
     1681# endif
     1682#else
     1683# define RTRCDECL(type)     DECLIMPORT(DECL_NOTHROW(type)) RTCALL
    15891684#endif
    15901685
     
    15951690 * @remarks This is only used inside IPRT.  Other APIs need to define their own
    15961691 *          XXXX_DECL macros for dealing with import/export/static visibility.
     1692 * @note    DECL_NOTHROW is implied.
    15971693 */
    15981694#if defined(IN_RT_R3) || defined(IN_RT_RC) || defined(IN_RT_R0)
    15991695# ifdef IN_RT_STATIC
    1600 #  define RTDECL(type)      DECLHIDDEN(type) RTCALL
     1696#  define RTDECL(type)      DECLHIDDEN(DECL_NOTHROW(type)) RTCALL
    16011697# else
    1602 #  define RTDECL(type)      DECLEXPORT(type) RTCALL
    1603 # endif
    1604 #else
    1605 # define RTDECL(type)       DECLIMPORT(type) RTCALL
     1698#  define RTDECL(type)      DECLEXPORT(DECL_NOTHROW(type)) RTCALL
     1699# endif
     1700#else
     1701# define RTDECL(type)       DECLIMPORT(DECL_NOTHROW(type)) RTCALL
    16061702#endif
    16071703
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