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 | // <iterator> |
10 | |
11 | // struct iterator_traits |
12 | // { |
13 | // }; |
14 | |
15 | #include <iterator> |
16 | #include "test_macros.h" |
17 | |
18 | struct A {}; |
19 | struct NotAnIteratorEmpty {}; |
20 | |
21 | struct NotAnIteratorNoDifference |
22 | { |
23 | // typedef int difference_type; |
24 | typedef A value_type; |
25 | typedef A* pointer; |
26 | typedef A& reference; |
27 | typedef std::forward_iterator_tag iterator_category; |
28 | }; |
29 | |
30 | struct NotAnIteratorNoValue |
31 | { |
32 | typedef int difference_type; |
33 | // typedef A value_type; |
34 | typedef A* pointer; |
35 | typedef A& reference; |
36 | typedef std::forward_iterator_tag iterator_category; |
37 | }; |
38 | |
39 | struct NotAnIteratorNoPointer |
40 | { |
41 | typedef int difference_type; |
42 | typedef A value_type; |
43 | // typedef A* pointer; |
44 | typedef A& reference; |
45 | typedef std::forward_iterator_tag iterator_category; |
46 | }; |
47 | |
48 | struct NotAnIteratorNoReference |
49 | { |
50 | typedef int difference_type; |
51 | typedef A value_type; |
52 | typedef A* pointer; |
53 | // typedef A& reference; |
54 | typedef std::forward_iterator_tag iterator_category; |
55 | }; |
56 | |
57 | struct NotAnIteratorNoCategory |
58 | { |
59 | typedef int difference_type; |
60 | typedef A value_type; |
61 | typedef A* pointer; |
62 | typedef A& reference; |
63 | // typedef std::forward_iterator_tag iterator_category; |
64 | }; |
65 | |
66 | int main(int, char**) |
67 | { |
68 | { |
69 | typedef std::iterator_traits<NotAnIteratorEmpty> T; |
70 | typedef T::difference_type DT; // expected-error-re {{no type named 'difference_type' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
71 | typedef T::value_type VT; // expected-error-re {{no type named 'value_type' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
72 | typedef T::pointer PT; // expected-error-re {{no type named 'pointer' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
73 | typedef T::reference RT; // expected-error-re {{no type named 'reference' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
74 | typedef T::iterator_category CT; // expected-error-re {{no type named 'iterator_category' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
75 | } |
76 | |
77 | { |
78 | typedef std::iterator_traits<NotAnIteratorNoDifference> T; |
79 | typedef T::difference_type DT; // expected-error-re {{no type named 'difference_type' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
80 | typedef T::value_type VT; // expected-error-re {{no type named 'value_type' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
81 | typedef T::pointer PT; // expected-error-re {{no type named 'pointer' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
82 | typedef T::reference RT; // expected-error-re {{no type named 'reference' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
83 | typedef T::iterator_category CT; // expected-error-re {{no type named 'iterator_category' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
84 | } |
85 | |
86 | { |
87 | typedef std::iterator_traits<NotAnIteratorNoValue> T; |
88 | typedef T::difference_type DT; // expected-error-re {{no type named 'difference_type' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
89 | typedef T::value_type VT; // expected-error-re {{no type named 'value_type' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
90 | typedef T::pointer PT; // expected-error-re {{no type named 'pointer' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
91 | typedef T::reference RT; // expected-error-re {{no type named 'reference' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
92 | typedef T::iterator_category CT; // expected-error-re {{no type named 'iterator_category' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
93 | } |
94 | #if TEST_STD_VER <= 17 || !defined(__cpp_lib_concepts) |
95 | { |
96 | typedef std::iterator_traits<NotAnIteratorNoPointer> T; |
97 | typedef T::difference_type DT; // expected-error-re {{no type named 'difference_type' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
98 | typedef T::value_type VT; // expected-error-re {{no type named 'value_type' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
99 | typedef T::pointer PT; // expected-error-re {{no type named 'pointer' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
100 | typedef T::reference RT; // expected-error-re {{no type named 'reference' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
101 | typedef T::iterator_category CT; // expected-error-re {{no type named 'iterator_category' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
102 | } |
103 | #endif // TEST_STD_VER <= 17 || !defined(__cpp_lib_concepts) |
104 | { |
105 | typedef std::iterator_traits<NotAnIteratorNoReference> T; |
106 | typedef T::difference_type DT; // expected-error-re {{no type named 'difference_type' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
107 | typedef T::value_type VT; // expected-error-re {{no type named 'value_type' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
108 | typedef T::pointer PT; // expected-error-re {{no type named 'pointer' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
109 | typedef T::reference RT; // expected-error-re {{no type named 'reference' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
110 | typedef T::iterator_category CT; // expected-error-re {{no type named 'iterator_category' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
111 | } |
112 | |
113 | { |
114 | typedef std::iterator_traits<NotAnIteratorNoCategory> T; |
115 | typedef T::difference_type DT; // expected-error-re {{no type named 'difference_type' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
116 | typedef T::value_type VT; // expected-error-re {{no type named 'value_type' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
117 | typedef T::pointer PT; // expected-error-re {{no type named 'pointer' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
118 | typedef T::reference RT; // expected-error-re {{no type named 'reference' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
119 | typedef T::iterator_category CT; // expected-error-re {{no type named 'iterator_category' in 'std:{{.*}}:iterator_traits<{{.+}}>}} |
120 | } |
121 | |
122 | return 0; |
123 | } |
124 | |