| 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 | struct Dummy4 {}; |
| 27 | struct Dummy5 {}; |
| 28 | |
| 29 | template <> |
| 30 | struct std::tuple_size<Dummy1> { |
| 31 | public: |
| 32 | static std::size_t value; |
| 33 | }; |
| 34 | |
| 35 | template <> |
| 36 | struct std::tuple_size<Dummy2> { |
| 37 | public: |
| 38 | static void value() {} |
| 39 | }; |
| 40 | |
| 41 | template <> |
| 42 | struct std::tuple_size<Dummy3> {}; |
| 43 | |
| 44 | template <> |
| 45 | struct std::tuple_size<Dummy4> { |
| 46 | void value(); |
| 47 | }; |
| 48 | |
| 49 | template <> |
| 50 | struct std::tuple_size<Dummy5> { |
| 51 | size_t value; |
| 52 | }; |
| 53 | |
| 54 | void f() { |
| 55 | // Test that tuple_size<const T> is not incomplete when tuple_size<T>::value |
| 56 | // is well-formed but not a constant expression. |
| 57 | { |
| 58 | // expected-error@*:* 1 {{is not a constant expression}} |
| 59 | (void)std::tuple_size<const Dummy1>::value; // expected-note {{here}} |
| 60 | } |
| 61 | // Test that tuple_size<const T> is not incomplete when tuple_size<T>::value |
| 62 | // is well-formed but not convertible to size_t. |
| 63 | { |
| 64 | // expected-error@*:* 1 {{value of type 'void ()' is not implicitly convertible to}} |
| 65 | (void)std::tuple_size<const Dummy2>::value; // expected-note {{here}} |
| 66 | } |
| 67 | // Test that tuple_size<const T> generates an error when tuple_size<T> is |
| 68 | // complete but has no ::value member. |
| 69 | { |
| 70 | // expected-error@*:* 1 {{implicit instantiation of undefined template}} |
| 71 | (void)std::tuple_size<const Dummy3>::value; |
| 72 | } |
| 73 | // Test that tuple_size<const T> generates an error when tuple_size<T> has |
| 74 | // the ::value member but tuple_size<T>::value is ill-formed. |
| 75 | { |
| 76 | // expected-error@*:* 1 {{implicit instantiation of undefined template}} |
| 77 | (void)std::tuple_size<const Dummy4>::value; |
| 78 | } |
| 79 | // Test that tuple_size<const T> generates an error when tuple_size<T> has |
| 80 | // the ::value member which is non-static. |
| 81 | { |
| 82 | // expected-error@*:* 1 {{invalid use of non-static data member 'value'}} |
| 83 | (void)std::tuple_size<const Dummy5>::value; // expected-note {{here}} |
| 84 | } |
| 85 | } |
| 86 | |