Implement -Wcast-qual, fixing #13772.

Many thanks to dblaikie for his advices and suggestions!