]> granicus.if.org Git - icu/commitdiff
ICU-20135 Use __has_declspec_attribute (#113)
authorDon <don.j.olmstead@gmail.com>
Tue, 18 Sep 2018 16:17:05 +0000 (09:17 -0700)
committerShane Carr <shane@unicode.org>
Thu, 27 Sep 2018 21:27:40 +0000 (14:27 -0700)
> Clang comes with __has_declspec_attribute to detect whether the name of an attribute is implemented as a MS style __declspec.

> This adds __has_declspect_attribute to the list of clang compatibility macros and then uses that check to determine if __declspec(dllimport) and __declspec(dllexport) can be used.

icu4c/source/common/unicode/platform.h

index 4c1603554fb8bfc1e1536039d21f53cf0dee35f1..a3623f5da6a75a51e91baddf677907e9e522e188 100644 (file)
 #ifndef __has_cpp_attribute
 #    define __has_cpp_attribute(x) 0
 #endif
+#ifndef __has_declspec_attribute
+#    define __has_declspec_attribute(x) 0
+#endif
 #ifndef __has_builtin
 #    define __has_builtin(x) 0
 #endif
@@ -783,6 +786,8 @@ namespace std {
     /* Use the predefined value. */
 #elif defined(U_STATIC_IMPLEMENTATION)
 #   define U_EXPORT
+#elif defined(_MSC_VER) || (__has_declspec_attribute(dllexport) && __has_declspec_attribute(dllimport))
+#   define U_EXPORT __declspec(dllexport)
 #elif defined(__GNUC__)
 #   define U_EXPORT __attribute__((visibility("default")))
 #elif (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x550) \
@@ -790,8 +795,6 @@ namespace std {
 #   define U_EXPORT __global
 /*#elif defined(__HP_aCC) || defined(__HP_cc)
 #   define U_EXPORT __declspec(dllexport)*/
-#elif defined(_MSC_VER)
-#   define U_EXPORT __declspec(dllexport)
 #else
 #   define U_EXPORT
 #endif
@@ -807,7 +810,7 @@ namespace std {
 
 #ifdef U_IMPORT
     /* Use the predefined value. */
-#elif defined(_MSC_VER)
+#elif defined(_MSC_VER) || (__has_declspec_attribute(dllexport) && __has_declspec_attribute(dllimport))
     /* Windows needs to export/import data. */
 #   define U_IMPORT __declspec(dllimport)
 #else