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

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

Open
muellerj2 opened this issue Jan 15, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@muellerj2
Copy link
Contributor

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
@muellerj2 muellerj2 changed the title <locale>: std::collate<wchar_t> does not respect collation order when compiled with /MD(d) /Zc:wchar_t- <locale>: std::collate<wchar_t> does not respect collation order when compiled with /MD(d) /Zc:wchar_t- Jan 15, 2025
@StephanTLavavej StephanTLavavej added the bug Something isn't working label Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants