Enable -Wfloat-conversion on Clang.

This is a high-SNR warning that's enabled by default on MSVC and
it has highlighted some bugs in glhelper.cpp (that are also fixed
in this commit).

Unfortunately GCC does not have an equivalent for that warning,
and -Wconversion is very noisy.
pull/10/head
whitequark 2016-05-18 09:40:50 +00:00
parent 69b8a3b3b3
commit fbc5bfc27f
5 changed files with 14 additions and 11 deletions

View File

@ -55,6 +55,9 @@ endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL GNU OR CMAKE_CXX_COMPILER_ID STREQUAL Clang)
set(WARNING_FLAGS "-Wall -Wextra -Wno-unused-parameter")
if(CMAKE_CXX_COMPILER_ID STREQUAL Clang)
set(WARNING_FLAGS "${WARNING_FLAGS} -Wfloat-conversion")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 ${WARNING_FLAGS}")
endif()

View File

@ -713,7 +713,7 @@ double ssglStrWidth(const std::string &str, double h)
{
LoadVectorFont();
int width = 0;
double width = 0;
for(char32_t codepoint : ReadUTF8(str)) {
width += BuiltinVectorFont.GetGlyph(codepoint).advanceWidth;
}
@ -728,11 +728,11 @@ static Vector PixelAlign(Vector v) {
return v;
}
static int DrawCharacter(const VectorFont::Glyph &glyph, Vector t, Vector o, Vector u, Vector v,
static double DrawCharacter(const VectorFont::Glyph &glyph, Vector t, Vector o, Vector u, Vector v,
double scale, ssglLineFn *fn, void *fndata, bool gridFit) {
int advanceWidth = glyph.advanceWidth;
double advanceWidth = glyph.advanceWidth;
int actualWidth, offsetX;
double actualWidth, offsetX;
if(gridFit) {
o.x += glyph.leftSideBearing;
offsetX = glyph.leftSideBearing;

View File

@ -1294,7 +1294,7 @@ void GraphicsWindow::MouseLeftDoubleClick(double mx, double my) {
hStyle hs = c->disp.style;
if(hs.v == 0) hs.v = Style::CONSTRAINT;
ShowGraphicsEditControl((int)p2.x, (int)p2.y,
ssglStrFontSize(Style::TextHeight(hs)) * scale,
(int)(ssglStrFontSize(Style::TextHeight(hs)) * scale),
editMinWidthChar, editValue);
}
}

View File

@ -637,11 +637,11 @@ protected:
private:
int _w, _h;
void ij_to_xy(int i, int j, int &x, int &y) {
void ij_to_xy(double i, double j, int &x, int &y) {
// Convert to xy (vs. ij) style coordinates,
// with (0, 0) at center
x = i - _w / 2;
y = _h / 2 - j;
x = (int)i - _w / 2;
y = _h / 2 - (int)j;
}
};
@ -1376,7 +1376,7 @@ protected:
}
virtual void on_scrollbar_value_changed() {
SS.TW.ScrollbarEvent(_scrollbar.get_adjustment()->get_value());
SS.TW.ScrollbarEvent((int)_scrollbar.get_adjustment()->get_value());
}
virtual void on_editing_done(Glib::ustring value) {

View File

@ -88,7 +88,7 @@ static Pixmap ReadPNGIntoPixmap(png_struct *png_ptr, png_info *info_ptr) {
Pixmap pixmap = {};
pixmap.width = png_get_image_width(png_ptr, info_ptr);
pixmap.height = png_get_image_height(png_ptr, info_ptr);
pixmap.hasAlpha = png_get_color_type(png_ptr, info_ptr) & PNG_COLOR_MASK_ALPHA;
pixmap.hasAlpha = (png_get_color_type(png_ptr, info_ptr) & PNG_COLOR_MASK_ALPHA) != 0;
size_t stride = pixmap.width * pixmap.GetBytesPerPixel();
if(stride % 4 != 0) stride += 4 - stride % 4;