Fix default case must at last assertion in Switch()

Fix an assertion in SwitchCases that default case must be last in Switch().

Change-Id: I5ece5a20e22f8df607581373d1f0bb0bd44fb58b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/85461
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Zhaoming Jiang <zhaoming.jiang@intel.com>
This commit is contained in:
Zhaoming Jiang 2022-04-01 11:12:36 +00:00 committed by Tint LUCI CQ
parent 79db32aff2
commit 4bc30b7ba2
1 changed files with 3 additions and 2 deletions

View File

@ -641,8 +641,9 @@ inline void SwitchCases(T* object,
std::tuple<CASES...>&& cases) { std::tuple<CASES...>&& cases) {
using Cases = std::tuple<CASES...>; using Cases = std::tuple<CASES...>;
static constexpr int kDefaultIndex = detail::IndexOfDefaultCase<Cases>(); static constexpr int kDefaultIndex = detail::IndexOfDefaultCase<Cases>();
static_assert(kDefaultIndex == -1 || std::tuple_size_v<Cases> - 1, static_assert(
"Default case must be last in Switch()"); kDefaultIndex == -1 || kDefaultIndex == std::tuple_size_v<Cases> - 1,
"Default case must be last in Switch()");
static constexpr bool kHasDefaultCase = kDefaultIndex >= 0; static constexpr bool kHasDefaultCase = kDefaultIndex >= 0;
static constexpr bool kHasReturnType = !std::is_same_v<RETURN_TYPE, void>; static constexpr bool kHasReturnType = !std::is_same_v<RETURN_TYPE, void>;