]>
Commit | Line | Data |
---|---|---|
99dee823 | 1 | // Copyright (C) 2018-2021 Free Software Foundation, Inc. |
4026227f VV |
2 | // |
3 | // This file is part of the GNU ISO C++ Library. This library is free | |
4 | // software; you can redistribute it and/or modify it under the | |
5 | // terms of the GNU General Public License as published by the | |
6 | // Free Software Foundation; either version 3, or (at your option) | |
7 | // any later version. | |
8 | ||
9 | // This library is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | ||
14 | // You should have received a copy of the GNU General Public License along | |
15 | // with this library; see the file COPYING3. If not see | |
16 | // <http://www.gnu.org/licenses/>. | |
17 | ||
4026227f | 18 | // { dg-do compile { target c++17 } } |
ad820b0b JW |
19 | // FIXME: Need increased timeout due to PR c++/102780 |
20 | // { dg-timeout-factor 2 { target c++20 } } | |
4026227f VV |
21 | |
22 | #include <variant> | |
23 | #include <utility> | |
24 | #include <limits> | |
25 | ||
26 | template<std::size_t I> | |
27 | struct S { | |
28 | }; | |
29 | ||
30 | template <std::size_t... Is> | |
31 | void f_impl(std::index_sequence<Is...>) | |
32 | { | |
33 | using V = std::variant<S<Is>...>; | |
34 | // For a variant of 255 alternatives the valid indices are [0,254] | |
35 | // and index 255 means valueless-by-exception, so fits in one byte. | |
36 | if constexpr (std::variant_size_v<V> <= | |
37 | std::numeric_limits<unsigned char>::max()) | |
38 | static_assert(sizeof(V) == 2); | |
39 | else | |
40 | static_assert(sizeof(V) > 2); | |
41 | } | |
42 | ||
43 | template <std::size_t I> | |
44 | void f() | |
45 | { | |
46 | f_impl(std::make_index_sequence<I>{}); | |
47 | } | |
48 | ||
49 | int main() | |
50 | { | |
51 | f<std::numeric_limits<unsigned char>::max() - 1>(); | |
52 | f<std::numeric_limits<unsigned char>::max()>(); | |
53 | f<std::numeric_limits<unsigned char>::max() + 1>(); | |
54 | } |