Skip to content

Commit df38079

Browse files
committed
Clang-cl can't use the never-value field optimization
Since offsetof() is not a constant expression on clang-cl, though it is on other compilers. llvm/llvm-project#59689
1 parent e217fcc commit df38079

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

macros/__private/compiler_bugs.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,13 @@
125125
#define sus_clang_bug_49358(...)
126126
#define sus_clang_bug_49358_else(...) __VA_ARGS__
127127
#endif
128+
129+
// TODO: https://github.com/llvm/llvm-project/issues/59689
130+
// offsetof() is not constant evaluable in clang-cl.
131+
#if _MSC_VER && __clang_major__ > 0 // TODO: Update when the bug is fixed.
132+
#define sus_clang_bug_59689(...) __VA_ARGS__
133+
#define sus_clang_bug_59689_else(...)
134+
#else
135+
#define sus_clang_bug_59689(...)
136+
#define sus_clang_bug_59689_else(...) __VA_ARGS__
137+
#endif

mem/never_value.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ concept NeverValueField = never_value_access<T>::has_field;
179179
\
180180
template <class SusUnsafeNeverValueOuter, \
181181
bool SusUnsafeNeverValueStandardLayout = \
182-
std::is_standard_layout_v<SusUnsafeNeverValueOuter>> \
182+
sus_clang_bug_59689(false) sus_clang_bug_59689_else( \
183+
std::is_standard_layout_v<SusUnsafeNeverValueOuter>)> \
183184
struct SusUnsafeNeverValueOverlay; \
184185
\
185186
template <class SusUnsafeNeverValueOuter> \

option/__private/storage.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ struct [[sus_trivial_abi]] StoragePointer<T&> {
211211

212212
// This must be true in order for StoragePointer to be useful with the
213213
// never-value field optimization.
214-
static_assert(::sus::mem::NeverValueField<StoragePointer<int&>>);
214+
// clang-format off
215+
sus_clang_bug_59689_else(
216+
static_assert(::sus::mem::NeverValueField<StoragePointer<int&>>);
217+
)
218+
// clang-format on
215219

216220
} // namespace sus::option::__private

0 commit comments

Comments
 (0)