Reputation: 2534
The last item in Microsoft extensions to C++, "Passing a Non-Const Pointer Parameter to a Function that Expects a Reference to a Const Pointer Parameter", is an extension and hence it could be considered a beneficial feature. However, I fail to see its value. The very example they show suggests it is dangerous.
typedef int T;
const T acT = 9; // A constant of type 'T'
const T * pcT = & acT; // A pointer to a constant of type 'T'
void func2 ( const T * & rpcT ) // A reference to a pointer to a constant of type 'T'
{
rpcT = pcT;
}
T * pT; // A pointer to a 'T'
void func ()
{
func2 ( pT ); // Should be an error, but isn't detected
* pT = 7; // Invalidly overwrites the constant 'acT'
}
Why is it an extension and not a bug?
Upvotes: 1
Views: 74
Reputation: 88215
Because "It's not a bug, it's a feature."
Yes, this is clearly a bad thing. You'd have to ask the Microsoft engineers responsible, but I suspect it was a bug and it was maintained only because at some point somebody's software depended on it and Microsoft wanted to maintain backwards compatibility.
However, it appears that this documentation is out of date: I can't get Visual Studio 2015 or 2013 to accept code using this extension.
Upvotes: 2