dimanche 6 décembre 2015

Why does this simple C++ program using

This code seemed to work ok in (ubuntu trusty) versions of gcc and clang, and in Win 7 on a VM via mingw... Recently I upgraded to Wily and now clang segfaults consistently here.

#include <iostream>
#include <locale>

int main() {
  std::cout << "The locale is '" << std::locale("").name() << "'" << std::endl;
}

I also got an invalid free on Coliru with it as well.

But this is very similar to example code on cppreference:

#include <iostream>
#include <locale>

int main()
{
    std::wcout << "User-preferred locale setting is " << std::locale("").name().c_str() << '\n';
    // on startup, the global locale is the "C" locale
    std::wcout << 1000.01 << '\n';
    // replace the C++ global locale as well as the C locale with the user-preferred locale
    std::locale::global(std::locale(""));
    // use the new global locale for future wide character output
    std::wcout.imbue(std::locale());
    // output the same number again
    std::wcout << 1000.01 << '\n';
}

Actually that code crashes Coliru also... :facepalm:

Is this a bug in clang's c++ library, or is this code defective?

Aucun commentaire:

Enregistrer un commentaire