Enable -Wcast-qual when compiling the valgrind source.
Testcases are not compiled with -Wcast-qual.
Introduce CONST_CAST macro to work around in the few spots
where a cast that drops type qualifiers is needed.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14652 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/configure.ac b/configure.ac
index 710accf..4b3edd0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1735,6 +1735,30 @@
 ])
 CFLAGS=$safe_CFLAGS
 
+# does this compiler support -Wcast-qual ?
+AC_MSG_CHECKING([if gcc accepts -Wcast-qual])
+
+safe_CFLAGS=$CFLAGS
+CFLAGS="-Wcast-qual"
+
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
+  return 0;
+]])], [
+cast_qual=yes
+AC_MSG_RESULT([yes])
+], [
+cast_qual=no
+AC_MSG_RESULT([no])
+])
+CFLAGS=$safe_CFLAGS
+
+AM_CONDITIONAL(HAS_CAST_QUAL_WARNING, test x$cast_qual = xyes)
+
+if test x$cast_qual = xyes; then
+  CFLAGS="$CFLAGS -Wcast-qual"
+  CXXFLAGS="$CXXFLAGS -Wcast-qual"
+fi
+
 
 # does this compiler support -fno-stack-protector ?
 AC_MSG_CHECKING([if gcc accepts -fno-stack-protector])