Uploaded image for project: 'Embedded Software & Tools'
  1. Embedded Software & Tools
  2. EXT_EP-10330

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Medium Medium

      "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.

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

              Created:
              Updated: