[gtk-doc/wip/swilmet/scangobj-fix-warnings] scangobj: fix -Wdouble-promotion warnings



commit 56e257d255cf30b0f06ecc879ff19d497f11c6ca
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Dec 18 14:25:12 2019 +0100

    scangobj: fix -Wdouble-promotion warnings
    
    If a project passes the -Wdouble-promotion CFLAG when compiling the
    generated *scan.c file, then it emits some warnings. For example in the
    Devhelp project:
    
    ```
    Building documentation for devhelp-3
    devhelp-3-scan.c: In function ‘describe_double_constant’:
    devhelp-3-scan.c:595:39: warning: implicit conversion from ‘float’ to
    ‘gdouble’ {aka ‘double’} to match other operand of binary expression
    [-Wdouble-promotion]
      595 | #define GTKDOC_COMPARE_FLOAT(x, y) (x <= y && x >= y
          |                                       ^~
    devhelp-3-scan.c:608:12: note: in expansion of macro ‘GTKDOC_COMPARE_FLOAT’
      608 |   else if (GTKDOC_COMPARE_FLOAT (value, G_MAXFLOAT))
          |            ^~~~~~~~~~~~~~~~~~~~
    
    [...]
    ```
    
    An example where the -Wdouble-promotion CFLAG is used is with the
    AX_COMPILER_FLAGS Autotools macro, part of autoconf-archive.
    
    -----
    
    In the diff, the `value` variable is of type gdouble.

 gtkdoc/scangobj.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
---
diff --git a/gtkdoc/scangobj.py b/gtkdoc/scangobj.py
index 683634a..7434ec1 100644
--- a/gtkdoc/scangobj.py
+++ b/gtkdoc/scangobj.py
@@ -611,11 +611,11 @@ describe_double_constant (gdouble value)
     desc = g_strdup ("G_MINDOUBLE");
   else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXDOUBLE))
     desc = g_strdup ("-G_MAXDOUBLE");
-  else if (GTKDOC_COMPARE_FLOAT (value, G_MAXFLOAT))
+  else if (GTKDOC_COMPARE_FLOAT (value, (gdouble)G_MAXFLOAT))
     desc = g_strdup ("G_MAXFLOAT");
-  else if (GTKDOC_COMPARE_FLOAT (value, G_MINFLOAT))
+  else if (GTKDOC_COMPARE_FLOAT (value, (gdouble)G_MINFLOAT))
     desc = g_strdup ("G_MINFLOAT");
-  else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXFLOAT))
+  else if (GTKDOC_COMPARE_FLOAT (value, (gdouble)-G_MAXFLOAT))
     desc = g_strdup ("-G_MAXFLOAT");
   else{
     /* make sure floats are output with a decimal dot irrespective of


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]