Extended Description
E.g. the following code fails to compile:
template <typename T>
struct special_ptr
{
T* ptr;
template <typename U>
special_ptr<U> as()
{
special_ptr<U> result;
result.ptr = reinterpret_cast<U*>(this->ptr);
return result;
}
};
template <typename T>
struct thing
{
special_ptr<int> intPtr;
virtual void do_something()
{
auto charPtr = this->intPtr.as<char>();
}
};
struct empty {};
int main()
{
thing<empty> t;
}
You can also view it at https://godbolt.org/z/ywb5CS. Note that GCC does not have a problem with it. If you change 'thing' to no longer be a class template or if you make 'do_something' no longer virtual, it compiles fine.