| 1 |
// PR c++/101698 |
| 2 |
// { dg-do compile { target c++11 } } |
| 3 |
|
| 4 |
class Base { |
| 5 |
public: |
| 6 |
template <class T> |
| 7 |
operator const T&() const = delete; |
| 8 |
|
| 9 |
virtual operator const int&() const { |
| 10 |
static int res; |
| 11 |
return res; |
| 12 |
} |
| 13 |
}; |
| 14 |
|
| 15 |
template <class T> |
| 16 |
class Derive : public Base { |
| 17 |
public: |
| 18 |
operator const T&() const override { |
| 19 |
using Y = int; |
| 20 |
//static_assert(__is_same_as(T,Y), ""); |
| 21 |
|
| 22 |
static int res; |
| 23 |
|
| 24 |
res = Base::operator const Y&(); // OK |
| 25 |
res = Base::operator const T&(); // { dg-bogus "deleted" } |
| 26 |
return res; |
| 27 |
} |
| 28 |
}; |
| 29 |
|
| 30 |
int main() { |
| 31 |
Derive<int> a; |
| 32 |
const int& b = a; |
| 33 |
(void)b; |
| 34 |
} |