https://git.reactos.org/?p=reactos.git;a=commitdiff;h=66f6abfc4ad866aa56bcb…
commit 66f6abfc4ad866aa56bcb1fe057ce18d13cc51e9
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Sun Apr 25 13:38:22 2021 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Sun Apr 25 13:38:22 2021 +0900
[SDK][INCLUDE] Fix offsetof and CCSIZEOF_STRUCT for Clang-CL build (#3624)
Clang-CL was failing with "error: function declaration cannot have variably
modified type". This PR will fix the Clang-CL build. CORE-17547
---
sdk/include/crt/stddef.h | 18 +++++++++++++++---
sdk/include/psdk/commctrl.h | 4 ++++
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/sdk/include/crt/stddef.h b/sdk/include/crt/stddef.h
index 97a519ea88e..b5210fb9e92 100644
--- a/sdk/include/crt/stddef.h
+++ b/sdk/include/crt/stddef.h
@@ -377,10 +377,22 @@ typedef __WCHAR_TYPE__ wchar_t;
#ifndef offsetof
/* Offset of member MEMBER in a struct of type TYPE. */
-#if defined(__GNUC__)
-#define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
+#if defined(__GNUC__) || defined(__clang__) || defined(_CRT_USE_BUILTIN_OFFSETOF)
+# define offsetof(TYPE,MEMBER) __builtin_offsetof(TYPE,MEMBER)
#else
-#define offsetof(TYPE, MEMBER) ((size_t)&(((TYPE *)0)->MEMBER))
+# ifdef __cplusplus
+# ifdef _WIN64
+# define offsetof(TYPE,MEMBER) ((::size_t)(ptrdiff_t)&reinterpret_cast<const
volatile char&>((((TYPE*)0)->MEMBER)))
+# else
+# define offsetof(TYPE,MEMBER) ((::size_t)&reinterpret_cast<const volatile
char&>((((TYPE*)0)->MEMBER)))
+# endif
+# else
+# ifdef _WIN64
+# define offsetof(TYPE,MEMBER) ((size_t)(ptrdiff_t)&(((TYPE*)0)->MEMBER))
+# else
+# define offsetof(TYPE,MEMBER) ((size_t)&(((TYPE*)0)->MEMBER))
+# endif
+# endif
#endif
#endif /* !offsetof */
diff --git a/sdk/include/psdk/commctrl.h b/sdk/include/psdk/commctrl.h
index 942d07c0883..845fd3061cb 100644
--- a/sdk/include/psdk/commctrl.h
+++ b/sdk/include/psdk/commctrl.h
@@ -147,7 +147,11 @@ extern "C" {
#define NM_THEMECHANGED (NM_FIRST-22)
#ifndef CCSIZEOF_STRUCT
+#if defined(__clang__) /* Clang-CL fails without this workaround. See CORE-17547 */
+#define CCSIZEOF_STRUCT(structname,member) (__builtin_offsetof(structname,member) +
sizeof(((structname*)0)->member))
+#else
#define CCSIZEOF_STRUCT(structname,member)
(((int)((LPBYTE)(&((structname*)0)->member) -
((LPBYTE)((structname*)0))))+sizeof(((structname*)0)->member))
+#endif
#endif
typedef struct tagNMTOOLTIPSCREATED {