Please consider:
struct X {
int x;
X ( int i = 0 )
: x ( i )
{}
operator X & ( void ) const {
return ( *this );
}
};
void add_one ( X & ref ) {
++ ref.x;
}
#include <iostream>
int main ( void ) {
X const a ( 2 );
add_one( a );
std::cout << a.x << '\n';
}
This code is clearly in violation of the standard [9.3.2/2]:
In a const member function, the object for which the function is called is
accessed through a const access path; [...]
However, I wonder whether diagnostics for this violation is required -- on
my machine, the code compiles but the program segfaults and I am
considering submitting a bug report to the compiler vendor.
Can someone give me chapter and verse on this?
Thanks
Kai-Uwe Bux