int main()
{
const char c = ‘c’;
char* pc;
char** ppc = &pc;
const char** pcc = ppc; // Error: T3 is not the same as cv-unqualified T2, no implicit conversion.
*pcc = &c;
*pc = ‘C’; // If the erroneous assignment above is allowed, the const object “c” may be modified.
}
C when I cast a
char * *
to achar * * const
: okC when I cast a
char * *
to achar * const *
: okC when I cast a
char * *
to achar const * *
: WTFC when I cast a
char * *
to achar const * const *
: okPlease stop, I have CPTSD.
In the WTF case, the reason is because this would allow modification of the const, so it is not allowed.
From https://en.cppreference.com/w/cpp/language/implicit_conversion