(svn r16422) -Codechange: use const_cast for removing const and warn when const is (accidentally?) removed using C-style casts.

This commit is contained in:
rubidium 2009-05-24 21:09:00 +00:00
parent 0d99b6c71c
commit 168ae6f7e2
12 changed files with 18 additions and 20 deletions

View File

@ -1103,7 +1103,7 @@ make_cflags_and_ldflags() {
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

View File

@ -440,7 +440,7 @@ bool SQVM::DerefInc(SQInteger op,SQObjectPtr &target, SQObjectPtr &self, SQObjec
#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))

View File

@ -807,7 +807,7 @@ void ChangeWorkingDirectory(const char *exe)
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__)

View File

@ -340,7 +340,7 @@ static int TruncateString(char *str, int maxw)
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 @@ uint32 FormatStringLinebreaks(char *str, int maxw)
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;

View File

@ -954,7 +954,7 @@ public:
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 */

View File

@ -82,7 +82,7 @@ public:
{
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 @@ public:
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);}
};

View File

@ -1793,7 +1793,7 @@ void NetworkServerBanIP(const char *banip)
/* 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);
}
}

View File

@ -1158,11 +1158,9 @@ static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, byte
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 @@ static void NewSpriteGroup(byte *buf, size_t len)
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 @@ static void NewSpriteGroup(byte *buf, size_t len)
}
/* 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;
}

View File

@ -416,7 +416,7 @@ static void VehicleSetTriggers(const ResolverObject *object, int triggers)
* 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. */

View File

@ -335,7 +335,7 @@ static uint32 StationGetTriggers(const ResolverObject *object)
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;
}

View File

@ -1396,7 +1396,7 @@ static SpriteID GetEngineColourMap(EngineID engine_type, CompanyID company, Engi
* 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 @@ static SpriteID GetEngineColourMap(EngineID engine_type, CompanyID company, Engi
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;
}

View File

@ -144,7 +144,7 @@ static RefitList *BuildRefitList(const Vehicle *v)
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;