From 5875f89361938c51cc1943901007aa362e828fae Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Sun, 3 Feb 2019 08:46:33 +0100 Subject: [PATCH] Update static_assert usage to c_static_assert_msg --- src/corefx/System.Globalization.Native/pal_collation.c | 13 +++++-------- src/corefx/System.Globalization.Native/pal_compiler.h | 6 +++--- src/corefx/System.Globalization.Native/pal_icushim.c | 8 ++++---- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/corefx/System.Globalization.Native/pal_collation.c b/src/corefx/System.Globalization.Native/pal_collation.c index 3541802..74f7bb3 100644 --- a/src/corefx/System.Globalization.Native/pal_collation.c +++ b/src/corefx/System.Globalization.Native/pal_collation.c @@ -13,6 +13,11 @@ #include "pal_collation.h" +c_static_assert_msg(UCOL_EQUAL == 0, "managed side requires 0 for equal strings"); +c_static_assert_msg(UCOL_LESS < 0, "managed side requires less than zero for a < b"); +c_static_assert_msg(UCOL_GREATER > 0, "managed side requires greater than zero for a > b"); +c_static_assert_msg(USEARCH_DONE == -1, "managed side requires -1 for not found"); + const int32_t CompareOptionsIgnoreCase = 0x1; const int32_t CompareOptionsIgnoreNonSpace = 0x2; const int32_t CompareOptionsIgnoreSymbols = 0x4; @@ -475,10 +480,6 @@ CompareString int32_t GlobalizationNative_CompareString( SortHandle* pSortHandle, const UChar* lpStr1, int32_t cwStr1Length, const UChar* lpStr2, int32_t cwStr2Length, int32_t options) { - static_assert(UCOL_EQUAL == 0, "managed side requires 0 for equal strings"); - static_assert(UCOL_LESS < 0, "managed side requires less than zero for a < b"); - static_assert(UCOL_GREATER > 0, "managed side requires greater than zero for a > b"); - UCollationResult result = UCOL_EQUAL; UErrorCode err = U_ZERO_ERROR; const UCollator* pColl = GetCollatorFromSortHandle(pSortHandle, options, &err); @@ -504,8 +505,6 @@ int32_t GlobalizationNative_IndexOf( int32_t options, int32_t* pMatchedLength) { - static_assert(USEARCH_DONE == -1, "managed side requires -1 for not found"); - int32_t result = USEARCH_DONE; UErrorCode err = U_ZERO_ERROR; const UCollator* pColl = GetCollatorFromSortHandle(pSortHandle, options, &err); @@ -543,8 +542,6 @@ int32_t GlobalizationNative_LastIndexOf( int32_t cwSourceLength, int32_t options) { - static_assert(USEARCH_DONE == -1, "managed side requires -1 for not found"); - int32_t result = USEARCH_DONE; UErrorCode err = U_ZERO_ERROR; const UCollator* pColl = GetCollatorFromSortHandle(pSortHandle, options, &err); diff --git a/src/corefx/System.Globalization.Native/pal_compiler.h b/src/corefx/System.Globalization.Native/pal_compiler.h index b87de64..01ba72a 100644 --- a/src/corefx/System.Globalization.Native/pal_compiler.h +++ b/src/corefx/System.Globalization.Native/pal_compiler.h @@ -9,11 +9,11 @@ #endif #ifdef static_assert -#define c_static_assert(e) static_assert((e),"") +#define c_static_assert_msg(e, msg) static_assert((e), msg) #elif __has_extension(c_static_assert) -#define c_static_assert(e) _Static_assert((e), "") +#define c_static_assert_msg(e, msg) _Static_assert((e), msg) #else -#define c_static_assert(e) typedef char __c_static_assert__[(e)?1:-1] +#define c_static_assert_msg(e, msg) typedef char __c_static_assert__[(e)?1:-1] #endif #define DLLEXPORT __attribute__ ((__visibility__ ("default"))) diff --git a/src/corefx/System.Globalization.Native/pal_icushim.c b/src/corefx/System.Globalization.Native/pal_icushim.c index 4c540ab..df92dec 100644 --- a/src/corefx/System.Globalization.Native/pal_icushim.c +++ b/src/corefx/System.Globalization.Native/pal_icushim.c @@ -31,7 +31,7 @@ static void* libicui18n = NULL; bool FindICULibs(const char* versionPrefix, char* symbolName, char* symbolVersion) { #ifndef OSX_ICU_LIBRARY_PATH - static_assert(false, "The ICU Library path is not defined"); + c_static_assert_msg(false, "The ICU Library path is not defined"); #endif // OSX_ICU_LIBRARY_PATH // Usually OSX_ICU_LIBRARY_PATH is "/usr/lib/libicucore.dylib" @@ -119,10 +119,10 @@ bool OpenICULibraries(int majorVer, int minorVer, int subVer, const char* versio char libicuucName[64]; char libicui18nName[64]; - static_assert(sizeof("libicuuc.so") + MaxICUVersionStringLength <= sizeof(libicuucName), "The libicuucName is too small"); + c_static_assert_msg(sizeof("libicuuc.so") + MaxICUVersionStringLength <= sizeof(libicuucName), "The libicuucName is too small"); GetVersionedLibFileName("libicuuc.so", majorVer, minorVer, subVer, versionPrefix, libicuucName); - static_assert(sizeof("libicui18n.so") + MaxICUVersionStringLength <= sizeof(libicui18nName), "The libicui18nName is too small"); + c_static_assert_msg(sizeof("libicui18n.so") + MaxICUVersionStringLength <= sizeof(libicui18nName), "The libicui18nName is too small"); GetVersionedLibFileName("libicui18n.so", majorVer, minorVer, subVer, versionPrefix, libicui18nName); libicuuc = dlopen(libicuucName, RTLD_LAZY); @@ -263,7 +263,7 @@ int32_t GlobalizationNative_LoadICU() // Get pointers to all the ICU functions that are needed #define PER_FUNCTION_BLOCK(fn, lib) \ - static_assert((sizeof(#fn) + MaxICUVersionStringLength + 1) <= sizeof(symbolName), "The symbolName is too small for symbol " #fn); \ + c_static_assert_msg((sizeof(#fn) + MaxICUVersionStringLength + 1) <= sizeof(symbolName), "The symbolName is too small for symbol " #fn); \ sprintf(symbolName, #fn "%s", symbolVersion); \ fn##_ptr = (__typeof(fn)*)dlsym(lib, symbolName); \ if (fn##_ptr == NULL) { fprintf(stderr, "Cannot get symbol %s from " #lib "\nError: %s\n", symbolName, dlerror()); abort(); } -- 2.7.4