aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/20_util/common_type/requirements/sfinae_friendly_2.cc
blob: 8b0e9fd3f33274365622deddc54f702f82a02a5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// { dg-do compile { target c++11 } }

// Copyright (C) 2012-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3.  If not see
// <http://www.gnu.org/licenses/>.

#include <type_traits>
#include <array>
#include <utility>

template<typename... Args>
constexpr
std::array<typename std::common_type<Args...>::type, 
  sizeof...(Args)>
make_array(Args&&... args)  // { dg-error "invalid use" }
{
  typedef typename std::common_type<Args...>::type CT;
  return std::array<CT, sizeof...(Args)>{static_cast<CT>
      (std::forward<Args>(args))...};
}

void test01()
{
  constexpr auto a1 = make_array(0);
  constexpr auto a2 = make_array(0, 1.2);
  constexpr auto a3 = make_array(5, true, 3.1415f, 'c');
  
  int i{};
  double d{1.2};
  float f{3.1415f};
  
  auto b1 = make_array(i);
  auto b2 = make_array(i, 1.2);
  auto b3 = make_array(i, d);
  auto b4 = make_array(0, d);
  auto b5 = make_array(i, true, f, 'c');

  static_assert(std::is_same<decltype(a1), const std::array<int, 1>>(), "");
  static_assert(std::is_same<decltype(a2), const std::array<double, 2>>(), "");
  static_assert(std::is_same<decltype(a3), const std::array<float, 4>>(), "");

  static_assert(std::is_same<decltype(b1), std::array<int, 1>>(), "");
  static_assert(std::is_same<decltype(b2), std::array<double, 2>>(), "");
  static_assert(std::is_same<decltype(b3), std::array<double, 2>>(), "");
  static_assert(std::is_same<decltype(b4), std::array<double, 2>>(), "");
  static_assert(std::is_same<decltype(b5), std::array<float, 4>>(), "");
}

void test02()
{
  make_array(); // { dg-error "no matching function" }
}
// { dg-prune-output "substitution" }
// { dg-prune-output "include" }