Debian Codegraph @

clang/test/CXX/temp/temp.spec/temp.expl.spec/p14-23.cpp

raw
1 // RUN: %clang_cc1 -std=c++20 -verify %s
2
3 namespace N0 {
4 template<int I>
5 concept C = I >= 4;
6
7 template<int I>
8 concept D = I < 8;
9
10 template<int I>
11 struct A { // #defined-here
12 constexpr static int f() { return 0; }
13 constexpr static int f() requires C<I> && D<I> { return 1; }
14 constexpr static int f() requires C<I> { return 2; }
15
16 constexpr static int g() requires C<I> { return 0; } // #candidate-0
17 constexpr static int g() requires D<I> { return 1; } // #candidate-1
18
19 constexpr static int h() requires C<I> { return 0; } // expected-note {{member declaration nearly matches}}
20 };
21
22 template<>
23 constexpr int A<2>::f() { return 3; }
24
25 template<>
26 constexpr int A<4>::f() { return 4; }
27
28 template<>
29 constexpr int A<8>::f() { return 5; }
30
31 static_assert(A<3>::f() == 0);
32 static_assert(A<5>::f() == 1);
33 static_assert(A<9>::f() == 2);
34 static_assert(A<2>::f() == 3);
35 static_assert(A<4>::f() == 4);
36 static_assert(A<8>::f() == 5);
37
38 template<>
39 constexpr int A<0>::g() { return 2; }
40
41 template<>
42 constexpr int A<8>::g() { return 3; }
43
44 template<>
45 constexpr int A<6>::g() { return 4; } // expected-error {{ambiguous member function specialization 'N0::A<6>::g' of 'N0::A::g'}}
46 // expected-note@#candidate-0 {{member function specialization matches 'g'}}
47 // expected-note@#candidate-1 {{member function specialization matches 'g'}}
48
49 static_assert(A<9>::g() == 0);
50 static_assert(A<1>::g() == 1);
51 static_assert(A<0>::g() == 2);
52 static_assert(A<8>::g() == 3);
53
54 template<>
55 constexpr int A<4>::h() { return 1; }
56
57 template<>
58 constexpr int A<0>::h() { return 2; } // expected-error {{out-of-line definition of 'h' does not match any declaration in 'N0::A<0>'}}
59 // expected-note@#defined-here {{defined here}}
60
61 static_assert(A<5>::h() == 0);
62 static_assert(A<4>::h() == 1);
63 } // namespace N0
64
65 namespace N1 {
66 template<int I>
67 concept C = I > 0;
68
69 template<int I>
70 concept D = I > 1;
71
72 template<int I>
73 concept E = I > 2;
74
75 template<int I>
76 struct A {
77 void f() requires C<I> && D<I>; // expected-note {{member function specialization matches 'f'}}
78 void f() requires C<I> && E<I>; // expected-note {{member function specialization matches 'f'}}
79 void f() requires C<I> && D<I> && true; // expected-note {{member function specialization matches 'f'}}
80
81 void g() requires C<I> && E<I>; // expected-note {{member function specialization matches 'g'}}
82 void g() requires C<I> && D<I>; // expected-note {{member function specialization matches 'g'}}
83 void g() requires C<I> && D<I> && true; // expected-note {{member function specialization matches 'g'}}
84 };
85
86 template<>
87 void A<3>::f(); // expected-error {{ambiguous member function specialization 'N1::A<3>::f' of 'N1::A::f'}}
88
89 template<>
90 void A<3>::g(); // expected-error {{ambiguous member function specialization 'N1::A<3>::g' of 'N1::A::g'}}
91 } // namespace N1