| 1 |
// { dg-do compile { target c++11 } } |
| 2 |
// PR c++/86246 ICE in tsubst |
| 3 |
|
| 4 |
namespace std { |
| 5 |
template<typename T> struct is_class { |
| 6 |
static constexpr bool value = true; |
| 7 |
}; |
| 8 |
template<> struct is_class<double> { |
| 9 |
static constexpr bool value = false; |
| 10 |
}; |
| 11 |
} |
| 12 |
|
| 13 |
class MyClass { |
| 14 |
public: |
| 15 |
operator double() const { |
| 16 |
return 1; |
| 17 |
} |
| 18 |
template<typename T> |
| 19 |
operator T() const { |
| 20 |
static_assert(std::is_class<T>::value, "problem"); |
| 21 |
return T(); |
| 22 |
} |
| 23 |
}; |
| 24 |
|
| 25 |
template<typename T> |
| 26 |
void SetValue(const MyClass& obj, T* value) { |
| 27 |
// erroneously dispatched to operator T when T is double |
| 28 |
*value = obj.operator T(); |
| 29 |
} |
| 30 |
|
| 31 |
int main() { |
| 32 |
MyClass obj; |
| 33 |
// works fine |
| 34 |
obj.operator double (); |
| 35 |
double x; |
| 36 |
// error, when operator T is called in SetValue |
| 37 |
SetValue(obj, &x); |
| 38 |
} |