Changeset 85086 in vbox for trunk/include
- Timestamp:
- Jul 7, 2020 5:01:10 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/cdefs.h
r85069 r85086 154 154 != 1 155 155 # 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) 156 167 #endif 157 168 … … 1072 1083 #endif 1073 1084 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 * 1075 1135 * How to express that a function doesn't throw C++ exceptions and the compiler 1076 1136 * can thus save itself the bother of trying to catch any of them and generate … … 1078 1138 * function prototypes (and implementation if C++). 1079 1139 * 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. 1081 1141 * 1082 1142 * @remarks The use of the nothrow attribute with GCC is because old compilers 1083 1143 * (4.1.1, 32-bit) leaking the nothrow into global space or something 1084 * when used with RTDECL or similar. Using this forces us eto have two1144 * when used with RTDECL or similar. Using this forces us to have two 1085 1145 * macros, as the nothrow attribute is not for the function definition. 1086 1146 */ 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 1089 1151 * definition. 1090 1152 */ … … 1093 1155 || RT_CLANG_HAS_FEATURE(cxx_noexcept) \ 1094 1156 || (RT_GNUC_PREREQ(7, 0) && __cplusplus >= 201100) 1095 # define RT_NO _THROW_PROTOnoexcept1096 # define RT_NO _THROW_DEFnoexcept1157 # define RT_NOTHROW_PROTO noexcept 1158 # define RT_NOTHROW_DEF noexcept 1097 1159 # elif defined(__GNUC__) 1098 1160 # if RT_GNUC_PREREQ(3, 3) 1099 # define RT_NO _THROW_PROTO__attribute__((__nothrow__))1161 # define RT_NOTHROW_PROTO __attribute__((__nothrow__)) 1100 1162 # else 1101 # define RT_NO _THROW_PROTO1163 # define RT_NOTHROW_PROTO 1102 1164 # 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. */ 1104 1166 # 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 1112 1180 1113 1181 /** @def RT_THROW … … 1160 1228 /** @def RT_NOEXCEPT 1161 1229 * Wrapper for the C++11 noexcept keyword (only true form). 1230 * @note use RT_NOTHROW instead. 1162 1231 */ 1163 1232 /** @def RT_NOEXCEPT_EX … … 1165 1234 */ 1166 1235 #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) 1168 1239 # define RT_NOEXCEPT noexcept 1169 1240 # define RT_NOEXCEPT_EX(expr) noexcept(expr) 1170 # elif RT_GNUC_PREREQ(7, 0)1171 # if __cplusplus >= 2011001172 # define RT_NOEXCEPT noexcept1173 # define RT_NOEXCEPT_EX(expr) noexcept(expr)1174 # else1175 # define RT_NOEXCEPT1176 # define RT_NOEXCEPT_EX(expr)1177 # endif1178 1241 # else 1179 1242 # define RT_NOEXCEPT … … 1189 1252 * Tell the compiler that we're falling through to the next case in a switch. 1190 1253 * @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) 1192 1257 # define RT_FALL_THROUGH() __attribute__((__fallthrough__)) 1193 1258 #else … … 1272 1337 # define DECLEXPORT(type) __declspec(dllexport) type 1273 1338 #elif defined(RT_USE_VISIBILITY_DEFAULT) 1274 # define DECLEXPORT(type) __attribute__((visibility("default"))) type1275 #else 1276 # define DECLEXPORT(type) type1339 # define DECLEXPORT(type) __attribute__((visibility("default"))) type 1340 #else 1341 # define DECLEXPORT(type) type 1277 1342 #endif 1278 1343 … … 1326 1391 * How to declare an internal assembly function. 1327 1392 * @param type The return type of the function declaration. 1393 * @note DECL_NOTHROW is implied. 1328 1394 */ 1329 1395 #ifdef __cplusplus 1330 # define DECLASM(type) extern "C" type RTCALL1331 #else 1332 # define DECLASM(type) type RTCALL1396 # define DECLASM(type) extern "C" DECL_NOTHROW(type RTCALL) 1397 #else 1398 # define DECLASM(type) DECL_NOTHROW(type RTCALL) 1333 1399 #endif 1334 1400 … … 1337 1403 * @param type The return type of the function. 1338 1404 */ 1339 #define DECLASMTYPE(type) type RTCALL1405 #define DECLASMTYPE(type) DECL_NOTHROW(type RTCALL) 1340 1406 1341 1407 /** @def RT_ASM_DECL_PRAGMA_WATCOM … … 1345 1411 * 8086, 80186 or 80286 is selected as the target CPU. */ 1346 1412 #if defined(__WATCOMC__) && ARCH_BITS == 16 && defined(RT_ARCH_X86) 1347 # define RT_ASM_DECL_PRAGMA_WATCOM(type) type1413 # define RT_ASM_DECL_PRAGMA_WATCOM(type) type 1348 1414 # if defined(__SW_0) || defined(__SW_1) || defined(__SW_2) 1349 1415 # define RT_ASM_DECL_PRAGMA_WATCOM_386(type) DECLASM(type) … … 1367 1433 */ 1368 1434 #ifdef _MSC_VER 1369 # define DECL_NO_RETURN(type) __declspec(noreturn) type1435 # define DECL_NO_RETURN(type) __declspec(noreturn) type 1370 1436 #elif defined(__GNUC__) 1371 # define DECL_NO_RETURN(type) __attribute__((noreturn)) type1372 #else 1373 # define DECL_NO_RETURN(type) type1437 # define DECL_NO_RETURN(type) __attribute__((noreturn)) type 1438 #else 1439 # define DECL_NO_RETURN(type) type 1374 1440 #endif 1375 1441 /** @deprecated Use DECL_NO_RETURN instead. */ 1376 #define DECLNORETURN(type) DECL_NO_RETURN(type)1442 #define DECLNORETURN(type) DECL_NO_RETURN(type) 1377 1443 1378 1444 /** @def DECL_RETURNS_TWICE … … 1384 1450 */ 1385 1451 #if RT_GNUC_PREREQ(4, 1) 1386 # define DECL_RETURNS_TWICE(type) __attribute__((returns_twice)) type1452 # define DECL_RETURNS_TWICE(type) __attribute__((returns_twice)) type 1387 1453 # else 1388 1454 # define DECL_RETURNS_TWICE(type) type … … 1398 1464 */ 1399 1465 #if defined(__GNUC__) 1400 # define DECLWEAK(type) type __attribute__((weak))1401 #else 1402 # define DECLWEAK(type) type1466 # define DECLWEAK(type) type __attribute__((weak)) 1467 #else 1468 # define DECLWEAK(type) type 1403 1469 #endif 1404 1470 … … 1407 1473 * @param type The return type of the function declaration. 1408 1474 */ 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 1410 1480 1411 1481 /** @def DECLCALLBACKPTR … … 1413 1483 * @param type The return type of the function declaration. 1414 1484 * @param name The name of the variable member. 1485 * @note DECL_NOTHROW is implied, but not supported by all compilers yet. 1415 1486 */ 1416 1487 #if defined(__IBMC__) || defined(__IBMCPP__) 1417 1488 # define DECLCALLBACKPTR(type, name) type (* RTCALL name) 1418 1489 #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) 1420 1491 #endif 1421 1492 … … 1424 1495 * @param type The return type of the function declaration. 1425 1496 * @param name The name of the struct/union/class member. 1497 * @note DECL_NOTHROW is implied, but not supported by all compilers yet. 1426 1498 */ 1427 1499 #if defined(__IBMC__) || defined(__IBMCPP__) 1428 1500 # define DECLCALLBACKMEMBER(type, name) type (* RTCALL name) 1429 1501 #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) 1431 1503 #endif 1432 1504 … … 1436 1508 * @param name The name of the struct/union/class member. 1437 1509 * @param args The argument list enclosed in parentheses. 1510 * @note DECL_NOTHROW is implied, but not supported by all compilers yet. 1438 1511 */ 1439 1512 #if defined(IN_RING3) || defined(DOXYGEN_RUNNING) … … 1448 1521 * @param name The name of the struct/union/class member. 1449 1522 * @param args The argument list enclosed in parentheses. 1523 * @note DECL_NOTHROW is implied, but not supported by all compilers yet. 1450 1524 */ 1451 1525 #if defined(IN_RC) || defined(DOXYGEN_RUNNING) … … 1465 1539 * @param name The name of the struct/union/class member. 1466 1540 * @param args The argument list enclosed in parentheses. 1541 * @note DECL_NOTHROW is implied, but not supported by all compilers yet. 1467 1542 */ 1468 1543 #if defined(IN_RING0) || defined(DOXYGEN_RUNNING) … … 1473 1548 1474 1549 /** @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. 1476 1551 * @param type The return type of the function declaration. 1477 1552 * @remarks Don't use this macro on C++ methods. 1553 * @sa DECL_INLINE_THROW 1478 1554 */ 1479 1555 #if defined(__GNUC__) && !defined(DOXYGEN_RUNNING) 1480 # define DECLINLINE(type) static __inline__ type1556 # define DECLINLINE(type) DECL_NOTHROW(static __inline__ type) 1481 1557 #elif defined(__cplusplus) || defined(DOXYGEN_RUNNING) 1482 # define DECLINLINE(type) static inline type1558 # define DECLINLINE(type) DECL_NOTHROW(static inline type) 1483 1559 #elif defined(_MSC_VER) 1484 # define DECLINLINE(type) static _inline type1560 # define DECLINLINE(type) DECL_NOTHROW(static _inline type) 1485 1561 #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 1491 1583 1492 1584 /** @def DECL_FORCE_INLINE … … 1538 1630 * @remarks This is only used inside IPRT. Other APIs need to define their own 1539 1631 * XXXX_DECL macros for dealing with import/export/static visibility. 1632 * @note DECL_NOTHROW is implied. 1540 1633 */ 1541 1634 #ifdef IN_RT_R0 1542 1635 # ifdef IN_RT_STATIC 1543 # define RTR0DECL(type) DECLHIDDEN( type) RTCALL1636 # define RTR0DECL(type) DECLHIDDEN(DECL_NOTHROW(type)) RTCALL 1544 1637 # else 1545 # define RTR0DECL(type) DECLEXPORT( type) RTCALL1546 # endif 1547 #else 1548 # define RTR0DECL(type) DECLIMPORT( type) RTCALL1638 # define RTR0DECL(type) DECLEXPORT(DECL_NOTHROW(type)) RTCALL 1639 # endif 1640 #else 1641 # define RTR0DECL(type) DECLIMPORT(DECL_NOTHROW(type)) RTCALL 1549 1642 #endif 1550 1643 … … 1558 1651 * @remarks This is only used inside IPRT. Other APIs need to define their own 1559 1652 * XXXX_DECL macros for dealing with import/export/static visibility. 1653 * @note DECL_NOTHROW is implied. 1560 1654 */ 1561 1655 #ifdef IN_RT_R3 1562 1656 # ifdef IN_RT_STATIC 1563 # define RTR3DECL(type) DECLHIDDEN( type) RTCALL1657 # define RTR3DECL(type) DECLHIDDEN(DECL_NOTHROW(type)) RTCALL 1564 1658 # else 1565 # define RTR3DECL(type) DECLEXPORT( type) RTCALL1566 # endif 1567 #else 1568 # define RTR3DECL(type) DECLIMPORT( type) RTCALL1659 # define RTR3DECL(type) DECLEXPORT(DECL_NOTHROW(type)) RTCALL 1660 # endif 1661 #else 1662 # define RTR3DECL(type) DECLIMPORT(DECL_NOTHROW(type)) RTCALL 1569 1663 #endif 1570 1664 … … 1578 1672 * @remarks This is only used inside IPRT. Other APIs need to define their own 1579 1673 * XXXX_DECL macros for dealing with import/export/static visibility. 1674 * @note DECL_NOTHROW is implied. 1580 1675 */ 1581 1676 #ifdef IN_RT_RC 1582 1677 # ifdef IN_RT_STATIC 1583 # define RTRCDECL(type) DECLHIDDEN( type) RTCALL1678 # define RTRCDECL(type) DECLHIDDEN(DECL_NOTHROW(type)) RTCALL 1584 1679 # else 1585 # define RTRCDECL(type) DECLEXPORT( type) RTCALL1586 # endif 1587 #else 1588 # define RTRCDECL(type) DECLIMPORT( type) RTCALL1680 # define RTRCDECL(type) DECLEXPORT(DECL_NOTHROW(type)) RTCALL 1681 # endif 1682 #else 1683 # define RTRCDECL(type) DECLIMPORT(DECL_NOTHROW(type)) RTCALL 1589 1684 #endif 1590 1685 … … 1595 1690 * @remarks This is only used inside IPRT. Other APIs need to define their own 1596 1691 * XXXX_DECL macros for dealing with import/export/static visibility. 1692 * @note DECL_NOTHROW is implied. 1597 1693 */ 1598 1694 #if defined(IN_RT_R3) || defined(IN_RT_RC) || defined(IN_RT_R0) 1599 1695 # ifdef IN_RT_STATIC 1600 # define RTDECL(type) DECLHIDDEN( type) RTCALL1696 # define RTDECL(type) DECLHIDDEN(DECL_NOTHROW(type)) RTCALL 1601 1697 # else 1602 # define RTDECL(type) DECLEXPORT( type) RTCALL1603 # endif 1604 #else 1605 # define RTDECL(type) DECLIMPORT( type) RTCALL1698 # define RTDECL(type) DECLEXPORT(DECL_NOTHROW(type)) RTCALL 1699 # endif 1700 #else 1701 # define RTDECL(type) DECLIMPORT(DECL_NOTHROW(type)) RTCALL 1606 1702 #endif 1607 1703
Note:
See TracChangeset
for help on using the changeset viewer.