nashiong / cantera

Automatically exported from code.google.com/p/cantera
0 stars 0 forks source link

Bug in checkFinite.cpp when building with g++-4.8 #217

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When using g++-4.8 as the C++ compiler, I found what seems to be a couple small 
bugs in checkFinite.cpp:

src/base/checkFinite.cpp: In function 'void Cantera::checkFinite(double)':
src/base/checkFinite.cpp:58:12: warning: 'int finite(double)' is deprecated 
(declared at 
/usr/local/Cellar/gcc48/4.8.2/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2/include-fi
xed/math.h:733) [-Wdeprecated-declarations]
     if (!::finite(tmp)) {
            ^
src/base/checkFinite.cpp:58:22: warning: 'int finite(double)' is deprecated 
(declared at 
/usr/local/Cellar/gcc48/4.8.2/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2/include-fi
xed/math.h:733) [-Wdeprecated-declarations]
     if (!::finite(tmp)) {
                      ^
src/base/checkFinite.cpp:59:13: error: '::isnan' has not been declared
         if (::isnan(tmp)) {
             ^
src/base/checkFinite.cpp:59:13: note: suggested alternative:
In file included from include/cantera/base/ct_defs.h:19:0,
                 from src/base/checkFinite.cpp:12:
/usr/local/Cellar/gcc48/4.8.2/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2/include/c+
+/cmath:632:5: note:   'std::isnan'
     isnan(_Tp __x)
     ^
src/base/checkFinite.cpp:61:20: error: '::isinf' has not been declared
         } else if (::isinf(tmp) == 1) {
                    ^
src/base/checkFinite.cpp:61:20: note: suggested alternative:
In file included from include/cantera/base/ct_defs.h:19:0,
                 from src/base/checkFinite.cpp:12:
/usr/local/Cellar/gcc48/4.8.2/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2/include/c+
+/cmath:614:5: note:   'std::isinf'
     isinf(_Tp __x)
     ^
scons: *** [build/src/base/checkFinite.os] Error 1

If I change "::isnan" and "::isinf" to "isnan" and "isinf", the file compiles 
fine. I assume this is because we are already using the std namespec, so the 
"::" are not needed.

Original issue reported on code.google.com by kyle.nie...@gmail.com on 1 May 2014 at 5:05

GoogleCodeExporter commented 9 years ago
...using the std namespace, I meant.

Original comment by kyle.nie...@gmail.com on 1 May 2014 at 5:06

GoogleCodeExporter commented 9 years ago
The "::" with no prefix is to specify the global namespace, not namespace std, 
which is required for some compilers / standard library implementations. 

The problem is that "isnan" and "isinf" are only part of the C++ standard as of 
C++11, but are frequently available in the global namespace by virtue of being 
available in C99 (which isn't part of the C++03 standard, either).

What I think is needed here is another configuration check to determine the 
correct way to call isnan/isinf, as the platform-based heuristic currently used 
is apparently insufficient.

Original comment by yarmond on 1 May 2014 at 9:41

GoogleCodeExporter commented 9 years ago
It looks like you may be able to check the value of "__cplusplus" for some 
compilers (e.g., gcc), although it appears Visual Studio doesn't support this.

Original comment by kyle.nie...@gmail.com on 1 May 2014 at 9:52

GoogleCodeExporter commented 9 years ago
I think this should be fixed by r2928, if you could please confirm.

Original comment by yarmond on 3 May 2014 at 5:41

GoogleCodeExporter commented 9 years ago
Yes, that revision builds and tests without error. Thanks!

Original comment by kyle.nie...@gmail.com on 3 May 2014 at 6:07

GoogleCodeExporter commented 9 years ago

Original comment by yarmond on 3 May 2014 at 6:26