Skip to content

Commit 8a3386a

Browse files
kazutakahiratagithub-actions[bot]
authored andcommitted
Automerge: [ADT] Simplify ResolveUnderlyingType (NFC) (#164114)
We have three implementations of ResolveUnderlyingType: - enum - bool - neither This patch combines the latter two with std::conditional_t. Without this patch, we use "void" to trigger a compilation failure downstream when sizeof(bool) != 1, which is not very friendly. This patch instead uses static_assert to catch the case where the user chooses to use bool but sizeof(bool) != 1.
2 parents e8964cf + 5a20b72 commit 8a3386a

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

llvm/include/llvm/ADT/Bitfields.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,9 @@ struct ResolveUnderlyingType {
154154
using type = std::underlying_type_t<T>;
155155
};
156156
template <typename T> struct ResolveUnderlyingType<T, false> {
157-
using type = T;
158-
};
159-
template <> struct ResolveUnderlyingType<bool, false> {
160-
/// In case sizeof(bool) != 1, replace `void` by an additionnal
161-
/// std::conditional.
162-
using type = std::conditional_t<sizeof(bool) == 1, uint8_t, void>;
157+
static_assert(!std::is_same_v<T, bool> || sizeof(bool) == 1,
158+
"T being bool requires sizeof(bool) == 1.");
159+
using type = std::conditional_t<std::is_same_v<T, bool>, uint8_t, T>;
163160
};
164161

165162
} // namespace bitfields_details

0 commit comments

Comments
 (0)