Compiler bug: error C2839 when operator-> returns pointer to built-in type
When operator->() returns a pointer to a built-in type (e.g., char), it
doesn't work properly on either VC++ 2003 or VC++ 2005. The following
valid C++ program is rejected by VC++, saying:
error C2839: invalid return type 'C *' for overloaded 'operator ->'
//////////////////////////////////////////////////////////////////////
typedef char C;
template <typename T>
class SmartPointer {
T * m_ptr;
public:
T * operator->() const {
return m_ptr;
}
SmartPointer(T* arg) : m_ptr(arg) {
}
};
int main() {
C* rawPtr = 0;
SmartPointer<C> smartPtr = 0;
rawPtr->~C(); // Okay :-)
smartPtr.operator->()->~C(); // Okay :-)
smartPtr->~C(); // error C2839!!! :-(
}
//////////////////////////////////////////////////////////////////////
Is this a known bug? I didn't find it at
https://connect.microsoft.com/VisualStudio/feedback
FYI, the thing is relevant to the resolution of C++ Standard Library
issue 659, "istreambuf_iterator should have an operator->()"
http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#659
Kind regards,
--
Niels Dekker
http://www.xs4all.nl/~nd/dekkerware
Scientific programmer at LKEB, Leiden University Medical Center