I have the following code that does not compile with gcc 10.2.1 :
struct Bar {
unsigned char *m_a;
unsigned char m_b[1];
};
int main()
{
Bar bar;
const Bar &b = bar;
void *p1 = b.m_a; // Ok
void *p2 = b.m_b; // Error
return 0;
}
The compiler error is :
error: invalid conversion from ‘const void*’ to ‘void*’ [-fpermissive]
I can fix this by using either void *p2 = (void *)b.m_b;
or void *p2 = const_cast<unsigned char *>(b.m_b);
however, constness of members does not seem to be treated the same by the compiler.
I guess there is an "extra-check" for the array and not with the pointer but why is that ?
Thank you.