changeset 12016:d45475f68f60 draft

(svn r16422) -Codechange: use const_cast for removing const and warn when const is (accidentally?) removed using C-style casts.
author rubidium <rubidium@openttd.org>
date Sun, 24 May 2009 21:09:00 +0000
parents f51061a22830
children e2ca508c540e
files config.lib src/3rdparty/squirrel/squirrel/sqvm.cpp src/fileio.cpp src/gfx.cpp src/industry_gui.cpp src/misc/blob.hpp src/network/network_server.cpp src/newgrf.cpp src/newgrf_engine.cpp src/newgrf_station.cpp src/vehicle.cpp src/vehicle_gui.cpp
diffstat 12 files changed, 18 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/config.lib
+++ b/config.lib
@@ -1103,7 +1103,7 @@
 		if [ $cc_version -ge 29 ]; then
 			CFLAGS="$CFLAGS -Wall -Wno-multichar -Wsign-compare -Wundef"
 			CFLAGS="$CFLAGS -Wwrite-strings -Wpointer-arith"
-			CFLAGS="$CFLAGS -Wno-uninitialized"
+			CFLAGS="$CFLAGS -Wno-uninitialized -Wcast-qual"
 
 			CC_CFLAGS="$CC_CFLAGS -Wstrict-prototypes"
 		fi
--- a/src/3rdparty/squirrel/squirrel/sqvm.cpp
+++ b/src/3rdparty/squirrel/squirrel/sqvm.cpp
@@ -440,7 +440,7 @@
 
 #define arg0 (_i_._arg0)
 #define arg1 (_i_._arg1)
-#define sarg1 (*((SQInt32 *)&_i_._arg1))
+#define sarg1 (*(const_cast<SQInt32 *>(&_i_._arg1)))
 #define arg2 (_i_._arg2)
 #define arg3 (_i_._arg3)
 #define sarg3 ((SQInteger)*((signed char *)&_i_._arg3))
--- a/src/fileio.cpp
+++ b/src/fileio.cpp
@@ -807,7 +807,7 @@
 
 	if (app_bundle != NULL) app_bundle[0] = '\0';
 #endif /* WITH_COCOA */
-	char *s = (char*)strrchr(exe, PATHSEPCHAR);
+	char *s = const_cast<char *>(strrchr(exe, PATHSEPCHAR));
 	if (s != NULL) {
 		*s = '\0';
 #if defined(__DJGPP__)
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -340,7 +340,7 @@
 
 	ddd_w = ddd = GetCharacterWidth(size, '.') * 3;
 
-	for (ddd_pos = str; (c = Utf8Consume((const char **)&str)) != '\0'; ) {
+	for (ddd_pos = str; (c = Utf8Consume(const_cast<const char **>(&str))) != '\0'; ) {
 		if (IsPrintable(c)) {
 			w += GetCharacterWidth(size, c);
 
@@ -577,7 +577,7 @@
 		int w = 0;
 
 		for (;;) {
-			WChar c = Utf8Consume((const char **)&str);
+			WChar c = Utf8Consume(const_cast<const char **>(&str));
 			/* whitespace is where we will insert the line-break */
 			if (IsWhitespace(c)) last_space = str;
 
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -954,7 +954,7 @@
 				if (i->produced_cargo[j] == CT_INVALID) continue;
 				SetDParam(p++, i->produced_cargo[j]);
 				SetDParam(p++, i->last_month_production[j]);
-				SetDParam(p++, GetCargoSuffix(j + 3, CST_DIR, (Industry*)i, i->type, indsp));
+				SetDParam(p++, GetCargoSuffix(j + 3, CST_DIR, const_cast<Industry *>(i), i->type, indsp));
 			}
 
 			/* Transported productions */
--- a/src/misc/blob.hpp
+++ b/src/misc/blob.hpp
@@ -82,7 +82,7 @@
 	{
 		assert(pHdr_1 != NULL);
 		ptr_u.m_pHdr_1 = pHdr_1;
-		*(CHdr**)&pHdr_1 = NULL;
+		*const_cast<CHdr**>(&pHdr_1) = NULL;
 	}
 
 	/** destructor */
@@ -330,7 +330,7 @@
 
 	struct OnTransfer {
 		typename Tbase_::CHdr *m_pHdr_1;
-		OnTransfer(const OnTransfer& src) : m_pHdr_1(src.m_pHdr_1) {assert(src.m_pHdr_1 != NULL); *(typename Tbase_::CHdr**)&src.m_pHdr_1 = NULL;}
+		OnTransfer(const OnTransfer& src) : m_pHdr_1(src.m_pHdr_1) {assert(src.m_pHdr_1 != NULL); *const_cast<typename Tbase_::CHdr**>(&src.m_pHdr_1) = NULL;}
 		OnTransfer(CBlobT& src) : m_pHdr_1(src.ptr_u.m_pHdr_1) {src.InitEmpty();}
 		~OnTransfer() {assert(m_pHdr_1 == NULL);}
 	};
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -1793,7 +1793,7 @@
 
 	/* There can be multiple clients with the same IP, kick them all */
 	FOR_ALL_CLIENT_INFOS(ci) {
-		if (ci->client_address.IsInNetmask((char*)banip)) {
+		if (ci->client_address.IsInNetmask(const_cast<char *>(banip))) {
 			NetworkServerKickClient(ci->client_id);
 		}
 	}
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -1158,11 +1158,9 @@
 					MapSpriteMappingRecolour(&dts->ground);
 
 					while (buf < *bufp + len) {
-						DrawTileSeqStruct *dtss;
-
 						/* no relative bounding box support */
-						dts->seq = ReallocT((DrawTileSeqStruct*)dts->seq, ++seq_count);
-						dtss = (DrawTileSeqStruct*) &dts->seq[seq_count - 1];
+						dts->seq = ReallocT(const_cast<DrawTileSeqStruct *>(dts->seq), ++seq_count);
+						DrawTileSeqStruct *dtss = const_cast<DrawTileSeqStruct *>(&dts->seq[seq_count - 1]);
 
 						dtss->delta_x = grf_load_byte(&buf);
 						if ((byte) dtss->delta_x == 0x80) break;
@@ -2907,7 +2905,7 @@
 					group->dts->seq = CallocT<DrawTileSeqStruct>(num_sprites + 1);
 
 					for (i = 0; i < num_sprites; i++) {
-						DrawTileSeqStruct *seq = (DrawTileSeqStruct*)&group->dts->seq[i];
+						DrawTileSeqStruct *seq = const_cast<DrawTileSeqStruct*>(&group->dts->seq[i]);
 
 						seq->image.sprite = grf_load_word(&buf);
 						seq->image.pal    = grf_load_word(&buf);
@@ -2935,7 +2933,7 @@
 					}
 
 					/* Set the terminator value. */
-					((DrawTileSeqStruct*)group->dts->seq)[i].delta_x = (int8)0x80;
+					const_cast<DrawTileSeqStruct *>(group->dts->seq)[i].delta_x = (int8)0x80;
 
 					break;
 				}
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -416,7 +416,7 @@
 	 * innocent looking function pointer cast... Currently I cannot see a
 	 * way of avoiding this without removing consts deep within gui code.
 	 */
-	Vehicle *v = (Vehicle*)GRV(object);
+	Vehicle *v = const_cast<Vehicle *>(GRV(object));
 
 	/* This function must only be called when processing triggers -- any
 	 * other time is an error. */
--- a/src/newgrf_station.cpp
+++ b/src/newgrf_station.cpp
@@ -335,7 +335,7 @@
 
 static void StationSetTriggers(const ResolverObject *object, int triggers)
 {
-	Station *st = (Station*)object->u.station.st;
+	Station *st = const_cast<Station *>(object->u.station.st);
 	assert(st != NULL);
 	st->waiting_triggers = triggers;
 }
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -1396,7 +1396,7 @@
 			 * map else it's returned as-is. */
 			if (!HasBit(callback, 14)) {
 				/* Update cache */
-				if (v != NULL) ((Vehicle*)v)->colourmap = map;
+				if (v != NULL) const_cast<Vehicle *>(v)->colourmap = map;
 				return map;
 			}
 		}
@@ -1412,7 +1412,7 @@
 	if (twocc) map += livery->colour2 * 16;
 
 	/* Update cache */
-	if (v != NULL) ((Vehicle*)v)->colourmap = map;
+	if (v != NULL) const_cast<Vehicle *>(v)->colourmap = map;
 	return map;
 }
 
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -144,7 +144,7 @@
 	uint max_lines = 256;
 	RefitOption *refit = CallocT<RefitOption>(max_lines);
 	RefitList *list = CallocT<RefitList>(1);
-	Vehicle *u = (Vehicle*)v;
+	Vehicle *u = const_cast<Vehicle *>(v);
 	uint num_lines = 0;
 	uint i;