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