Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<xlocale>: boolalpha extraction should be case-sensitive #1541

Closed
StephanTLavavej opened this issue Dec 17, 2020 · 2 comments · Fixed by #1543
Closed

<xlocale>: boolalpha extraction should be case-sensitive #1541

StephanTLavavej opened this issue Dec 17, 2020 · 2 comments · Fixed by #1543
Labels
bug Something isn't working fixed Something works now, yay! high priority Important!

Comments

@StephanTLavavej
Copy link
Member

StephanTLavavej commented Dec 17, 2020

Reported by @b7f7 in ea1aaf7#commitcomment-45101146 . Also tracked by Microsoft-internal VSO-1259300 / AB#1259300 .

This is a regression in VS 2019 16.8 caused by GH-1168. I developed a complete test case:

C:\Temp>type meow.cpp
#include <cassert>
#include <ios>
#include <sstream>
using namespace std;

enum class Parse { Success, Failure };

struct TestCase {
    const char* str;
    ios_base::fmtflags flags;
    Parse expected;
    bool result;
};

// clang-format off
constexpr TestCase test_cases[] = {
    {"0",     ios_base::fmtflags{}, Parse::Success, false},
    {"1",     ios_base::fmtflags{}, Parse::Success, true },
    {"2",     ios_base::fmtflags{}, Parse::Failure, true }, // N4868 [facet.num.get.virtuals]/6
    {"WOOF",  ios_base::fmtflags{}, Parse::Failure, false}, // N4868 [facet.num.get.virtuals]/3.6
    {"false", ios_base::boolalpha,  Parse::Success, false},
    {"true",  ios_base::boolalpha,  Parse::Success, true },
    {"WOOF",  ios_base::boolalpha,  Parse::Failure, false}, // N4868 [facet.num.get.virtuals]/7
    {"FALSE", ios_base::boolalpha,  Parse::Failure, false}, // regressed by GH-1168
    {"TRUE",  ios_base::boolalpha,  Parse::Failure, false}, // regressed by GH-1168
};
// clang-format on

int main() {
    for (const auto& test : test_cases) {
        bool val = !test.result;
        istringstream iss(test.str);
        iss.setf(test.flags);
        iss >> val;
        assert(iss.fail() == (test.expected == Parse::Failure));
        assert(val == test.result);
    }
}
C:\Temp>cl /EHsc /nologo /W4 meow.cpp && meow
meow.cpp
Assertion failed: iss.fail() == (test.expected == Parse::Failure), file meow.cpp, line 35

The "FALSE" and "TRUE" cases are asserting because the Standard says that the extraction should fail, but the extraction is succeeding after GH-1168 modified _Getloctxt() to perform case-insensitive comparisons:

} else if (_First == _Last || _CType.tolower(_Ptr[_Off]) != _CType.tolower(static_cast<_Elem>(*_First))) {

@StephanTLavavej StephanTLavavej added the bug Something isn't working label Dec 17, 2020
StephanTLavavej referenced this issue Dec 17, 2020
Fixes #1126.

Co-authored-by: Stephan T. Lavavej <stl@microsoft.com>
@fsb4000
Copy link
Contributor

fsb4000 commented Dec 17, 2020

developer community issue: DevCom-1289669

@StephanTLavavej StephanTLavavej added the high priority Important! label Dec 17, 2020
@StephanTLavavej
Copy link
Member Author

As this is a runtime behavior regression and has been encountered by 2-3 users, I am marking this as high priority.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed Something works now, yay! high priority Important!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants