]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/variant/87619.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / variant / 87619.cc
1 // Copyright (C) 2018-2020 Free Software Foundation, Inc.
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
18 // { dg-options "-std=gnu++17" }
19 // { dg-do compile { target c++17 } }
20
21 #include <variant>
22 #include <utility>
23 #include <limits>
24
25 template<std::size_t I>
26 struct S {
27 };
28
29 template <std::size_t... Is>
30 void f_impl(std::index_sequence<Is...>)
31 {
32 using V = std::variant<S<Is>...>;
33 // For a variant of 255 alternatives the valid indices are [0,254]
34 // and index 255 means valueless-by-exception, so fits in one byte.
35 if constexpr (std::variant_size_v<V> <=
36 std::numeric_limits<unsigned char>::max())
37 static_assert(sizeof(V) == 2);
38 else
39 static_assert(sizeof(V) > 2);
40 }
41
42 template <std::size_t I>
43 void f()
44 {
45 f_impl(std::make_index_sequence<I>{});
46 }
47
48 int main()
49 {
50 f<std::numeric_limits<unsigned char>::max() - 1>();
51 f<std::numeric_limits<unsigned char>::max()>();
52 f<std::numeric_limits<unsigned char>::max() + 1>();
53 }