| 1 |
// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -verify -fms-compatibility |
| 2 |
// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -verify |
| 3 |
// expected-no-diagnostics |
| 4 |
|
| 5 |
typedef __typeof__(sizeof(0)) size_t; |
| 6 |
|
| 7 |
#ifdef _MSC_VER |
| 8 |
#ifndef _CRT_USE_BUILTIN_OFFSETOF |
| 9 |
#error _CRT_USE_BUILTIN_OFFSETOF should be predefined in MSVC-compatible modes. |
| 10 |
#endif |
| 11 |
#else |
| 12 |
#ifdef _CRT_USE_BUILTIN_OFFSETOF |
| 13 |
#error _CRT_USE_BUILTIN_OFFSETOF should not be predefined in non-MSVC-compatible modes. |
| 14 |
#endif |
| 15 |
#endif |
| 16 |
|
| 17 |
#if defined _MSC_VER && !defined _CRT_USE_BUILTIN_OFFSETOF |
| 18 |
#ifdef __cplusplus |
| 19 |
#define offsetof(s,m) ((::size_t)&reinterpret_cast<char const volatile&>((((s*)0)->m))) |
| 20 |
#else |
| 21 |
#define offsetof(s,m) ((size_t)&(((s*)0)->m)) |
| 22 |
#endif |
| 23 |
#else |
| 24 |
#define offsetof(s,m) __builtin_offsetof(s,m) |
| 25 |
#endif |
| 26 |
|
| 27 |
struct S { int a; }; |
| 28 |
_Static_assert(offsetof(struct S, a) == 0, ""); |