Skip to content

ios_base constants should have bitmask types - #3405

Merged
Stephan T. Lavavej (StephanTLavavej) merged 8 commits into
microsoft:mainfrom
fsb4000:fix3401
Feb 23, 2023
Merged

Stephan T. Lavavej (StephanTLavavej) merged 8 commits into
microsoft:mainfrom
fsb4000:fix3401

Conversation

@fsb4000

Copy link
Copy Markdown
Contributor

Fixes #3401

If I understand correctly we can't change types of the variables but we can add operators.

@fsb4000
Igor Zhukov (fsb4000) requested a review from a team as a code owner February 11, 2023 08:05
@AlexGuteniev

Copy link
Copy Markdown
Contributor

Have you considered _BITMASK_OPS macro?

Co-authored-by: Alex Guteniev 
@fsb4000

Copy link
Copy Markdown
Contributor Author

Thanks. I knew about the macro but I forgot about it.

@frederick-vs-ja

Copy link
Copy Markdown
Contributor

std::ios_base::openmode is still int. We should fix the type mismatch, see [ios.base.general].

@AlexGuteniev

Copy link
Copy Markdown
Contributor

std::ios_base::openmode is still int. We should fix the type mismatch, see [ios.base.general].

Not sure if it wouldn't be an ABI break

@fsb4000

Copy link
Copy Markdown
Contributor Author

Can we fix it?

What if a user used std::ios_base::openmode in his function. Before the type was int, and it is std::ios_base::_Openmode after.

It looks like ABI break.

I don't really understand all this about ABI break, but I remember that intmax_t was considered a very bad decision because this type is forever int64_t, because changing it to a hypothetical int128_t would be an ABI break.

@StephanTLavavej

Copy link
Copy Markdown
Member

The variables don't seem to appear on the DLL's export surface, so it might be possible to change their types. Yes, theoretically someone could have been depending on their types in their own signatures, but it would be fairly hard (especially pre-decltype). I am pretty scared to change anything in iostreams but it might be possible, and it would be simpler and better for throughput than emitting a bunch of bitmask ops (which are unfortunately widely visible).

@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) added the bug Something isn't working label Feb 11, 2023
Comment thread stl/inc/xiosbase Outdated
Comment thread tests/std/tests/P2467R1_exclusive_mode_fstreams/test.cpp Outdated
Comment thread tests/std/tests/P2467R1_exclusive_mode_fstreams/test.cpp Outdated
@StephanTLavavej

Copy link
Copy Markdown
Member

Thanks, I pushed small changes to the test.

I double-checked for changes to the release and debug DLL export surfaces, and found none. I think this is ABI-safe from a "does this affect the redist" perspective, and I think that it's unlikely to be disruptive (as I mentioned earlier, theoretically someone could have used decltype to make their own signatures depend on the types of these constants, but that is totally different from normal usage).

There is now unused enum machinery but I would prefer not to mess with that at this time (as the TRANSITION, ABI comments indicate, I once thought this affected ABI - I can't remember why).

@StephanTLavavej

Copy link
Copy Markdown
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) changed the title _Openmode,_Seekdir,_Fmtflags,_Iostate are BitmaskTypes ios_base constants should have bitmask types Feb 23, 2023
@StephanTLavavej
Stephan T. Lavavej (StephanTLavavej) merged commit bd07818 into microsoft:main Feb 23, 2023
@StephanTLavavej

Copy link
Copy Markdown
Member

Thanks for fixing this long-standing nonconformance! ✨ 😺 🎉

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

Successfully merging this pull request may close these issues.

: std::ios_base::openmode is not a bitmask type

5 participants