Is the handling of constness in fa being turned inside out intentional, or does it look like a bug (compiler or the standard)? I can see how this can happen, but it still feels pretty weird (at the very least I would expect a = "qwe" to be treated as an error, too---like in fs).
typedef char A[8];
typedef char *P;
typedef std::string S;
void fa( const A a ) {
a = "qwe"; // ok
// *a = 'Q'; // error
}
void fp( const P p ) {
// p = "qwe"; // error
*p = 'Q'; // ok
}
void fs( const S s ) {
// s = "qwe"; // error
// *s = 'Q'; // error
}
[MinGW 4.9.1]
CLARIFICATION: I understand the general way this conversion works, hence the "I can see how this can happen" part. What this question is about, is (a) std references (thanks to those who provided them), and (b) if there is an actual rationale for this quirk (which is pretty counter-intuitive).
const, in this case, is to indicate that the value is to be "passed by-reference," instead of a literal value being placed on the stack. However, I agree that the behavior you've described is "counter-intuitive to the point of being 'wrong.'" (Most likely, it's an artifact made pragmatically necessary by what people have actually been doing with C++, and with C in decades before it.)