]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/common_type/requirements/sfinae_friendly_2.cc
1 // { dg-do compile { target c++11 } }
3 // Copyright (C) 2012-2021 Free Software Foundation, Inc.
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)
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.
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/>.
20 #include <type_traits>
24 template<typename
... Args
>
26 std::array
<typename
std::common_type
<Args
...>::type
,
28 make_array(Args
&&... args
) // { dg-error "no type.*common_type<>" }
30 typedef typename
std::common_type
<Args
...>::type CT
;
31 return std::array
<CT
, sizeof...(Args
)>{static_cast<CT
>
32 (std::forward
<Args
>(args
))...};
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');
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');
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>>(), "");
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>>(), "");
64 make_array(); // { dg-error "no matching function" }
66 // { dg-prune-output "substitution" }
67 // { dg-prune-output "include" }