View Issue Details
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0002041||OpenFOAM||[All Projects] Bug||public||2016-04-03 18:14||2016-04-04 12:53|
|Fixed in Version|
|Summary||0002041: Problems with "isnan" in "src/conversion/ensight/part": C99 vs C++11|
|Description||I was testing building OpenFOAM-dev (commit ac71f86574) with Ubuntu 16.04 and I tripped on this compiler error message:|
ensight/part/ensightPart.C:54:54: error: ‘isnan’ was not declared in this scope
if (id >= field.size() || isnan(field[id]))
Even though I'm using Ubuntu 16.04 beta, it is using GCC 5.3.1, so I expect that something changed permanently in the build pattern when using "-std=c++0x", given that I don't get this issue with GCC 5.2.1 on Ubuntu 15.10.
Attached is the file "ensightPart.H", to update "src/conversion/ensight/part/ensightPart.H" in OpenFOAM-dev. It adds an "inline isnan" method that will use either the C99 or C++11 definition at build time.
For easier inspection, the patch is shown in the "Additional Information" section below.
|Additional Information||diff --git a/src/conversion/ensight/part/ensightPart.H b/src/conversion/ensight/part/ensightPart.H|
index feb6d37..d6e4cd5 100644
@@ -62,6 +62,16 @@ class ensightPart
// Static data members
static const List<word> elemTypes_;
+ // wrapper for isnan, namely C99 or C++11
+ inline bool isnan(const scalar value) const
+ #ifndef isnan
+ return std::isnan(value);
+ return ::isnan(value);
|Tags||No tags attached.|
ensightPart.H (9,345 bytes)
I am using gcc-5.3.1 and not seen this issue so it is something to do with the header files on Ubuntu 16.04. Why is it necessary to create this inline wrapper? Why not simply use
if (id >= field.size() || std::isnan(field[id]))
As far as I can figure out (although I haven't fully tested this yet), the "std::isnan" solution will not work when GCC is not set to use C++11 or similar (namely the "tr1"). This is because "isnan()" was only introduced as a function part of the "std" namespace in the C++11 standard.
When not using the C++11 standard, it will default to the C99 standard which relies on a macro named "isnan". This is the option I suspect is being used by default in your build of GCC 5.3.1. This was why I proposed the wrapper, so that it would cover both scenarios... although the wrapper is assuming that the correct "isnan" is predefined by default.
If you prefer to simply deprecate the reliance on the C99 standard, there are 2 more occurrences of "isnan" in the "ensightPartIO.C" file:
- Line 66: https://github.com/OpenFOAM/OpenFOAM-dev/blob/master/src/conversion/ensight/part/ensightPartIO.C#L66
- Line 83: https://github.com/OpenFOAM/OpenFOAM-dev/blob/master/src/conversion/ensight/part/ensightPartIO.C#L83
And that's it. There are no other needs for "isnan" at this moment.
I have tested std::isnan with gcc-5.3.1, gcc-4.5.4, clang-3.7.0 and icpc-15.0.3 without any problems so I don't think there is a need for the inline wrapper.
I will make the same change to ensightPartIO.C and close this report; please reopen if further issues with isnan occur.
Resolved in OpenFOAM-3.0.x by
Resolved in OpenFOAM-dev by
|2016-04-03 18:14||wyldckat||New Issue|
|2016-04-03 18:14||wyldckat||Status||new => assigned|
|2016-04-03 18:14||wyldckat||Assigned To||=> henry|
|2016-04-03 18:14||wyldckat||File Added: ensightPart.H|
|2016-04-04 08:22||henry||Note Added: 0006078|
|2016-04-04 12:25||wyldckat||Note Added: 0006080|
|2016-04-04 12:45||henry||Note Added: 0006081|
|2016-04-04 12:52||henry||Note Added: 0006082|
|2016-04-04 12:52||henry||Status||assigned => resolved|
|2016-04-04 12:52||henry||Fixed in Version||=> 3.0.x|
|2016-04-04 12:52||henry||Resolution||open => fixed|