------- Comment #4 from bugs at 59A2 dot org 2008-11-17 12:24 ------- There is no way to qualify an array type, but this sort of conversion is very useful. For instance, the optimizer produces better code for
void foo(const double a[], int m, int n) { const double (*b)[n] = (const double(*)[n])a; /* use b[i][j] in inner loops */ } than when `a[i*n+j]' is used (without manually hoisting arithmetic out of inner loops). With -Wcast-qual, a warning is given since the qualifier does not apply to the array type, only the elements. Note that this example is very similar to the example given in http://www.open-std.org/jtc1/sc22/wg14/www/C99RationaleV5.10.pdf page 87 (physical page 94). Clearly the cast above should be possible, although there is no way to express it in a way that is compatible with C99 paragraph 6.7.3.8. I propose that -Wcast-qual promote qualifiers on array elements to the array itself when determining whether a cast discards qualifiers. That is, not warn for casts like the one above. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31887