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

Crash when declaring std::locale #498

Open
hcfcoder opened this issue Sep 6, 2021 · 3 comments
Open

Crash when declaring std::locale #498

hcfcoder opened this issue Sep 6, 2021 · 3 comments

Comments

@hcfcoder
Copy link

hcfcoder commented Sep 6, 2021

This line makes the program crash at the beginning, without running a single line. It doesn't matter if the declaration is done as a local variable or as a global one (it fails on both ways):

std::locale const f_portable_locale("C");

The following gist has a minimal program to reproduce this issue:

https://gist.github.com/hcfcoder/326b826dbd13e64f19110bd9905dfaae

@hcfcoder
Copy link
Author

I have updated the program, removing the SDL functions and library, to make it even more minimal.

@thrimbor
Copy link
Member

It appears that the program doesn't actually crash, it exits because it's unable to recover from an error.

We don't really support locales yet, so we're using the stubs included in libc++. Apparently this is not enough to allow constructing a std::locale object though: The constructor contains the line install(new collate_byname<char>(name_)), which calls into https://github.com/XboxDev/nxdk-libcxx/blob/c594e975f383418d98dbdf35a8f2fff4699a62fb/src/locale.cpp#L674

The stubbed newlocale function returns NULL, causing this function to try to throw an exception via __throw_runtime_error, but because C++ exceptions are disabled, that function makes the program quit instead.

I'm not sure why libc++ does it this way, but until we have better locale support, it's probably best to avoid using std::locale at all.

@hcfcoder
Copy link
Author

Thank you very much, everything is clear!

As these errors can be hard to debug, would it be worth to put a warning message in the "locale" constructor, so that when someone compiles a program and "locale" is used, a warning message is triggered? I know that it is a bad solution, but leaving as it is can make someone waste a lot of time trying to figure out where is his error...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants