microsoft / microsoft/STL

`<xloctime>`: `do_get_monthname` and `do_get_weekday` do not set `eofbit` in some cases, but `libcxx` tests expect them to do

Open
#6,128 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C++
Stars
11.1k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

(I'm filing this issue to record my analysis about a few libcxx test failures related to get_monthname and get_weekday. These functions are super old, rarely used, and it's unclear what the correct behavior is.)

These `libcxx` tests seem to be affected ``` std/localization/locale.categories/category.time/locale.time.get.byname/get_monthname.pass.cpp std/localization/locale.categories/category.time/locale.time.get.byname/get_monthname_wide.pass.cpp std/localization/locale.categories/category.time/locale.time.get.byname/get_weekday.pass.cpp std/localization/locale.categories/category.time/locale.time.get.byname/get_weekday_wide.pass.cpp std/localization/locale.categories/category.time/locale.time.get/locale.time.get.members/get_monthname_wide.pass.cpp std/localization/locale.categories/category.time/locale.time.get/locale.time.get.members/get_monthname.pass.cpp std/localization/locale.categories/category.time/locale.time.get/locale.time.get.members/get_weekday_wide.pass.cpp std/localization/locale.categories/category.time/locale.time.get/locale.time.get.members/get_weekday.pass.cpp ```

Describe the bug

When they reach the end of input after a successful match, time_get::do_get_monthname and time_get::do_get_weekday do not set eofbit, but libcxx tests expect them to do.

Command-line test case

D:\test>type test-time-get.cpp
#include <cassert>
#include <ctime>
#include <iostream>
#include <locale>

using I = const char*;

class my_facet : public std::time_get<char, I>
{
public:
    explicit my_facet(std::size_t refs = 0)
        : time_get(refs) {}
};

int main() {
    const my_facet f(1);
    std::ios str(nullptr);
    std::ios_base::iostate err;
    std::tm t;

    {
        std::cout << "Test 1: Get month name\n";

        const char in[] = "Jan";
        err = std::ios_base::goodbit;
        t = std::tm();
#ifdef TEST_GET_MONTHNAME_WEEKDAY
        I i = f.get_monthname(I(in), I(in+sizeof(in)-1), str, err, &t);
#else
        I i = f.get(I(in), I(in+sizeof(in)-1), str, err, &t, 'b');
#endif
        assert(i == in+3);
        assert(t.tm_mon == 0);
        if (err == std::ios::eofbit) {
            std::cout << "eofbit is set\n";
        } else {
            assert(err == std::ios::goodbit);
        }
    }

    {
        std::cout << "Test 2: Get weekday\n";
        const char in[] = "Sun";
        err = std::ios_base::goodbit;
        t = std::tm();
#ifdef TEST_GET_MONTHNAME_WEEKDAY
        I i = f.get_weekday(I(in), I(in+sizeof(in)-1), str, err, &t);
#else
        I i = f.get(I(in), I(in+sizeof(in)-1), str, err, &t, 'a');
#endif
        assert(i == in+3);
        assert(t.tm_mday == 0);
        if (err == std::ios::eofbit) {
            std::cout << "eofbit is set\n";
        } else {
            assert(err == std::ios::goodbit);
        }
    }
}
D:\test>cl /EHsc /DTEST_GET_MONTHNAME_WEEKDAY test-time-get.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.50.35725 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

test-time-get.cpp
Microsoft (R) Incremental Linker Version 14.50.35725.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:test-time-get.exe
test-time-get.obj
D:\test>cl /EHsc test-time-get.cpp /Fe: test-time-get-with-get.exe
Microsoft (R) C/C++ Optimizing Compiler Version 19.50.35725 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

test-time-get.cpp
Microsoft (R) Incremental Linker Version 14.50.35725.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:test-time-get-with-get.exe
test-time-get.obj
D:\test>test-time-get.exe
Test 1: Get month name
Test 2: Get weekday
D:\test>test-time-get-with-get.exe
Test 1: Get month name
eofbit is set
Test 2: Get weekday
eofbit is set

Expected behavior

test-time-get.exe has the same output as test-time-get-with-get.exe.

STL version

https://github.com/microsoft/STL/commit/117ca965fe2f7157540edd9df5a62b0e42d7ece2

Additional context

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the eight listed libcxx time_get tests and the provided test-time-get.cpp reproduction, comparing the named get_monthname/get_weekday calls with the get overload. Check the standard requirements and existing time_get behavior before deciding whether eofbit should be set; done when the intended behavior is resolved and the affected tests agree.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
internationalization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.