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

constructing an ios_base::Init object clobbers stream state #42645

Closed
zygoloid mannequin opened this issue Sep 12, 2019 · 3 comments
Closed

constructing an ios_base::Init object clobbers stream state #42645

zygoloid mannequin opened this issue Sep 12, 2019 · 3 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Sep 12, 2019

Bugzilla Link 43300
Resolution FIXED
Resolved on Sep 13, 2019 08:28
Version unspecified
OS Linux
CC @mclow

Extended Description

Constructing an object of type std::ios_base::Init is supposed to have no effect when the IO streams have already been initialized. In libc++, that is not the case.

Testcase:

#include

int main() {
std::cout << "hello, " << std::boolalpha;
std::ios_base::Init init_streams;
std::cout << true << " world!";
}

... should print "hello true world!" but with libc++ prints "hello 1 world!".

This also presumably means that a multithreaded program that constructs an Init object has a data race. This seems straightforward to fix by adding a static one-time initialization guard to the iso_base::Init constructor.

It might also be reasonable to maintain an atomic count of the number of extant Init objects so that the flushes in the destructor are only run when the last one is destroyed, as [ios.init]/4 requires. I think that the current destructor behavior might even result in observable nonconformance in programs that call cout.rdbuf(stream) and observe when stream sees writes.

@zygoloid
Copy link
Mannequin Author

zygoloid mannequin commented Sep 12, 2019

assigned to @mclow

@mclow
Copy link
Contributor

mclow commented Sep 12, 2019

Yeah, we don't actually check to see if Init has been called before.
Apparently no one does that.

@mclow
Copy link
Contributor

mclow commented Sep 13, 2019

Fixed in revision 371864.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

No branches or pull requests

1 participant