Add -Wsign-compare for Clang builds and fix some signed/unsigned compiler warnings

This commit is contained in:
kwolekr 2015-05-16 19:59:53 -04:00
parent fb36c471d7
commit 11a96e4901
4 changed files with 31 additions and 30 deletions

View File

@ -590,6 +590,7 @@ else()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# clang does not understand __extern_always_inline but libc headers use it # clang does not understand __extern_always_inline but libc headers use it
set(OTHER_FLAGS "${OTHER_FLAGS} \"-D__extern_always_inline=extern __always_inline\"") set(OTHER_FLAGS "${OTHER_FLAGS} \"-D__extern_always_inline=extern __always_inline\"")
set(OTHER_FLAGS "${OTHER_FLAGS} -Wsign-compare")
endif() endif()
if(MINGW) if(MINGW)

View File

@ -142,12 +142,12 @@ class TestCAO : public ClientActiveObject
public: public:
TestCAO(IGameDef *gamedef, ClientEnvironment *env); TestCAO(IGameDef *gamedef, ClientEnvironment *env);
virtual ~TestCAO(); virtual ~TestCAO();
ActiveObjectType getType() const ActiveObjectType getType() const
{ {
return ACTIVEOBJECT_TYPE_TEST; return ACTIVEOBJECT_TYPE_TEST;
} }
static ClientActiveObject* create(IGameDef *gamedef, ClientEnvironment *env); static ClientActiveObject* create(IGameDef *gamedef, ClientEnvironment *env);
void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc, void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
@ -192,9 +192,9 @@ void TestCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
{ {
if(m_node != NULL) if(m_node != NULL)
return; return;
//video::IVideoDriver* driver = smgr->getVideoDriver(); //video::IVideoDriver* driver = smgr->getVideoDriver();
scene::SMesh *mesh = new scene::SMesh(); scene::SMesh *mesh = new scene::SMesh();
scene::IMeshBuffer *buf = new scene::SMeshBuffer(); scene::IMeshBuffer *buf = new scene::SMeshBuffer();
video::SColor c(255,255,255,255); video::SColor c(255,255,255,255);
@ -286,12 +286,12 @@ class ItemCAO : public ClientActiveObject
public: public:
ItemCAO(IGameDef *gamedef, ClientEnvironment *env); ItemCAO(IGameDef *gamedef, ClientEnvironment *env);
virtual ~ItemCAO(); virtual ~ItemCAO();
ActiveObjectType getType() const ActiveObjectType getType() const
{ {
return ACTIVEOBJECT_TYPE_ITEM; return ACTIVEOBJECT_TYPE_ITEM;
} }
static ClientActiveObject* create(IGameDef *gamedef, ClientEnvironment *env); static ClientActiveObject* create(IGameDef *gamedef, ClientEnvironment *env);
void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc, void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
@ -308,12 +308,12 @@ public:
void processMessage(const std::string &data); void processMessage(const std::string &data);
void initialize(const std::string &data); void initialize(const std::string &data);
core::aabbox3d<f32>* getSelectionBox() core::aabbox3d<f32>* getSelectionBox()
{return &m_selection_box;} {return &m_selection_box;}
v3f getPosition() v3f getPosition()
{return m_position;} {return m_position;}
std::string infoText() std::string infoText()
{return m_infotext;} {return m_infotext;}
@ -357,9 +357,9 @@ void ItemCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
{ {
if(m_node != NULL) if(m_node != NULL)
return; return;
//video::IVideoDriver* driver = smgr->getVideoDriver(); //video::IVideoDriver* driver = smgr->getVideoDriver();
scene::SMesh *mesh = new scene::SMesh(); scene::SMesh *mesh = new scene::SMesh();
scene::IMeshBuffer *buf = new scene::SMeshBuffer(); scene::IMeshBuffer *buf = new scene::SMeshBuffer();
video::SColor c(255,255,255,255); video::SColor c(255,255,255,255);
@ -469,7 +469,7 @@ void ItemCAO::updateTexture()
<<": error deSerializing itemstring \"" <<": error deSerializing itemstring \""
<<m_itemstring<<std::endl; <<m_itemstring<<std::endl;
} }
// Set meshbuffer texture // Set meshbuffer texture
m_node->getMaterial(0).setTexture(0, texture); m_node->getMaterial(0).setTexture(0, texture);
} }
@ -514,7 +514,7 @@ void ItemCAO::processMessage(const std::string &data)
void ItemCAO::initialize(const std::string &data) void ItemCAO::initialize(const std::string &data)
{ {
infostream<<"ItemCAO: Got init data"<<std::endl; infostream<<"ItemCAO: Got init data"<<std::endl;
{ {
std::istringstream is(data, std::ios::binary); std::istringstream is(data, std::ios::binary);
// version // version
@ -527,7 +527,7 @@ void ItemCAO::initialize(const std::string &data)
// itemstring // itemstring
m_itemstring = deSerializeString(is); m_itemstring = deSerializeString(is);
} }
updateNodePos(); updateNodePos();
updateInfoText(); updateInfoText();
} }
@ -748,7 +748,7 @@ ClientActiveObject* GenericCAO::getParent()
void GenericCAO::removeFromScene(bool permanent) void GenericCAO::removeFromScene(bool permanent)
{ {
// Should be true when removing the object permanently and false when refreshing (eg: updating visuals) // Should be true when removing the object permanently and false when refreshing (eg: updating visuals)
if((m_env != NULL) && (permanent)) if((m_env != NULL) && (permanent))
{ {
for(std::vector<u16>::iterator ci = m_children.begin(); for(std::vector<u16>::iterator ci = m_children.begin();
ci != m_children.end(); ci++) ci != m_children.end(); ci++)
@ -759,7 +759,7 @@ void GenericCAO::removeFromScene(bool permanent)
} }
m_env->m_attachements[getId()] = 0; m_env->m_attachements[getId()] = 0;
LocalPlayer* player = m_env->getLocalPlayer(); LocalPlayer* player = m_env->getLocalPlayer();
if (this == player->parent) { if (this == player->parent) {
player->parent = NULL; player->parent = NULL;
@ -898,7 +898,7 @@ void GenericCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
m_meshnode = smgr->addMeshSceneNode(mesh, NULL); m_meshnode = smgr->addMeshSceneNode(mesh, NULL);
m_meshnode->grab(); m_meshnode->grab();
mesh->drop(); mesh->drop();
m_meshnode->setScale(v3f(m_prop.visual_size.X, m_meshnode->setScale(v3f(m_prop.visual_size.X,
m_prop.visual_size.Y, m_prop.visual_size.Y,
m_prop.visual_size.X)); m_prop.visual_size.X));
@ -1014,7 +1014,7 @@ void GenericCAO::updateNodePos()
} }
} }
} }
void GenericCAO::step(float dtime, ClientEnvironment *env) void GenericCAO::step(float dtime, ClientEnvironment *env)
{ {
// Handel model of local player instantly to prevent lags // Handel model of local player instantly to prevent lags
@ -1485,7 +1485,7 @@ void GenericCAO::updateBonePosition()
} }
} }
} }
void GenericCAO::updateAttachments() void GenericCAO::updateAttachments()
{ {
@ -1716,14 +1716,14 @@ void GenericCAO::processMessage(const std::string &data)
m_armor_groups[name] = rating; m_armor_groups[name] = rating;
} }
} else if (cmd == GENERIC_CMD_UPDATE_NAMETAG_ATTRIBUTES) { } else if (cmd == GENERIC_CMD_UPDATE_NAMETAG_ATTRIBUTES) {
u8 version = readU8(is); // forward compatibility //u8 version = readU8(is); // forward compatibility
m_nametag_color = readARGB8(is); m_nametag_color = readARGB8(is);
if (m_textnode != NULL) { if (m_textnode != NULL) {
m_textnode->setTextColor(m_nametag_color); m_textnode->setTextColor(m_nametag_color);
} }
} }
} }
/* \pre punchitem != NULL /* \pre punchitem != NULL
*/ */
bool GenericCAO::directReportPunch(v3f dir, const ItemStack *punchitem, bool GenericCAO::directReportPunch(v3f dir, const ItemStack *punchitem,

View File

@ -590,8 +590,8 @@ void Noise::gradientMap2D(
int seed) int seed)
{ {
float v00, v01, v10, v11, u, v, orig_u; float v00, v01, v10, v11, u, v, orig_u;
int index, i, j, x0, y0, noisex, noisey; u32 index, i, j, x0, y0, noisex, noisey;
int nlx, nly; u32 nlx, nly;
bool eased = np.flags & (NOISE_FLAG_DEFAULTS | NOISE_FLAG_EASED); bool eased = np.flags & (NOISE_FLAG_DEFAULTS | NOISE_FLAG_EASED);
Interp2dFxn interpolate = eased ? Interp2dFxn interpolate = eased ?
@ -604,8 +604,8 @@ void Noise::gradientMap2D(
orig_u = u; orig_u = u;
//calculate noise point lattice //calculate noise point lattice
nlx = (int)(u + sx * step_x) + 2; nlx = (u32)(u + sx * step_x) + 2;
nly = (int)(v + sy * step_y) + 2; nly = (u32)(v + sy * step_y) + 2;
index = 0; index = 0;
for (j = 0; j != nly; j++) for (j = 0; j != nly; j++)
for (i = 0; i != nlx; i++) for (i = 0; i != nlx; i++)
@ -655,8 +655,8 @@ void Noise::gradientMap3D(
float v000, v010, v100, v110; float v000, v010, v100, v110;
float v001, v011, v101, v111; float v001, v011, v101, v111;
float u, v, w, orig_u, orig_v; float u, v, w, orig_u, orig_v;
int index, i, j, k, x0, y0, z0, noisex, noisey, noisez; u32 index, i, j, k, x0, y0, z0, noisex, noisey, noisez;
int nlx, nly, nlz; u32 nlx, nly, nlz;
Interp3dFxn interpolate = (np.flags & NOISE_FLAG_EASED) ? Interp3dFxn interpolate = (np.flags & NOISE_FLAG_EASED) ?
triLinearInterpolation : triLinearInterpolationNoEase; triLinearInterpolation : triLinearInterpolationNoEase;
@ -671,9 +671,9 @@ void Noise::gradientMap3D(
orig_v = v; orig_v = v;
//calculate noise point lattice //calculate noise point lattice
nlx = (int)(u + sx * step_x) + 2; nlx = (u32)(u + sx * step_x) + 2;
nly = (int)(v + sy * step_y) + 2; nly = (u32)(v + sy * step_y) + 2;
nlz = (int)(w + sz * step_z) + 2; nlz = (u32)(w + sz * step_z) + 2;
index = 0; index = 0;
for (k = 0; k != nlz; k++) for (k = 0; k != nlz; k++)
for (j = 0; j != nly; j++) for (j = 0; j != nly; j++)

View File

@ -99,7 +99,7 @@ void TestSchematic::testMtsSerializeDeserialize(INodeDefManager *ndef)
UASSERT(schem2.size == size); UASSERT(schem2.size == size);
for (size_t i = 0; i != volume; i++) for (size_t i = 0; i != volume; i++)
UASSERT(schem2.schemdata[i] == schem.schemdata[i]); UASSERT(schem2.schemdata[i] == schem.schemdata[i]);
for (size_t y = 0; y != size.Y; y++) for (s16 y = 0; y != size.Y; y++)
UASSERTEQ(u8, schem2.slice_probs[y], schem.slice_probs[y]); UASSERTEQ(u8, schem2.slice_probs[y], schem.slice_probs[y]);
} }