llvm-project

Форк
0
/
cxx2a-concepts-requires-expr.cpp 
170 строк · 5.7 Кб
1
// RUN: %clang_cc1 -std=c++2a -x c++ %s -verify
2

3
bool r1 = requires () {};
4
// expected-error@-1 {{a requires expression must contain at least one requirement}}
5

6
bool r2 = requires { requires true; };
7

8
bool r3 = requires (int a, ...) { requires true; };
9
// expected-error@-1 {{varargs not allowed in requires expression}}
10

11
template<typename... T>
12
bool r4 = requires (T... ts) { requires true; };
13

14
bool r5 = requires (bool c, int d) { c; d; };
15

16
bool r6 = requires (bool c, int d) { c; d; } && decltype(d){};
17
// expected-error@-1 {{use of undeclared identifier 'd'}}
18

19
bool r7 = requires (bool c) { c; (requires (int d) { c; d; }); d; } && decltype(c){} && decltype(d){};
20
// expected-error@-1 2{{use of undeclared identifier 'd'}}
21
// expected-error@-2 {{use of undeclared identifier 'c'}}
22

23
bool r8 = requires (bool, int) { requires true; };
24

25
bool r9 = requires (bool a, int a) { requires true; };
26
// expected-error@-1 {{redefinition of parameter 'a'}}
27
// expected-note@-2 {{previous declaration is here}}
28

29
bool r10 = requires (struct new_struct { int x; } s) { requires true; };
30
// expected-error@-1 {{'new_struct' cannot be defined in a parameter type}}
31

32
bool r11 = requires (int x(1)) { requires true; };
33
// expected-error@-1 {{expected parameter declarator}}
34
// expected-error@-2 {{expected ')'}}
35
// expected-note@-3 {{to match this '('}}
36

37
bool r12 = requires (int x = 10) { requires true; };
38
// expected-error@-1 {{default arguments not allowed for parameters of a requires expression}}
39

40
bool r13 = requires (int f(int)) { requires true; };
41

42
bool r14 = requires (int (*f)(int)) { requires true; };
43

44
bool r15 = requires (10) { requires true; };
45
// expected-error@-1 {{expected parameter declarator}}
46
// expected-error@-2 {{expected ')'}} expected-note@-2 {{to match}}
47

48
bool r16 = requires (auto x) { requires true; };
49
// expected-error@-1 {{'auto' not allowed in requires expression parameter}}
50

51
bool r17 = requires (auto [x, y]) { requires true; };
52
// expected-error@-1 {{'auto' not allowed in requires expression parameter}}
53
// expected-error@-2 {{use of undeclared identifier 'x'}}
54

55
using a = int;
56

57
bool r18 = requires { typename a; };
58

59
bool r19 = requires { typename ::a; };
60

61
template<typename T> struct identity { using type = T; };
62

63
template<typename T> using identity_t = T;
64

65
bool r20 = requires {
66
    typename identity<int>::type;
67
    typename identity<int>;
68
    typename ::identity_t<int>;
69
};
70

71
struct s { bool operator==(const s&); ~s(); };
72

73
bool r21 = requires { typename s::operator==; };
74
// expected-error@-1 {{expected an identifier or template-id after '::'}}
75

76
bool r22 = requires { typename s::~s; };
77
// expected-error@-1 {{expected an identifier or template-id after '::'}}
78

79
template<typename T>
80
bool r23 = requires { typename identity<T>::temp<T>; };
81
// expected-error@-1 {{use 'template' keyword to treat 'temp' as a dependent template name}}
82

83
template<typename T>
84
bool r24 = requires {
85
    typename identity<T>::template temp<T>;
86
    typename identity<T>::template temp; // expected-error{{template argument list is expected after a name prefixed by the template keyword}}
87
};
88

89
bool r25 = requires { ; };
90
// expected-error@-1 {{expected expression}}
91

92
bool r26 = requires { {}; };
93
// expected-error@-1 {{expected expression}}
94

95
bool r27 = requires { { 0 } noexcept; };
96

97
bool r28 = requires { { 0 } noexcept noexcept; };
98
// expected-error@-1 {{expected '->' before expression type requirement}}
99
// expected-error@-2 {{expected concept name with optional arguments}}
100

101
template<typename T>
102
concept C1 = true;
103

104
template<typename T, typename U>
105
concept C2 = true;
106

107
bool r29 = requires { { 0 } noexcept C1; };
108
// expected-error@-1 {{expected '->' before expression type requirement}}
109

110
bool r30 = requires { { 0 } noexcept -> C2<int>; };
111

112
namespace ns { template<typename T> concept C = true; }
113

114
bool r31 = requires { { 0 } noexcept -> ns::C; };
115

116
template<typename T>
117
T i1 = 0;
118

119
bool r32 = requires { requires false, 1; };
120
// expected-error@-1 {{expected ';' at end of requirement}}
121

122
bool r33 = requires { 0 noexcept; };
123
// expected-error@-1 {{'noexcept' can only be used in a compound requirement (with '{' '}' around the expression)}}
124

125
bool r34 = requires { 0 int; };
126
// expected-error@-1 {{expected ';' at end of requirement}}
127

128
bool r35 = requires { requires true };
129
// expected-error@-1 {{expected ';' at end of requirement}}
130

131
bool r36 = requires (bool b) { requires sizeof(b) == 1; };
132

133
template<typename T>
134
void r37(bool b) requires requires { 1 } {}
135
// expected-error@-1 {{expected ';' at end of requirement}}
136

137
bool r38 = requires { requires { 1; }; };
138
// expected-error@-1 {{requires expression in requirement body; did you intend to place it in a nested requirement? (add another 'requires' before the expression)}}
139

140
bool r39 = requires { requires () { 1; }; };
141
// expected-error@-1 {{requires expression in requirement body; did you intend to place it in a nested requirement? (add another 'requires' before the expression)}}
142

143
bool r40 = requires { requires (int i) { i; }; };
144
// expected-error@-1 {{requires expression in requirement body; did you intend to place it in a nested requirement? (add another 'requires' before the expression)}}
145

146
bool r41 = requires { requires (); };
147
// expected-error@-1 {{expected expression}}
148

149
bool r42 = requires { typename long; }; // expected-error {{expected a qualified name after 'typename'}}
150

151
template <int N>
152
requires requires {
153
 typename _BitInt(N); // expected-error {{expected a qualified name after 'typename'}}
154
} using r43 = void;
155

156
template <int N>
157
using BitInt = _BitInt(N);
158

159
template <int N>
160
requires requires {
161
 typename BitInt<N>; // ok
162
} using r44 = void;
163

164
namespace GH73112 {
165
void f() {
166
    requires { requires(int; } // expected-error {{expected ')'}} \
167
                               // expected-error {{expected expression}} \
168
                               // expected-note {{to match this '('}}
169
}
170
}
171

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.