pybind11 icon indicating copy to clipboard operation
pybind11 copied to clipboard

[WARING]: Compile Warning

Open NNUCJ opened this issue 8 months ago • 1 comments

Required prerequisites

  • [x] Make sure you've read the documentation. Your issue may be addressed there.
  • [x] Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
  • [x] Consider asking first in the Gitter chat room or in a Discussion.

What version (or hash if on master) of pybind11 are you using?

master

Problem description

We notice the compile warning in this file [include/pybind11/complex.h:58]

The warning is shown below: warning: comparing floating point with == or != is unsafe [-Wfloat-equal]

Detail Code is shown below: if (result.real == -1.0 && PyErr_Occurred())

I would like to konw your team will consider resolving this compilation alert ? In which version will the compilation alarm be removed ?

Reproducible example code


Is this a regression? Put the last known working version here if it is.

Not a regression

NNUCJ avatar Apr 10 '25 11:04 NNUCJ

Getting rid of this is hard; this is literally how CPython communicates errors, we are not doing something wrong here. This is an extremely pedantic warning; I'd recommend not enabling it (or passing -Wno-float-equal) on code that uses CPython (including pybind11). It's really just trying to protect you from comparing computed values, something like .1 + .2 == .3.

If someone wanted to put warning suppression pragmas around everything in pybind11, we probably could review such a patch, as long as it wasn't too long.

henryiii avatar Jun 03 '25 14:06 henryiii