]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/common_type/requirements/sfinae_friendly_2.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / common_type / requirements / sfinae_friendly_2.cc
1 // { dg-do compile { target c++11 } }
2
3 // Copyright (C) 2012-2021 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
19
20 #include <type_traits>
21 #include <array>
22 #include <utility>
23
24 template<typename... Args>
25 constexpr
26 std::array<typename std::common_type<Args...>::type,
27 sizeof...(Args)>
28 make_array(Args&&... args) // { dg-error "no type.*common_type<>" }
29 {
30 typedef typename std::common_type<Args...>::type CT;
31 return std::array<CT, sizeof...(Args)>{static_cast<CT>
32 (std::forward<Args>(args))...};
33 }
34
35 void test01()
36 {
37 constexpr auto a1 = make_array(0);
38 constexpr auto a2 = make_array(0, 1.2);
39 constexpr auto a3 = make_array(5, true, 3.1415f, 'c');
40
41 int i{};
42 double d{1.2};
43 float f{3.1415f};
44
45 auto b1 = make_array(i);
46 auto b2 = make_array(i, 1.2);
47 auto b3 = make_array(i, d);
48 auto b4 = make_array(0, d);
49 auto b5 = make_array(i, true, f, 'c');
50
51 static_assert(std::is_same<decltype(a1), const std::array<int, 1>>(), "");
52 static_assert(std::is_same<decltype(a2), const std::array<double, 2>>(), "");
53 static_assert(std::is_same<decltype(a3), const std::array<float, 4>>(), "");
54
55 static_assert(std::is_same<decltype(b1), std::array<int, 1>>(), "");
56 static_assert(std::is_same<decltype(b2), std::array<double, 2>>(), "");
57 static_assert(std::is_same<decltype(b3), std::array<double, 2>>(), "");
58 static_assert(std::is_same<decltype(b4), std::array<double, 2>>(), "");
59 static_assert(std::is_same<decltype(b5), std::array<float, 4>>(), "");
60 }
61
62 void test02()
63 {
64 make_array(); // { dg-error "no matching function" }
65 }
66 // { dg-prune-output "substitution" }
67 // { dg-prune-output "include" }