#6489 closed defect (fixed)
compilation fails with G++5 if c++0x / c++11 flag (ambiguous isnan and isinf)
Reported by: | shot2 | Owned by: | warmerdam |
---|---|---|---|
Priority: | low | Milestone: | 2.1.1 |
Component: | ConfigBuild | Version: | svn-trunk |
Severity: | normal | Keywords: | gcc c++ build isinf isnan math |
Cc: |
Description
The latest SVN/trunk builds fine under gcc/g++ 5.3.1 out of the box. However, enabling the pdfium library (as per this page) enforces -std=c++0x, which in turn causes compilation to fail for e.g. vrtrasterband.cpp and other critical parts of GDAL as well.
libtool: compile: g++ -I/home/admin/dmz/gdal/gdal-svn-trunk-2016.04.26/port -I/home/admin/dmz/gdal/gdal-svn-trunk-2016.04.26/gcore -I/home/admin/dmz/gdal/gdal-svn-trunk-2016.04.26/alg -I/home/admin/dmz/gdal/gdal-svn-trunk-2016.04.26/ogr -I/home/admin/dmz/gdal/gdal-svn-trunk-2016.04.26/ogr/ogrsf_frmts -I/home/admin/dmz/gdal/gdal-svn-trunk-2016.04.26/gnm -I/home/admin/dmz/gdal/gdal-svn-trunk-2016.04.26/apps -std=c++0x -g -O2 -fvisibility=hidden -Wall -Wextra -Winit-self -Wunused-parameter -Wformat -Werror=format-security -Wno-format-nonliteral -Wlogical-op -Wshadow -Werror=vla -Wmissing-declarations -Wnon-virtual-dtor -Woverloaded-virtual -fno-operator-names -I../raw -DGNM_ENABLED -DOGR_ENABLED -I/home/admin/dmz/gdal/gdal-svn-trunk-2016.04.26/port -I/usr/include/libqhull -I/usr/include/qhull -I/usr/include -DGDAL_COMPILATION -c vrtrasterband.cpp -fPIC -DPIC -o ../o/.libs/vrtrasterband.o In file included from /home/admin/dmz/gdal/gdal-svn-trunk-2016.04.26/port/cpl_hash_set.h:34:0, from vrtdataset.h:34, from vrtrasterband.cpp:31: vrtrasterband.cpp: In member function 'virtual CPLXMLNode* VRTRasterBand::SerializeToXML(const char*)': /home/admin/dmz/gdal/gdal-svn-trunk-2016.04.26/port/cpl_port.h:551:30: error: 'isnan' was not declared in this scope # define CPLIsNan(x) isnan(x) ^ vrtrasterband.cpp:550:13: note: in expansion of macro 'CPLIsNan' if (CPLIsNan(m_dfNoDataValue)) ^ /home/admin/dmz/gdal/gdal-svn-trunk-2016.04.26/port/cpl_port.h:551:30: note: suggested alternative: # define CPLIsNan(x) isnan(x) ^ vrtrasterband.cpp:550:13: note: in expansion of macro 'CPLIsNan' if (CPLIsNan(m_dfNoDataValue)) ^ In file included from /usr/include/c++/5/random:38:0, from /usr/include/c++/5/bits/stl_algo.h:66, from /usr/include/c++/5/algorithm:62, from vrtrasterband.cpp:35: /usr/include/c++/5/cmath:641:5: note: 'std::isnan' isnan(_Tp __x) ^ ../../GDALmake.opt:648: recipe for target '../o/vrtrasterband.lo' failed
The errors seem related to inclusion of cmath macros relying on isnan and isinf (cf. cpl_port.h), those being ambiguous or conflicting when in ~c++11 mode (see e.g. this).
Temporarily redefining the macros on a per-need basis (to e.g. std::isnan and/or std::isinf) allows compilation to proceed further in a stepwise manner, so as to locate various points of failure due to isnan and isinf. Note that the same errors occur with either c++0x or c++11 flags. Using explicitly-defined functions and/or macros for isnan and isinf may help solve the issue. In the meantime, a pdf library other than "home-brewed" pdfium should be preferred.
Ubuntu 16.04 LTS amd64, gdal-svn-trunk-2016.04.26, gcc version 5.3.1.
Change History (7)
comment:1 by , 8 years ago
Version: | unspecified → svn-trunk |
---|
comment:2 by , 8 years ago
comment:3 by , 8 years ago
Files identified (so far...) which cause c++11 failure due to CPLIsFinite/CPLIsNan macros calling ambiguous isnan/isinf:
apps/gdaldem_lib.cpp (lines :152 :162 :224 :812 :941 :943 :2071 = std::isnan)
apps/gdalwarp_lib.cpp (line :1094 = std::isnan)
frmts/usgsdem/usgsdemdataset.cpp (line :395 = std::isnan and std::isinf)
frmts/vrt/vrtrasterband.cpp (line :550 = std::isnan)
frmts/vrt/vrtsources.cpp (lines :888-:891 = std::isinf)
frmts/vrt/vrtwarped.cpp (lines :1394 :1395 :1399 = std::isnan)
Ugly workaround: in order to locate problematic calls to ambiguous stuff, I temporarily added some new alternate CPLIsStdNan/CPLIsStdFinite to rely on std:: namespace; editing the aforementionned files to use these new std-enabled macros results in a successful compilation with internal pdfium (and enabling a whole lot of external libs as well).
A prettier solution would definitely be to investigate and explicitly declare each and every call to isnan/isinf, with conditional logic depending on the build environment...
comment:4 by , 8 years ago
comment:6 by , 8 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:7 by , 8 years ago
Milestone: | → 2.1.1 |
---|
It must be something new with GCC 5.3. https://github.com/rouault/gdal_coverage/blob/trunk_gcc5.2_sanitize/.travis.yml runs fine with GCC 5.2.0 and -std=c++14
In frmts/vrt/vrtsources.cpp, I see there's a (ugly) workaround for a similar issue. Not sure how to fix that more cleanly. It seems CPLIsNan() should be a function whose definition is put in a separate .cpp files, instead of a macro so as to avoid being dependant on which headers are included and in which order.