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 std::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 
f()42 void f() {
43   // Test that tuple_size<const T> is not incomplete when tuple_size<T>::value
44   // is well-formed but not a constant expression.
45   {
46     // expected-error@*:* 1 {{is not a constant expression}}
47     (void)std::tuple_size<const Dummy1>::value; // expected-note {{here}}
48   }
49   // Test that tuple_size<const T> is not incomplete when tuple_size<T>::value
50   // is well-formed but not convertible to size_t.
51   {
52     // expected-error@*:* 1 {{value of type 'void ()' is not implicitly convertible to}}
53     (void)std::tuple_size<const Dummy2>::value; // expected-note {{here}}
54   }
55   // Test that tuple_size<const T> generates an error when tuple_size<T> is
56   // complete but ::value isn't a constant expression convertible to size_t.
57   {
58     // expected-error@*:* 1 {{no member named 'value'}}
59     (void)std::tuple_size<const Dummy3>::value; // expected-note {{here}}
60   }
61 }
62