Skip to content

<locale>: std::collate<wchar_t> does not respect collation order when compiled with /MD(d) /Zc:wchar_t- #5236

Open
@muellerj2

Description

std::collate<wchar_t>::compare() and std::collate<wchar_t>::transform() do not actually perform comparisons or transformations with respect to the collation order when the program is compiled with flags /MD(d) /Zc:wchar_t-.

Test case

#include <iostream>
#include <locale>

using namespace std;

int main() {
    const wchar_t Ue = L'\u00DC'; // U+00DC LATIN CAPITAL LETTER U WITH DIARESIS
    const wchar_t U = L'U';
    const wchar_t V = L'V';

    // German phonebook order: "U+00DC" collates like string "Ue"
    locale loc("de-DE_phoneb");
    auto &coll = use_facet<collate<wchar_t>>(loc);

    cout << "transform(Ue) != Ue: "
            << (coll.transform(&Ue, &Ue + 1) != L"\u00DC") << '\n';

    cout << "transform(U) <= transform(Ue) <= transform(V): "
            << (coll.transform(&U, &U + 1) <= coll.transform(&Ue, &Ue + 1) &&
                coll.transform(&Ue, &Ue + 1) <= coll.transform(&V, &V + 1)); 
}

https://godbolt.org/z/Kx8z43e71

Compiled with /MD(d) /Zc:wchar_t-, this prints:

transform(Ue) != Ue: 0
transform(U) <= transform(Ue) <= transform(V): 0

Expected result

Because "Ü" should collate like "Ue" in the German phonebook collation order, this should print (as it does with /MD /Zc:wchar_t or /MT /Zc:wchar_t-):

transform(Ue) != Ue: 1
transform(U) <= transform(Ue) <= transform(V): 1

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