<div dir="ltr"><div>I usually compile my code with almost most warning flags on, including -Wfloat-equal.</div><div>My implementation of the C++ complex fix that is not included by default is an obvious offender (see warning messages at the end). </div><div><br></div><div>A simple fix (and I think it is a safe one, same thing is used in the boost libraries, <a href="https://www.boost.org/doc/libs/1_72_0/boost/config/detail/suffix.hpp">https://www.boost.org/doc/libs/1_72_0/boost/config/detail/suffix.hpp</a>) that works with both GCC and clang (and most likely Intel, I'll try tomorrow) is the following:</div><div><br></div><div><font face="monospace">diff --git a/include/petsccxxcomplexfix.h b/include/petsccxxcomplexfix.h<br>index d3614e8a62..3c3090215b 100644<br>--- a/include/petsccxxcomplexfix.h<br>+++ b/include/petsccxxcomplexfix.h<br>@@ -35,6 +35,10 @@<br>      before including any PETSc include files to prevent these methods from being provided.<br> */<br> <br>+#if defined(__GNUC__) && (__GNUC__ >= 4)<br>+#pragma GCC system_header<br>+#endif<br>+<br> #define PETSC_CXX_COMPLEX_FIX(Type) \<br> static inline PetscComplex operator+(const PetscComplex& lhs, const Type& rhs) { return const_cast<PetscComplex&>(lhs) + PetscReal(rhs); } \<br> static inline PetscComplex operator+(const Type& lhs, const PetscComplex& rhs) { return PetscReal(lhs) + const_cast<PetscComplex&>(rhs); } \<br></font></div><div><br></div><div>Would that be an acceptable solution o we should rather implement a configure test and define PETSC_HAVE_PRAGMA_GCC_SYSTEM_HEADER ? </div><div><br></div><div>These are the kind of errors that show up for EVERY C++ source compile if -Wfloat-equal is passed.</div><div><br></div><font face="monospace">/home/devel/petsc/dev/include/petsccxxcomplexfix.h: In function ‘bool operator==(const PetscComplex&, const PetscInt&)’:<br>/home/devel/petsc/dev/include/petsccxxcomplexfix.h:47:134: warning: comparing floating point with == or != is unsafe [-Wfloat-equal]<br>   47 | static inline bool operator==(const PetscComplex& lhs, const Type& rhs) { return const_cast<PetscComplex&>(lhs).imag() == PetscReal(0) && const_cast<PetscComplex&>(lhs).real() == PetscReal(rhs); } \<br>      |                                                                                                                                      ^<br>/home/devel/petsc/dev/include/petsccxxcomplexfix.h:60:1: note: in expansion of macro ‘PETSC_CXX_COMPLEX_FIX’<br>   60 | PETSC_CXX_COMPLEX_FIX(PetscInt)<br></font><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Lisandro Dalcin<br>============<br>Research Scientist<br>Extreme Computing Research Center (ECRC)<br>King Abdullah University of Science and Technology (KAUST)<br><a href="http://ecrc.kaust.edu.sa/" target="_blank">http://ecrc.kaust.edu.sa/</a><br></div></div></div></div>