View Issue Details

IDProjectCategoryView StatusLast Update
0002041OpenFOAM[All Projects] Bugpublic2016-04-04 12:53
ReporterwyldckatAssigned Tohenry 
Status resolvedResolutionfixed 
PlatformGNU/LinuxOSUbuntuOS Version16.04
Product Versiondev 
Fixed in Version 
Summary0002041: Problems with "isnan" in "src/conversion/ensight/part": C99 vs C++11
DescriptionI 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 Informationdiff --git a/src/conversion/ensight/part/ensightPart.H b/src/conversion/ensight/part/ensightPart.H
index feb6d37..d6e4cd5 100644
--- a/src/conversion/ensight/part/ensightPart.H
+++ b/src/conversion/ensight/part/ensightPart.H
@@ -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);
+ #else
+ return ::isnan(value);
+ #endif
+ }
TagsNo tags attached.



2016-04-03 18:14


ensightPart.H (9,345 bytes)


2016-04-04 08:22

manager   ~0006078

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]))


2016-04-04 12:25

updater   ~0006080

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:

  - Line 83:

And that's it. There are no other needs for "isnan" at this moment.


2016-04-04 12:45

manager   ~0006081

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.


2016-04-04 12:52

manager   ~0006082

Resolved in OpenFOAM-3.0.x by
commit 9716f15f665cf0579e97b23703183b3db95afaf2
commit ea3490b533b444dd42292c6dec940b03b3313ddc

Resolved in OpenFOAM-dev by
commit 1c97ed7098cc579168d7e58ddefe47af282de0fd
commit 1fbd362faa9a14c99ec13c88ea6863cac68976d9

Issue History

Date Modified Username Field Change
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