Skip to content

Commit

Permalink
Avoid lambda to work around clang assertion failure
Browse files Browse the repository at this point in the history
Using a lambda in a requires clause can cause clang to assert, so
move to a named function instead.

Clang bug: llvm/llvm-project#64086
  • Loading branch information
danakj committed Aug 4, 2023
1 parent c016f17 commit 8f9ff3c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions sus/num/integer_concepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,28 @@ template <class T>
concept PrimitiveInteger =
UnsignedPrimitiveInteger<T> || SignedPrimitiveInteger<T>;

namespace __private {
// Workaround for https://github.com/llvm/llvm-project/issues/64086 which
// prevents us from doing this as a lambda inside the requires clause.
template <class T>
void implicit_conversion(T) {}
} // namespace __private

/// Enum types that are backed by an unsigned value, excluding `enum class`
/// types.
template <class T>
concept UnsignedPrimitiveEnum =
std::is_enum_v<T> && UnsignedPrimitiveInteger<std::underlying_type_t<T>> &&
requires(T t) {
{
[](std::underlying_type_t<T>) {}(t)
};
{ __private::implicit_conversion<std::underlying_type_t<T>>(t) };
};

/// Enum types that are backed by a signed value, excluding `enum class` types.
template <class T>
concept SignedPrimitiveEnum =
std::is_enum_v<T> && SignedPrimitiveInteger<std::underlying_type_t<T>> &&
requires(T t) {
{
[](std::underlying_type_t<T>) {}(t)
};
{ __private::implicit_conversion<std::underlying_type_t<T>>(t) };
};

/// Enum types that are backed by a signed or unsigned value, excluding `enum
Expand Down

0 comments on commit 8f9ff3c

Please sign in to comment.