Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sergrak opened this issue Jul 11, 2023 · 2 comments
Closed

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

sergrak opened this issue Jul 11, 2023 · 2 comments

Comments

@sergrak
Copy link

sergrak commented Jul 11, 2023

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
Copy link
Member

chwarr commented Jul 11, 2023

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
Copy link
Member

chwarr commented Sep 7, 2023

I believe this has been addressed. Closing this issue.

@chwarr chwarr closed this as completed Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants