#include <math.h>
int isnan_wrapper(double value)
{
return isnan(value);
}
Compiling this snippet with:
g++ -Wconversion -c snippet.cpp
gives following error:
snippet.cpp: In function 'int isnan_wrapper(double)':
snippet.cpp:5:10: warning: conversion to 'float' from 'double' may alter its value [-Wfloat-conversion]
return isnan(value);
^
snippet.cpp:5:10: warning: conversion to 'int' from 'double' may alter its value [-Wfloat-conversion]
I would expect this to compile without any warning or error.
Described behaviour can be reproduced with mingw-w64 from msys2. This error was originally discovered here.
g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=C:/Coding/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4
.9.2/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-4.9.2/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --with-gxx-include-dir=/mingw64/include/c++/4.9.2 --enable-bootstrap --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,objc,obj-c++,fortran,ada --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-cloog-backend=isl --enable-version-specific-runtime-libs --disable-cloog-version-check --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-cloog=/mingw64 --with-pkgversion='Rev5, Built by MSYS2 project' --with-bugurl=http://sourceforge.net/projects/msys2 --with-gnu-as --with-gnu-ld
Thread model: posix
gcc version 4.9.2 (Rev5, Built by MSYS2 project)
Hit same issue trying to build code (in same source as origional reporter - CppUTest) that builds fine under cygwin 2.3.1 GCC
It compiles fine with GCC 6.1.0.
Can corfirm it’s working with GCC 6.1.0 from msys2.
This bug can be closed.
Last edit: lolwat 2016-07-24
Hello,
I am experiencing this bug in mingw 7.3.0 64-bit too.
Hi I still see this issue today when using -Wconversion with mingw gcc v14.1
It looks like mingw is not choosing the correct __isnan from math.h
Hello, I have looked at this problem and mingw-w64 math.h header file is choosing the correct
__isnanfunction. The problem is in how gcc throws-Wconversionwarnings for__builtin_choose_exprusage.isnanin math is defined as:and
__mingw_choose_exprin C mode is__builtin_choose_expr.gcc
-Wconversionduring compilation see that there is some possible__isnanf(x)call forxofdouble valueand it triggers warning. It is even for the case which is not evaluated. The final compiled version does not contain any__isnanfusage asdouble valuedoes not matchfloattype.So you can safely ignores this
-Wconversionwarning, it is false-positive here.One of the option how to change
isnanmacro to avoid this false-positive warning can be to postpone function call after evaluating the macro itself. To completely avoid parser to see__isnanf(x)call. For example as:You can look into objdump to check that the correct function is called.
The example how to avoid that false-positive warning in previous post does not work in C++ mode, because
__mingw_choose_expris C++ is ternary operator.Possible fix which can work in both C and C++ mode to avoid that false-positive warning can be:
It explicitly cast x-argument to the called function type. And also it changes finalizer from
(__builtin_trap(),x)to(__builtin_trap(),(int)0)which mute the second false-positive warningconversion from ‘double’ to ‘int’ may change value. It is caused by the fact that isnan's return value isint, but type of(__builtin_trap(),x)expression isdouble.(int)0in this case is always of type int.Amazing work, thanks Pali. Will you add your fix in a future version?
Now the fix is in master branch in commit d60139
Please check if it works for you.
Hi Pali, I am just working with released versions of the mingw so to try the change I just copied your fix into math.h in v12.0.0 installed by msys2.
This worked for me just fine and resolved the problem. Thanks very much.
Do you expect the change to be included in the next release?