1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <tuple>
10 
11 // template <class... Types> class tuple;
12 
13 // template <class... Types>
14 //   struct tuple_size<tuple<Types...>>
15 //     : public integral_constant<size_t, sizeof...(Types)> { };
16 
17 // UNSUPPORTED: c++03
18 
19 #include <tuple>
20 #include <array>
21 #include <type_traits>
22 
23 struct Dummy1 {};
24 struct Dummy2 {};
25 struct Dummy3 {};
26 
27 template <>
28 struct std::tuple_size<Dummy1> {
29 public:
30   static size_t value;
31 };
32 
33 template <>
34 struct std::tuple_size<Dummy2> {
35 public:
valuestd::tuple_size36   static void value() {}
37 };
38 
39 template <>
40 struct std::tuple_size<Dummy3> {};
41 
main(int,char **)42 int main(int, char**)
43 {
44   // Test that tuple_size<const T> is not incomplete when tuple_size<T>::value
45   // is well-formed but not a constant expression.
46   {
47     // expected-error@__tuple:* 1 {{is not a constant expression}}
48     (void)std::tuple_size<const Dummy1>::value; // expected-note {{here}}
49   }
50   // Test that tuple_size<const T> is not incomplete when tuple_size<T>::value
51   // is well-formed but not convertible to size_t.
52   {
53     // expected-error@__tuple:* 1 {{value of type 'void ()' is not implicitly convertible to}}
54     (void)std::tuple_size<const Dummy2>::value; // expected-note {{here}}
55   }
56   // Test that tuple_size<const T> generates an error when tuple_size<T> is
57   // complete but ::value isn't a constant expression convertible to size_t.
58   {
59     // expected-error@__tuple:* 1 {{no member named 'value'}}
60     (void)std::tuple_size<const Dummy3>::value; // expected-note {{here}}
61   }
62 
63   return 0;
64 }
65