aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp2a/concepts-requires2.C
blob: a9b422b5bac5e3ed130be3dda09c4f23626101cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// { dg-do compile { target c++20 } }

// Test the types of atomic constraints

// req5.C
struct fool {
  constexpr fool operator&&(fool) const { return {}; }
  constexpr fool operator||(fool) const { return {}; }
};

template<typename T> constexpr fool p1() { return {}; }
template<typename T> constexpr fool p2() { return {}; }

template<typename T>
concept Bad = p1<T>() && p2<T>(); // { dg-error "bool" }

template<typename T> requires Bad<T> void bad(T x) { }

void driver_2()
{
  bad(0); // { dg-message "" }
}

// req6.C
struct X { };
int operator==(X, X) { return 0; }

template<typename T>
concept C1 = (X()); // { dg-error "bool" }

template<typename T>
concept C2 = (X() == X()); // { dg-error "bool" }

template<typename T>
  requires C1<T>
void h1(T) { }

template<typename T>
  requires C2<T>
void h2(T);

void driver_3()
{
  h1(0); // { dg-message "" }
  h2(0); // { dg-message "" }
}

// req7.C
template<bool B>
struct boolean_constant
{
  constexpr operator bool() const { return B; }
};

using true_type = boolean_constant<true>;
using false_type = boolean_constant<false>;

template<typename T>
struct dependent_true : true_type { };

template<typename T>
struct dependent_false : false_type { };

template<typename T>
  requires (dependent_true<T>{}) // { dg-message "bool" }
struct S5 { };

template<typename T>
  requires (dependent_false<T>{}) // { dg-message "bool" }
struct S6 { };

S5<int> x5; // { dg-error "template constraint failure" }
S6<int> x6; // { dg-error "template constraint failure" }