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
23struct Dummy1 {};
24struct Dummy2 {};
25struct Dummy3 {};
26struct Dummy4 {};
27struct Dummy5 {};
28
29template <>
30struct std::tuple_size<Dummy1> {
31public:
32 static std::size_t value;
33};
34
35template <>
36struct std::tuple_size<Dummy2> {
37public:
38 static void value() {}
39};
40
41template <>
42struct std::tuple_size<Dummy3> {};
43
44template <>
45struct std::tuple_size<Dummy4> {
46 void value();
47};
48
49template <>
50struct std::tuple_size<Dummy5> {
51 size_t value;
52};
53
54void 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

source code of libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_incomplete.verify.cpp