-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
std::cout
is not initialized when used in the constructor of a global static variable.
#153
Comments
Thanks for the report, this is indeed a bug! It appears that this is an instance of https://bugs.llvm.org/show_bug.cgi?id=28954 . Another workaround is to add |
I also have a patch to upstream the fix we made in emscripten: https://reviews.llvm.org/D74885 |
@sbc100 Is there an update on the status of that patch? |
No really, I guess we should push on it? |
Looks like we are moving forward with https://reviews.llvm.org/D31413. I'm hoping we even get it into llvm 11 which is about to be released. |
Awesome, thanks! |
This issue should be fixed with https://reviews.llvm.org/D31413 (by commit llvm/llvm-project@39faf42). I'll see if we can cherry-pick to LLVM 11. |
@ldionne Do you know if https://reviews.llvm.org/D31413 was cherry-picked into LLVM 11? Either way, #178 updates wasi-sdk to LLVM 12, which will hopefully resolve this. |
@sunfishcode The commit is:
I think it was only included in LLVM 12. |
This is purely a style change, in accordance with WebAssembly#116.
I can confirm that it is resolved in LLVM v12. |
This change was mostly generated by changing the upstream llvm branch to 9.x and running: $ git submodule update --remote As well as switching the llvm 9 this change also bring in the following wasi-libc changes: 5933c20 fix macos filename, use https 7c39519 CI: upgrade to llvm 9.0.0 9ca5187 remove no-self-update workaround for windows azure 9580a25 deprecate azure pipelines CI, build libc on GH Actions 2c2fc9a Don't call `free` on paths which are about to call `_Exit`. (WebAssembly#161) c6f2c05 gen-headers: Generate assertions of layout from witx (WebAssembly#149) 37c663f Correct minor typo in c_headers.rs (WebAssembly#166) 12f5832 Convert more wasi-libc code to `//`-style comments. (WebAssembly#153) ec86d4d Improvements to wasi-headers tool (WebAssembly#160) 1fad338 Fix environment variable init to exit successfully. (WebAssembly#159) a280fea Move math source files. (WebAssembly#151) dd010be Avoid using cast expressions in WASI API constants. (WebAssembly#148) Fixes: WebAssembly#101
When compiling and running the followig code:
The following error occurs:
It seems that
std::cout
is not initialized at the time it is used, when constructingstatic S s
.According to the C++ standard, paragraph 3 of [iostream.objects.overview] (where "the objects" refers to
std::cout
and co., emphasis of mine):And according to
[basic.start.dynamic]
, objects with static storage duration in the same compilation unit should be initialized in the order they appear; thusios_base::Init
beforeS s
.A workaround is to explicitly declare an
std::ios_base::Init
before usingstd::cout
:The text was updated successfully, but these errors were encountered: