In The this pointer [class.this], the C++ standard states:

The type of this in a member function of a class X is X*.

i.e. this is not const. But why is it then that

struct M {
    M() { this = new M; }
};

gives

error: invalid lvalue in assignment  <-- gcc
'=' : left operand must be l-value   <-- VC++
'=' : left operand must be l-value   <-- clang++
'=' : left operand must be l-value   <-- ICC
(source: some online compiler frontends)

In other words, this is not const, but it really is!

Edit
Report