https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99439

            Bug ID: 99439
           Summary: use_facet<time_get<wchar_t>> (l); get() API with
                    kMonthDayYearFormat = L"%m/%d/%Y" should allow missing
                    leading zero
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lewis at sophists dot com
  Target Milestone: ---

This code fails to compile (viewable on onlinegcc compiler link
https://onlinegdb.com/rkloG0-7O)

---

#include <cstdio>
#include <locale>
#include <cassert>
#include <sstream>

using namespace std;


auto getPCTMRequiresLeadingZeroBug = [] () {
    static constexpr wstring_view kMonthDayYearFormat = L"%m/%d/%Y"sv;

    std::locale                  l     = locale::classic ();
    const time_get<wchar_t>&     tmget = use_facet<time_get<wchar_t>> (l);
    ios::iostate                 state = ios::goodbit;
    wistringstream               iss (L"11/1/2002");
    istreambuf_iterator<wchar_t> itbegin (iss); // beginning of iss
    istreambuf_iterator<wchar_t> itend;         // end-of-stream
    tm                           resultTM{};
    auto                         i = tmget.get (itbegin, itend, iss, state,
&resultTM, kMonthDayYearFormat.data (), kMonthDayYearFormat.data () +
kMonthDayYearFormat.length ());
#if qCompilerAndStdLib_locale_time_get_PCTM_RequiresLeadingZero_Buggy
    assert ((state & ios::badbit) or (state & ios::failbit));
#else
    assert (not((state & ios::badbit) or (state & ios::failbit)));
#endif
};


int main()
{
    getPCTMRequiresLeadingZeroBug();
    printf("Hello World");

    return 0;
}
---

The reason this APPEARS to be a bug is the docs:

https://en.cppreference.com/w/cpp/locale/time_get/get
say 
parses the month as a decimal number (range [01,12]), leading zeroes permitted
but not required

meaning leading zero CAN be there in month, but not it says NOT REQUIRED.

11/1/2004 fails to parse, but 11/01/2004 works (but the leading zero should be
optional).

Reply via email to