Uploaded image for project: 'C++ Standard Library'
  1. C++ Standard Library
  2. STDCXX-462

std::time_get example exposes undefined behavior

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 4.1.2, 4.1.3
    • 4.2.0
    • Documentation
    • None

    Description

      The example program demonstrating the use of the std::time_get facet (http://incubator.apache.org/stdcxx/doc/stdlibref/time-get.html) exposes undefined behavior. Quoting from the following post http://www.mail-archive.com/stdcxx-dev@incubator.apache.org/msg03760.html:

      Martin Sebor wrote:
      > Farid Zaripov wrote:
      [...]
      >> Btw below is a part of the conforming program (taken from
      >> time_get.cpp)?
      >
      > It's not a conforming program. The locale must stay around as
      > long as the last reference to the facet obtained from it. The
      > tests that fail to follow this rule should be changed.
      >
      >>
      >> -------------------
      >> const std::time_get<char, Iter> &tg =
      >> std::use_facet<std::time_get<char, Iter> >(std::locale ("C"));
      >>
      >> // Display time_base::dateorder value.
      >> std::cout << "time_base::dateorder == " << tg.date_order () <<
      >> ".\n";
      >> -------------------
      >>
      >> This fragment fails on Dinkumware STL because of tg.date_order() uses
      >> (internal)
      >> pointer to the destroyed locale object.
      >
      > Right, and that's allowed.

      Attachments

        Activity

          People

            farid Farid Zaripov
            sebor Martin Sebor
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: