> On Jan 27, 2020, at 3:42 PM, Lisandro Dalcin <dalc...@gmail.com> wrote:
> 
> I usually compile my code with almost most warning flags on, including 
> -Wfloat-equal.
> My implementation of the C++ complex fix that is not included by default is 
> an obvious offender (see warning messages at the end). 
> 
> A simple fix (and I think it is a safe one, same thing is used in the boost 
> libraries, 
> https://www.boost.org/doc/libs/1_72_0/boost/config/detail/suffix.hpp) that 
> works with both GCC and clang (and most likely Intel, I'll try tomorrow) is 
> the following:
> 
> diff --git a/include/petsccxxcomplexfix.h b/include/petsccxxcomplexfix.h
> index d3614e8a62..3c3090215b 100644
> --- a/include/petsccxxcomplexfix.h
> +++ b/include/petsccxxcomplexfix.h
> @@ -35,6 +35,10 @@
>       before including any PETSc include files to prevent these methods from 
> being provided.
>  */
>  
> +#if defined(__GNUC__) && (__GNUC__ >= 4)
> +#pragma GCC system_header
> +#endif
> +
>  #define PETSC_CXX_COMPLEX_FIX(Type) \
>  static inline PetscComplex operator+(const PetscComplex& lhs, const Type& 
> rhs) { return const_cast<PetscComplex&>(lhs) + PetscReal(rhs); } \
>  static inline PetscComplex operator+(const Type& lhs, const PetscComplex& 
> rhs) { return PetscReal(lhs) + const_cast<PetscComplex&>(rhs); } \
> 
> Would that be an acceptable solution o we should rather implement a configure 
> test and define PETSC_HAVE_PRAGMA_GCC_SYSTEM_HEADER ? 

  I'm fine with having it handled by the version check.

> 
> These are the kind of errors that show up for EVERY C++ source compile if 
> -Wfloat-equal is passed.
> 
> /home/devel/petsc/dev/include/petsccxxcomplexfix.h: In function ‘bool 
> operator==(const PetscComplex&, const PetscInt&)’:
> /home/devel/petsc/dev/include/petsccxxcomplexfix.h:47:134: warning: comparing 
> floating point with == or != is unsafe [-Wfloat-equal]
>    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); } \
>       |                                                                       
>                                                                ^
> /home/devel/petsc/dev/include/petsccxxcomplexfix.h:60:1: note: in expansion 
> of macro ‘PETSC_CXX_COMPLEX_FIX’
>    60 | PETSC_CXX_COMPLEX_FIX(PetscInt)

  I don't understand the above. Are these two unrelated issues? Or does adding 
the first chunk of code prevent the warnings from the second chunk of code.

   Barry

> 
> -- 
> Lisandro Dalcin
> ============
> Research Scientist
> Extreme Computing Research Center (ECRC)
> King Abdullah University of Science and Technology (KAUST)
> http://ecrc.kaust.edu.sa/

Reply via email to