Debian Codegraph @

clang/test/CXX/temp/temp.constr/temp.constr.atomic/constrant-satisfaction-conversions.cpp

raw
1 // RUN: %clang_cc1 -std=c++20 -x c++ -Wno-constant-logical-operand -verify %s
2
3 template<typename T> concept C =
4 sizeof(T) == 4 && !true; // requires atomic constraints sizeof(T) == 4 and !true
5
6 template<typename T> concept C2 = sizeof(T); // expected-error{{atomic constraint must be of type 'bool' (found }}
7
8 template<typename T> struct S {
9 constexpr operator bool() const { return true; }
10 };
11
12 // expected-error@+3{{atomic constraint must be of type 'bool' (found 'S<int>')}}
13 // expected-note@#FINST{{while checking constraint satisfaction}}
14 // expected-note@#FINST{{while substituting deduced template arguments into function template 'f' [with T = int]}}
15 template<typename T> requires (S<T>{})
16 void f(T);
17 void f(long);
18
19 // Ensure this applies to operator && as well.
20 // expected-error@+3{{atomic constraint must be of type 'bool' (found 'S<int>')}}
21 // expected-note@#F2INST{{while checking constraint satisfaction}}
22 // expected-note@#F2INST{{while substituting deduced template arguments into function template 'f2' [with T = int]}}
23 template<typename T> requires (S<T>{} && true)
24 void f2(T);
25 void f2(long);
26
27 template<typename T> requires requires {
28 requires S<T>{};
29 // expected-error@-1{{atomic constraint must be of type 'bool' (found 'S<int>')}}
30 // expected-note@-2{{while checking the satisfaction}}
31 // expected-note@-3{{while checking the satisfaction of nested requirement}}
32 // expected-note@-5{{while substituting template arguments}}
33 // expected-note@#F3INST{{while checking constraint satisfaction}}
34 // expected-note@#F3INST{{while substituting deduced template arguments into function template 'f3' [with T = int]}}
35 //
36 }
37 void f3(T);
38 void f3(long);
39
40 // Doesn't diagnose, since this is no longer a compound requirement.
41 template<typename T> requires (bool(1 && 2))
42 void f4(T);
43 void f4(long);
44
45 void g() {
46 f(0); // #FINST
47 f2(0); // #F2INST
48 f3(0); // #F3INST
49 f4(0);
50 }
51
52 template<typename T>
53 auto Nullptr = nullptr;
54
55 template<typename T> concept NullTy = Nullptr<T>;
56 // expected-error@-1{{atomic constraint must be of type 'bool' (found }}
57 // expected-note@+1{{while checking the satisfaction}}
58 static_assert(NullTy<int>);
59
60 template<typename T>
61 auto Struct = S<T>{};
62
63 template<typename T> concept StructTy = Struct<T>;
64 // expected-error@-1{{atomic constraint must be of type 'bool' (found 'S<int>')}}
65 // expected-note@+1{{while checking the satisfaction}}
66 static_assert(StructTy<int>);