Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/concepts-memfun4.C

raw
1 // PR c++/113191
2 // CWG 2789
3 // { dg-do compile { target c++20 } }
4 // { dg-additional-options "-Wno-error=c++23-extensions" { target c++20_only } }
5
6 template<typename> struct S;
7
8 template<typename T = void>
9 struct B {
10 constexpr int f() const requires true { return 5; }
11 constexpr operator int () const requires true { return 5; }
12 constexpr int g(this S<T>&&) requires true { return 5; }
13 // { dg-warning "explicit object" "" { target c++20_only } .-1 }
14 constexpr int h() requires true { return 5; }
15 };
16
17 template<typename = void>
18 struct S : B<> {
19 using B::f;
20 using B::g;
21 using B::h;
22 constexpr int f() const { return 10; }
23 constexpr operator int () const { return 10; }
24 constexpr int g() { return 10; }
25 constexpr int h(this S&&) { return 10; }
26 // { dg-warning "explicit object" "" { target c++20_only } .-1 }
27 };
28
29 // ambiguous, constraints aren't considered since the candidates
30 // come from different classes
31 static_assert(S<>{}.f() == 5); // { dg-error "ambiguous" }
32 static_assert(S<>{}.g() == 5); // { dg-error "ambiguous" }
33 static_assert(S<>{}.h() == 5); // { dg-error "ambiguous" }
34
35 template <typename = void>
36 struct C {
37 constexpr int f() const { return 15; }
38 constexpr operator int () const { return 15; }
39 };
40
41 template <typename = void>
42 struct S2: B<>, C<> { };
43
44 // ambiguous as above
45 static_assert(S2<>{} == 5); // { dg-error "ambiguous" }
46
47 // ambiguous lookup, so we never actually compare the candidates
48 // if we did, implicit object parms don't match due to different classes
49 // so constraints aren't considered and it would still be ambiguous
50 static_assert(S2<>{}.f() == 5); // { dg-error "ambiguous" }
51
52 template <typename = void>
53 struct S3 : B<> {
54 using B::f;
55 constexpr int f() volatile { return 10; }
56 };
57
58 static_assert(S3<>{}.f() == 5); // { dg-error "ambiguous" }
59
60 template <typename = void>
61 struct S4 : B<> {
62 using B::f;
63 constexpr int f() const & { return 10; }
64 };
65
66 static_assert(S4<>{}.f() == 5); // { dg-error "ambiguous" }
67
68 template <typename = void>
69 struct C2 {
70 constexpr operator int () volatile { return 15; }
71 };
72
73 template <typename = void>
74 struct S5: B<>, C2<> { };
75
76 // implicit object parms don't match due to different cv-quals
77 static_assert(S5<>{} == 5); // { dg-error "ambiguous" }
78
79 namespace N1 {
80 template <class = void> struct B;
81
82 template <class = void>
83 struct A {
84 constexpr bool operator==(B<>&) { return false; }
85 };
86
87 template <class>
88 struct B {
89 constexpr bool operator==(A<>&) requires true { return true; }
90 };
91
92 A<> a;
93 B<> b;
94 // A op== and B op== are defined in different classes so constraints
95 // aren't considered, and the tie is broken via reversedness.
96 static_assert (!(a == b));
97 }