-
Notifications
You must be signed in to change notification settings - Fork 75
/
self.cxx
43 lines (33 loc) · 854 Bytes
/
self.cxx
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
#include <iostream>
#include <utility>
struct B1 {
template<typename Self>
auto&& get0(this Self&& self) {
// Error: ambiguous declarations found from id-expression 'i'.
return std::forward<Self>(self).i;
}
template<typename Self>
auto&& get1(this Self&& self) {
// P00847R7: mitigate against shadowing by copy-cvref.
return ((__copy_cvref(Self, B1)&&)self).i;
}
template<typename Self>
auto&& get2(this Self&& self : B1) {
// Circle deduced forward reference uses a normal forward.
return std::forward<Self>(self).i;
}
int i;
};
struct B2 {
int i;
};
struct D : B1, B2 { };
int main() {
D d;
// Uncomment this for ambiguous declaration error.
// int x0 = d.get0();
// Works with explicit upcast to B1.
int x1 = d.get1();
// Works with deduced forward reference.
int x2 = d.get2();
}