Including math.h between C++ header files can lead to error: class "std::__2::ios_base" has no member "__c6xabi_trunc"

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Medium
    • Code Generation Tools
    • CODEGEN-8767
    • Hide
      C6000_8.3.0
      C6000_8.3.1
      C6000_8.3.2
      C6000_8.5.0.LTS
      C6000_8.3.3
      C6000_8.3.13
      C6000_8.3.4
      C6000_8.3.12
      C6000_8.3.5
      C6000_8.3.6
      C6000_8.3.14
      C6000_8.3.7
      C6000_8.3.8
      C6000_8.3.15*
      C6000_8.3.9
      C6000_8.3.11
      C6000_8.3.10
      Show
      C6000_8.3.0 C6000_8.3.1 C6000_8.3.2 C6000_8.5.0.LTS C6000_8.3.3 C6000_8.3.13 C6000_8.3.4 C6000_8.3.12 C6000_8.3.5 C6000_8.3.6 C6000_8.3.14 C6000_8.3.7 C6000_8.3.8 C6000_8.3.15* C6000_8.3.9 C6000_8.3.11 C6000_8.3.10
    • 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.

            Assignee:
            TI User
            Reporter:
            TI User
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:

                Connection: Intermediate to External PROD System
                EXTSYNC-2864 - Including math.h between C++ header...
                SYNCHRONIZED
                • Last Sync Date: