[gdal-dev] OGREnvelope: add == and != comparison operators

Even Rouault even.rouault at spatialys.com
Wed Feb 23 06:16:17 PST 2022


Andrew,

we have already suppression for such warning for the IsInit() method

#ifdef HAVE_GCC_DIAGNOSTIC_PUSH
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
     /** Return whether the object has been initialized, that is, is non 
empty */
     int  IsInit() const { return MinX != 
std::numeric_limits<double>::infinity(); }

#ifdef HAVE_GCC_DIAGNOSTIC_PUSH
#pragma GCC diagnostic pop
#endif

so I guess this should be extended to operator== as well.

And likely replace #ifdef HAVE_GCC_DIAGNOSTIC_PUSH by just #ifdef __GNUC__

since HAVE_GCC_DIAGNOSTIC_PUSH is something that is defined only during 
GDAL build.

The HAVE_GCC_DIAGNOSTIC_PUSH define should be set for all reasonably GCC 
and Clang versions that can build modern GDAL.

Please issue a PR with those changes if that fixes thing for you.

Even


Le 23/02/2022 à 15:08, Andrew C Aitchison a écrit :
>
> I am trying to track down numerical errors in my driver code
> by turning up all the compiler warnings, but pull request #5122
> https://github.com/OSGeo/gdal/pull/5122/commits/3d877aa5da8868ed5c3aacf98845c90bc0d36e54 
>
> triggers clang++ -Werror,-Wfloat-equal
>
> Assuming it is possible, would it make sense to tell compilers
> (and static analyzers?) to ignore this warning ?
>
> I assume that in this case we *do* want an exact floating point 
> comparison.
>
> ------------------------------------------------------
>
> clang++-13 -I /usr/local/gdal.git.llvm/include -fPIC -std=c++11 -Wall
>     -Wextra -Weverything -Werror -Wno-padded
>     -Wno-error=unknown-warning-option -Wno-format-pedantic
>     -Wno-c++98-compat-pedantic   -Wno-deprecated-copy-with-dtor
>     -Wno-reserved-identifier -Og -g -DFRMT_qct -DFRMT_qed
>     -c -o qed.o qed.cpp
> In file included from qed.cpp:42:
> In file included from /usr/local/gdal.git.llvm/include/gdal_pam.h:36:
> In file included from /usr/local/gdal.git.llvm/include/gdal_priv.h:60:
> In file included from /usr/local/gdal.git.llvm/include/gdal.h:50:
> In file included from /usr/local/gdal.git.llvm/include/ogr_api.h:45:
> /usr/local/gdal.git.llvm/include/ogr_core.h:158:21: error: comparing 
> floating point with == or != is unsafe [-Werror,-Wfloat-equal]
>         return MinX == other.MinX &&
>                ~~~~ ^  ~~~~~~~~~~
> /usr/local/gdal.git.llvm/include/ogr_core.h:159:21: error: comparing 
> floating point with == or != is unsafe [-Werror,-Wfloat-equal]
>                MinY == other.MinY &&
>                ~~~~ ^  ~~~~~~~~~~
> /usr/local/gdal.git.llvm/include/ogr_core.h:160:21: error: comparing 
> floating point with == or != is unsafe [-Werror,-Wfloat-equal]
>                MaxX == other.MaxX &&
>                ~~~~ ^  ~~~~~~~~~~
> /usr/local/gdal.git.llvm/include/ogr_core.h:161:21: error: comparing 
> floating point with == or != is unsafe [-Werror,-Wfloat-equal]
>                MaxY == other.MaxY;
>                ~~~~ ^  ~~~~~~~~~~
> 4 errors generated.
>
>
-- 
http://www.spatialys.com
My software is free, but my time generally not.



More information about the gdal-dev mailing list