-
Bug
-
Resolution: Unresolved
-
Medium
-
Code Generation Tools
-
CODEGEN-8767
-
C6000_8.3.9
-
C7000_NEXT
-
default
-
Make sure to include math.h last
"fstream", line 486: error: class "std::_2::ios_base" has no member "_c6xabi_trunc"
This is an unfortunate interaction between C macros and C++ header files.
In the C6x implementation of math.h, the C99 floating-point function trunc() was actually implemented as _trunc() to keep it out of the user's namespace because the C99 standard was not ratified. A macro "#define trunc _trunc" was provided if the user defined a certain macro to use C99-like floating-point functions. Later on, this macro was changed to "#define trunc _trunc", which precipitated this bug. If you include math.h along with any other files that define or refer to an identifier "trunc," it may get changed to _trunc inadvertently. In particular, C++ standard header file <ios> defines "class ios_base" which has a member "ios_base::trunc," which has nothing to do with the floating-point function trunc.
This test case includes <iostream> first, which includes <ios>, which defines ios_base::trunc. The test case then includes math.h so it cannot affect the definition of ios_base::trunc. Then the test case includes <fstream>, which defines the template basic_filebuf, which uses ios_base::trunc. However, because it got included after math.h, the macro takes effect and it now tries to use ios_base::_trunc, which doesn't exist.