Ian Lance Taylor wrote: > Consider this C/C++ program: > > extern void **f1(); > void f2(const char *p) { *(const void **)f1() = p; } > > If I compile this program with g++ -Wcast-qual, I get this: > > foo2.cc:2: warning: cast from type ‘void**’ to type ‘const void**’ casts away > qualifiers > > If I compile this program with gcc -Wcast-qual, I do not get any > warning.
> 2) Change the C frontend to also warn about this case, albeit with a > better message. > Of course in all cases the frontends should continue to warn about a > cast from const void** to void**. Well, they should warn about this case also then. extern void **f1(); void f2(const char *p) { *(const void **)f1() = p; } void *x; void **f1() { return &x } void f2(char *foo, int n) { memcpy (x, foo, n); // BOOM! } This looks like a disguised way of casting a const char* to a (non-const) void* to me, isn't it? Sure, the warning is being tripped by the cast rather than the conversion that the cast is hiding, it needs to be improved, but I'm glad we got at least some noise from such a dubious construction. cheers, DaveK