Skip to content

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

@cpplearner

Description

@cpplearner

(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

117ca96

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions