microsoft / bond

Bond is a cross-platform framework for working with schematized data. It supports cross-language de/serialization and powerful generic mechanisms for efficiently manipulating data. Bond is broadly used at Microsoft in high scale services.
MIT License
2.61k stars 321 forks source link

C++: GCC: Double/Float comparison warning #1191

Closed sergrak closed 1 year ago

sergrak commented 1 year ago

When using double/float inside structures it's generating bad comparison (operator==) code which triggers gcc warnings

namespace Test

struct A
{
  0: required double fieldA;
  1: required float fieldB;
};

Run as following:

#:/tmp$ gbc c++ -o ./ ./test.idl
#:/tmp$ g++ -Wfloat-equal -c ./test_types.cpp
In file included from ./test_reflection.h:16,
from ./test_types.cpp:14:
./test_types.h: In member function 'bool Test::A::operator==(const Test::A&) const':
./test_types.h:59:37: warning: comparing floating point with == or != is unsafe [-Wfloat-equal]
&& (fieldA == other.fieldA)
^~~~~~
./test_types.h:60:37: warning: comparing floating point with == or != is unsafe [-Wfloat-equal]
&& (fieldB == other.fieldB);
^~~~~~
chwarr commented 1 year ago

Bond builds with -Wall. -Wfloat-equal is not in -Wall.

Please build Bond-generated code with -Wall and without -Wfloat-equal. Consider using -isystem to add the generated Bond code to you header search path so that warnings in your code that uses Bond. This should let you continue to use -Wfloat-eqaul in your own code.

The Bond project itself isn't interested in being 100% warning clean for every warning that every compiler can emit. So, we at Microsoft have no plans to change the generated code to handle -Wfloat-equal.

chwarr commented 1 year ago

I believe this has been addressed. Closing this issue.