Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/g++.dg/lookup/pr87531.C @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
131:84e7813d76e9 | 145:1830386684a0 |
---|---|
1 // PR c+/87531 lookup of operator= in templates | |
2 // { dg-do run } | |
3 | |
4 struct Base { | |
5 void operator= (Base const&); | |
6 }; | |
7 | |
8 void Base::operator= (Base const &) | |
9 { | |
10 } | |
11 | |
12 template <typename T> | |
13 struct Derived : Base | |
14 { | |
15 T v; | |
16 | |
17 Derived() : v (0) {} | |
18 Derived(T v_) : v (v_) {} | |
19 | |
20 T &assign1 (Derived const& rhs) | |
21 { | |
22 operator=(rhs); // erroneously bound to Base::operator= | |
23 return v; | |
24 } | |
25 | |
26 T &assign2 (Derived const& rhs) | |
27 { | |
28 this->operator=(rhs); // erroneously bound to Base::operator= | |
29 return v; | |
30 } | |
31 }; | |
32 | |
33 template <typename T> | |
34 struct Single | |
35 { | |
36 T v; | |
37 | |
38 Single () : v (0) {} | |
39 Single (T v_) : v (v_) {} | |
40 | |
41 T &assign1 (Single const& rhs) | |
42 { | |
43 operator=(rhs); // lookup failed | |
44 return v; | |
45 } | |
46 | |
47 T &assign2 (Single const& rhs) | |
48 { | |
49 this->operator=(rhs); // Marked as dependent, happened to work | |
50 return v; | |
51 } | |
52 }; | |
53 | |
54 int main() | |
55 { | |
56 Derived<int> a, b(123); | |
57 | |
58 if (a.assign1 (b) != 123) | |
59 return 1; | |
60 | |
61 if (a.assign2 (b) != 123) | |
62 return 2; | |
63 | |
64 Single<int> c, d(123); | |
65 | |
66 if (c.assign1 (d) != 123) | |
67 return 3; | |
68 | |
69 if (c.assign2 (d) != 123) | |
70 return 4; | |
71 | |
72 return 0; | |
73 } |