Commit 8ee0d83b2725a46ccf3badd51bbdef8a640a70da

Frank Heckenbach 2019-02-07T22:31:57

fix (if possible) or silence (otherwise) compiler warnings

diff --git a/ChangeLog b/ChangeLog
index ac154f7..cb0aade 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2019-02-07 22:31  Frank Heckenbach <f.heckenbach@fh-soft.de>
+
+  * configure.ac: remove -Waggregate-return (returning aggregates is
+    usual in C++)
+
+  * src/FTCharToGlyphIndexMap.h, src/FTContour.cpp,
+    src/FTGL/FTLibrary.h, src/FTGlyph/FTBufferGlyph.cpp,
+    src/FTGlyph/FTExtrudeGlyph.cpp, src/FTGlyph/FTPixmapGlyph.cpp,
+    src/FTGlyph/FTTextureGlyph.cpp, src/FTGlyphContainer.cpp,
+    src/FTGlyphContainer.h, src/FTInternals.h,
+    src/FTLayout/FTSimpleLayout.cpp, src/FTPoint.cpp,
+    src/FTVectoriser.cpp, demo/FTGLDemo.cpp, demo/FTGLMFontDemo.cpp,
+    demo/c-demo.c, demo/simple.cpp, demo/trackball.c:
+    fix (if possible) or silence (otherwise) compiler warnings
+
 2019-02-07 21:05  Frank Heckenbach <f.heckenbach@fh-soft.de>
 
   * src/FTGL/FTLibrary.h, src/FTLibrary.cpp:
diff --git a/configure.ac b/configure.ac
index a901f9d..3a0ff01 100644
--- a/configure.ac
+++ b/configure.ac
@@ -73,7 +73,7 @@ dnl may conflict.
 CPPFLAGS="$CPPFLAGS -I\${top_srcdir}/src"
 
 # Warning flags
-BC_COMPILER_AND_LINKER_RECOGNIZES([-W -Wall -Wundef -Wfloat-equal  -Wpointer-arith -Wcast-align -Wcast-qual -Wshadow -Wsign-compare -Winline -Waggregate-return], [warning])
+BC_COMPILER_AND_LINKER_RECOGNIZES([-W -Wall -Wundef -Wfloat-equal  -Wpointer-arith -Wcast-align -Wcast-qual -Wshadow -Wsign-compare -Winline], [warning])
 BC_COMPILER_AND_LINKER_RECOGNIZES([-Wstrict-prototypes -Wmissing-prototypes -Wnested-externs], [warncflags], [no])
 if test "x$bc_warncflags_works" = "xyes" ; then
     CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs"
diff --git a/demo/FTGLDemo.cpp b/demo/FTGLDemo.cpp
index a84cd2c..01f9049 100644
--- a/demo/FTGLDemo.cpp
+++ b/demo/FTGLDemo.cpp
@@ -229,7 +229,11 @@ void renderFontmetrics()
         glVertex3f(x2, y1, z1);
     glEnd();
     // Draw the back face
-    if(current_font == FTGL_EXTRUDE && z1 != z2)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wfloat-equal"
+    bool zd = z1 != z2;
+#pragma GCC diagnostic pop
+    if(current_font == FTGL_EXTRUDE && zd)
     {
         glBegin(GL_LINE_LOOP);
             glVertex3f(x1, y1, z2);
@@ -524,7 +528,7 @@ void myinit(const char* file)
 }
 
 
-void parsekey(unsigned char key, int x, int y)
+void parsekey(unsigned char key, int, int)
 {
     switch (key)
     {
@@ -585,7 +589,7 @@ void parsekey(unsigned char key, int x, int y)
 }
 
 
-void parseSpecialKey(int key, int x, int y)
+void parseSpecialKey(int key, int, int)
 {
     FTSimpleLayout *l = NULL;
     unsigned int s;
diff --git a/demo/FTGLMFontDemo.cpp b/demo/FTGLMFontDemo.cpp
index cead3f2..196b54c 100644
--- a/demo/FTGLMFontDemo.cpp
+++ b/demo/FTGLMFontDemo.cpp
@@ -241,7 +241,11 @@ void renderFontmetrics()
         glVertex3f(x2, y1, z1);
     glEnd();
     // Draw the back face
-    if((GetStyle() == FTGL_EXTRUDE) && (z1 != z2))
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wfloat-equal"
+    bool zd = z1 != z2;
+#pragma GCC diagnostic pop
+    if((GetStyle() == FTGL_EXTRUDE) && zd)
     {
         glBegin(GL_LINE_LOOP);
             glVertex3f(x1, y1, z2);
@@ -480,7 +484,7 @@ void myinit(int numFontFiles)
 }
 
 
-void parsekey(unsigned char key, int x, int y)
+void parsekey(unsigned char key, int, int)
 {
     switch (key)
     {
@@ -541,7 +545,7 @@ void parsekey(unsigned char key, int x, int y)
 }
 
 
-void parseSpecialKey(int key, int x, int y)
+void parseSpecialKey(int key, int, int)
 {
     FTSimpleLayout *l = NULL;
 	unsigned int s;
diff --git a/demo/c-demo.c b/demo/c-demo.c
index 79028f8..f577fb3 100644
--- a/demo/c-demo.c
+++ b/demo/c-demo.c
@@ -88,6 +88,7 @@ static void DestroyHalo(FTGLglyph * baseGlyph, void *data)
 
 static FTGLglyph *MakeHaloGlyph(FT_GlyphSlot slot, void *data)
 {
+    (void) data;
     struct HaloGlyph *p = malloc(sizeof(struct HaloGlyph));
     FTGLglyph *baseGlyph = ftglCreatePolygonGlyph(slot, 0.0f, 1.0f);
     int i;
@@ -169,6 +170,8 @@ static void RenderScene(void)
  */
 static void ProcessKeys(unsigned char key, int x, int y)
 {
+    (void) x;
+    (void) y;
     switch(key)
     {
     case 27:
diff --git a/demo/simple.cpp b/demo/simple.cpp
index c9b2db2..7f7f63b 100644
--- a/demo/simple.cpp
+++ b/demo/simple.cpp
@@ -105,9 +105,9 @@ static void RenderScene(void)
     float t2 = sin(n / 50 + 1);
     float t3 = sin(n / 30 + 2);
 
-    float ambient[4]  = { (t1 + 2.0) / 3,
-                          (t2 + 2.0) / 3,
-                          (t3 + 2.0) / 3, 0.3 };
+    float ambient[4]  = { (t1 + 2.0f) / 3,
+                          (t2 + 2.0f) / 3,
+                          (t3 + 2.0f) / 3, 0.3 };
     float diffuse[4]  = { 1.0, 0.9, 0.9, 1.0 };
     float specular[4] = { 1.0, 0.7, 0.7, 1.0 };
     float position[4] = { 100.0, 100.0, 0.0, 1.0 };
@@ -159,7 +159,7 @@ static void RenderScene(void)
 //
 //  GLUT key processing function: <esc> quits, <tab> cycles across fonts.
 //
-static void ProcessKeys(unsigned char key, int x, int y)
+static void ProcessKeys(unsigned char key, int, int)
 {
     switch(key)
     {
diff --git a/demo/trackball.c b/demo/trackball.c
index 37d7f86..8c9bd57 100644
--- a/demo/trackball.c
+++ b/demo/trackball.c
@@ -167,12 +167,15 @@ trackball(float q[4], float p1x, float p1y, float p2x, float p2y)
     float p1[3], p2[3], d[3];
     float t;
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wfloat-equal"
     if (p1x == p2x && p1y == p2y) {
         /* Zero rotation */
         vzero(q);
         q[3] = 1.0;
         return;
     }
+#pragma GCC diagnostic pop
 
     /*
      * First, figure out z-coordinates for projection of P1 and P2 to
diff --git a/src/FTCharToGlyphIndexMap.h b/src/FTCharToGlyphIndexMap.h
index 5e7d4e0..6fdcd56 100644
--- a/src/FTCharToGlyphIndexMap.h
+++ b/src/FTCharToGlyphIndexMap.h
@@ -90,7 +90,7 @@ class FTCharToGlyphIndexMap
             Indices = 0;
         }
 
-        const GlyphIndex find(CharacterCode c)
+        GlyphIndex find(CharacterCode c)
         {
             int OuterIdx = (c >> (BucketIdxBits * 2)) & BucketIdxMask;
             int InnerIdx = (c >> BucketIdxBits) & BucketIdxMask;
diff --git a/src/FTContour.cpp b/src/FTContour.cpp
index 931ca76..c668d32 100644
--- a/src/FTContour.cpp
+++ b/src/FTContour.cpp
@@ -177,7 +177,6 @@ void FTContour::SetParity(int parity)
 FTContour::FTContour(FT_Vector* contour, char* tags, unsigned int n)
 {
     FTPoint prev, cur(contour[(n - 1) % n]), next(contour[0]);
-    FTPoint a, b = next - cur;
     double olddir, dir = atan2((next - cur).Y(), (next - cur).X());
     double angle = 0.0;
 
diff --git a/src/FTGL/FTLibrary.h b/src/FTGL/FTLibrary.h
index d6641b2..5581494 100644
--- a/src/FTGL/FTLibrary.h
+++ b/src/FTGL/FTLibrary.h
@@ -68,7 +68,7 @@ class FTLibrary
          *
          * @return A handle to a FreeType library instance.
          */
-        const FT_Library* const GetLibrary() const { return library; }
+        const FT_Library* GetLibrary() const { return library; }
 
         /**
          * Queries the library for errors.
diff --git a/src/FTGlyph/FTBufferGlyph.cpp b/src/FTGlyph/FTBufferGlyph.cpp
index d85146f..5267afb 100644
--- a/src/FTGlyph/FTBufferGlyph.cpp
+++ b/src/FTGlyph/FTBufferGlyph.cpp
@@ -99,14 +99,14 @@ const FTPoint& FTBufferGlyphImpl::RenderImpl(const FTPoint& pen, int renderMode)
         int dy = buffer->Height() - (int)(pos.Yf() + 0.5f);
         unsigned char * dest = buffer->Pixels() + dx + dy * buffer->Width();
 
-        for(int y = 0; y < bitmap.rows; y++)
+        for(int y = 0; y < int (bitmap.rows); y++)
         {
             // FIXME: change the loop bounds instead of doing this test
             if(y + dy < 0 || y + dy >= buffer->Height()) continue;
 
             if(bitmap.num_grays == 1)
             {
-                for(int x = 0; x < bitmap.width; x++)
+                for(int x = 0; x < int (bitmap.width); x++)
                 {
                     if(x + dx < 0 || x + dx >= buffer->Width()) continue;
 
@@ -120,7 +120,7 @@ const FTPoint& FTBufferGlyphImpl::RenderImpl(const FTPoint& pen, int renderMode)
             }
             else
             {
-                for(int x = 0; x < bitmap.width; x++)
+                for(int x = 0; x < int (bitmap.width); x++)
                 {
                     if(x + dx < 0 || x + dx >= buffer->Width()) continue;
 
diff --git a/src/FTGlyph/FTExtrudeGlyph.cpp b/src/FTGlyph/FTExtrudeGlyph.cpp
index ff068a2..d25592b 100644
--- a/src/FTGlyph/FTExtrudeGlyph.cpp
+++ b/src/FTGlyph/FTExtrudeGlyph.cpp
@@ -202,8 +202,6 @@ void FTExtrudeGlyphImpl::RenderBack()
         glBegin(polygonType);
             for(unsigned int i = 0; i < subMesh->PointCount(); ++i)
             {
-                FTPoint pt = subMesh->Point(i);
-
                 glTexCoord2f(subMesh->Point(i).Xf() / hscale,
                              subMesh->Point(i).Yf() / vscale);
 
diff --git a/src/FTGlyph/FTPixmapGlyph.cpp b/src/FTGlyph/FTPixmapGlyph.cpp
index fee383c..e087af0 100644
--- a/src/FTGlyph/FTPixmapGlyph.cpp
+++ b/src/FTGlyph/FTPixmapGlyph.cpp
@@ -148,7 +148,7 @@ FTPixmapGlyphImpl::~FTPixmapGlyphImpl()
 
 
 const FTPoint& FTPixmapGlyphImpl::RenderImpl(const FTPoint& pen,
-                                             int renderMode)
+                                             int /*renderMode*/)
 {
     if(data)
     {
diff --git a/src/FTGlyph/FTTextureGlyph.cpp b/src/FTGlyph/FTTextureGlyph.cpp
index 64b28e7..8644d19 100644
--- a/src/FTGlyph/FTTextureGlyph.cpp
+++ b/src/FTGlyph/FTTextureGlyph.cpp
@@ -145,7 +145,7 @@ FTTextureGlyphImpl::FTTextureGlyphImpl(FT_GlyphSlot glyph, int id, int xOffset,
                     unsigned char* src = bitmap.pitch < 0
                       ? bitmap.buffer + (y - destHeight + 1) * bitmap.pitch
                       : bitmap.buffer + y * bitmap.pitch;
-                    unsigned char c;
+                    unsigned char c = 0;
                     for(int x = 0; x < destWidth; ++x)
                     {
                         if (x % 8 == 0)
@@ -186,7 +186,7 @@ FTTextureGlyphImpl::~FTTextureGlyphImpl()
 
 
 const FTPoint& FTTextureGlyphImpl::RenderImpl(const FTPoint& pen,
-                                              int renderMode)
+                                              int /*renderMode*/)
 {
     float dx, dy;
 
diff --git a/src/FTGlyphContainer.cpp b/src/FTGlyphContainer.cpp
index 8ca36c9..6a47291 100644
--- a/src/FTGlyphContainer.cpp
+++ b/src/FTGlyphContainer.cpp
@@ -76,7 +76,7 @@ void FTGlyphContainer::Add(FTGlyph* tempGlyph, const unsigned int charCode)
 }
 
 
-const FTGlyph* const FTGlyphContainer::Glyph(const unsigned int charCode) const
+const FTGlyph* FTGlyphContainer::Glyph(const unsigned int charCode) const
 {
     unsigned int index = charMap->GlyphListIndex(charCode);
 
diff --git a/src/FTGlyphContainer.h b/src/FTGlyphContainer.h
index d4bbb74..6833643 100644
--- a/src/FTGlyphContainer.h
+++ b/src/FTGlyphContainer.h
@@ -92,7 +92,7 @@ class FTGlyphContainer
          * @return              An FTGlyph or <code>null</code> is it hasn't been
          * loaded.
          */
-        const FTGlyph* const Glyph(const unsigned int characterCode) const;
+        const FTGlyph* Glyph(const unsigned int characterCode) const;
 
         /**
          * Get the bounding box for a character.
diff --git a/src/FTInternals.h b/src/FTInternals.h
index 65424a3..50d102e 100644
--- a/src/FTInternals.h
+++ b/src/FTInternals.h
@@ -68,7 +68,7 @@
     #ifndef __gl_h_
         #ifdef SDL_main
             #include "SDL_opengl.h"
-        #elif __APPLE_CC__
+        #elif defined(__APPLE_CC__)
             #include <OpenGL/gl.h>
             #include <OpenGL/glu.h>
         #else
diff --git a/src/FTLayout/FTSimpleLayout.cpp b/src/FTLayout/FTSimpleLayout.cpp
index d1a8e55..d91622e 100644
--- a/src/FTLayout/FTSimpleLayout.cpp
+++ b/src/FTLayout/FTSimpleLayout.cpp
@@ -191,7 +191,7 @@ void FTSimpleLayoutImpl::Render(const wchar_t* string, const int len,
 
 
 template <typename T>
-inline void FTSimpleLayoutImpl::WrapTextI(const T *buf, const int len,
+inline void FTSimpleLayoutImpl::WrapTextI(const T *buf, const int /*len*/,
                                           FTPoint position, int renderMode,
                                           FTBBox *bounds)
 {
diff --git a/src/FTPoint.cpp b/src/FTPoint.cpp
index 243df3e..51bf060 100644
--- a/src/FTPoint.cpp
+++ b/src/FTPoint.cpp
@@ -30,6 +30,9 @@
 
 #include "FTGL/ftgl.h"
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wfloat-equal"
+
 bool operator == (const FTPoint &a, const FTPoint &b)
 {
     return((a.values[0] == b.values[0]) && (a.values[1] == b.values[1]) && (a.values[2] == b.values[2]));
@@ -41,13 +44,14 @@ bool operator != (const FTPoint &a, const FTPoint &b)
     return((a.values[0] != b.values[0]) || (a.values[1] != b.values[1]) || (a.values[2] != b.values[2]));
 }
 
+#pragma GCC diagnostic pop
 
 FTPoint FTPoint::Normalise()
 {
     double norm = sqrt(values[0] * values[0]
                        + values[1] * values[1]
                        + values[2] * values[2]);
-    if(norm == 0.0)
+    if(norm <= 0.0)
     {
         return *this;
     }
diff --git a/src/FTVectoriser.cpp b/src/FTVectoriser.cpp
index ca7417f..26e7da8 100644
--- a/src/FTVectoriser.cpp
+++ b/src/FTVectoriser.cpp
@@ -318,7 +318,8 @@ void FTVectoriser::MakeMesh(FTGL_DOUBLE zNormal, int outsetType, float outsetSiz
                     // XXX: gluTessVertex doesn't modify the data but does not
                     // specify "const" in its prototype, so we cannot cast to
                     // a const type.
-                    gluTessVertex(tobj, const_cast<GLdouble*>(d), (GLvoid *)d);
+                    GLdouble* dd = const_cast<GLdouble*>(d);
+                    gluTessVertex(tobj, dd, static_cast<GLvoid*>(dd));
                 }
 
             gluTessEndContour(tobj);