g_assert_cmpfloat trips -Wdouble-promotion on Clang
@ptomato
Submitted by Philip Chimento Link to original bug (#795992)
Description
Using g_assert_cmpfloat() with a float or double produces warnings on the newest Clang version in macOS, because it internally promotes everything to a long double.
Test program:
/* clang -o bug bug.c `pkg-config --cflags --libs glib-2.0` -Wdouble-promotion */
#include <glib.h>
int
main(void) {
double val = 0.1;
g_assert_cmpfloat(val, ==, 0.1);
return 0;
}
Output:
bug.c:8:21: warning: implicit conversion increases floating-point precision:
'double' to 'long double' [-Wdouble-promotion]
g_assert_cmpfloat(val, ==, 0.1);
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
/Users/ptomato/jhbuild/install/include/glib-2.0/glib/gtestutils.h:67:66: note:
expanded from macro 'g_assert_cmpfloat'
long double __n1 = (n1), __...
~~~~ ^~
bug.c:8:30: warning: implicit conversion increases floating-point precision:
'double' to 'long double' [-Wdouble-promotion]
g_assert_cmpfloat(val, ==, 0.1);
~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
/Users/ptomato/jhbuild/install/include/glib-2.0/glib/gtestutils.h:67:79: note:
expanded from macro 'g_assert_cmpfloat'
...long double __n1 = (n1), __n2 = (n2); \
~~~~ ^~
2 warnings generated.
Compiler version: Apple LLVM version 9.1.0 (clang-902.0.39.1)