From e112f896a215e79ea249a715f128c73c1da04e7a Mon Sep 17 00:00:00 2001 From: Fredrik Roubert Date: Thu, 30 Nov 2023 20:07:03 +0100 Subject: [PATCH] ICU-22576 Use standard alignof() with modern C. --- .ci-builds/.azure-pipelines.yml | 6 +++--- icu4c/source/test/cintltst/ccapitst.c | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.ci-builds/.azure-pipelines.yml b/.ci-builds/.azure-pipelines.yml index c0599ad9f5ec..bb4b5fc8b7cf 100644 --- a/.ci-builds/.azure-pipelines.yml +++ b/.ci-builds/.azure-pipelines.yml @@ -164,7 +164,7 @@ jobs: displayName: 'Build only (WarningsAsErrors)' env: CC: clang-16 - CPPFLAGS: '-Werror -Wno-strict-prototypes -Wno-gnu-offsetof-extensions -Wall -Wextra -Wextra-semi -Wundef -Wnon-virtual-dtor -Wsuggest-override' + CPPFLAGS: '-Werror -Wno-strict-prototypes -Wall -Wextra -Wextra-semi -Wundef -Wnon-virtual-dtor -Wsuggest-override' CXX: clang++-16 #------------------------------------------------------------------------- - job: ICU4C_Clang16_Cpp20_Ubuntu_2004 @@ -188,7 +188,7 @@ jobs: displayName: 'Build and Test' env: CC: clang-16 - CPPFLAGS: '-Werror -Wno-strict-prototypes -Wno-gnu-offsetof-extensions' + CPPFLAGS: '-Werror -Wno-strict-prototypes' CXX: clang++-16 CXXFLAGS: '-std=c++20' #------------------------------------------------------------------------- @@ -213,7 +213,7 @@ jobs: displayName: 'Build and Test' env: CC: clang-16 - CPPFLAGS: '-Werror -Wno-strict-prototypes -Wno-gnu-offsetof-extensions' + CPPFLAGS: '-Werror -Wno-strict-prototypes' CXX: clang++-16 CXXFLAGS: '-std=c++20 -stdlib=libc++' #------------------------------------------------------------------------- diff --git a/icu4c/source/test/cintltst/ccapitst.c b/icu4c/source/test/cintltst/ccapitst.c index 376388bf4f2c..48ad77c92f2b 100644 --- a/icu4c/source/test/cintltst/ccapitst.c +++ b/icu4c/source/test/cintltst/ccapitst.c @@ -37,8 +37,11 @@ #define MAX_FILE_LEN 1024*20 #define UCS_FILE_NAME_SIZE 512 -/* Similar to C++ alignof(type) */ -#define ALIGNOF(type) offsetof (struct { char c; type member; }, member) +#if __STDC_VERSION__ < 201112 +# define alignof(type) offsetof (struct { char c; type member; }, member) +#elif __STDC_VERSION__ < 202311 +# include +#endif /*returns an action other than the one provided*/ #if !UCONFIG_NO_LEGACY_CONVERSION @@ -1837,7 +1840,7 @@ static void TestConvertSafeClone() /* close the original immediately to make sure that the clone works by itself */ ucnv_close(cnv); - if( actualSizes[idx] <= (bufferSizes[j] - (int32_t)ALIGNOF(UConverter)) && + if( actualSizes[idx] <= (bufferSizes[j] - (int32_t)alignof(UConverter)) && err == U_SAFECLONE_ALLOCATED_WARNING ) { log_err("ucnv_safeClone(%s) did a heap clone although the buffer was large enough\n", names[idx]);