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

StringMaker for vector<bool>::reference and vector<bool>::const_reference #2391

Closed

Conversation

schallerr
Copy link
Contributor

Description

Currently, stringification of a vector<bool>::reference yields "0" and "1" instead of "false" and "true".

For vector<bool>::const_reference, the behavior differs between the STL implementations:
For libc++, it's printed as "0" and "1", while for MSVC and libstdc++, "false" and "true" are printed.

This PR fixes both, so "false" and "true" is printed consistently.

@codecov
Copy link

codecov bot commented Mar 13, 2022

Codecov Report

Merging #2391 (4fad3d2) into devel (81f612c) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##            devel    #2391   +/-   ##
=======================================
  Coverage   91.02%   91.02%           
=======================================
  Files         154      154           
  Lines        7290     7293    +3     
=======================================
+ Hits         6635     6638    +3     
  Misses        655      655           

@horenmar
Copy link
Member

So, I don't see an issue with the code, but I have a bigger question: why, and is it worth it?

Generally I don't like adding new specializations to StringMaker that are enabled by default, because it increases the compilation cost of every single assertion -- in fact, if I started from scratch, there would likely be less of them. Given the fact that std::vector<bool> is not used too often, the question has to be whether the specialization is worth it.

@schallerr
Copy link
Contributor Author

I'm not having a strong opinion about vector<bool>::reference, I just found it nice that it's printed consistently with printing bool.

For vector<bool>::const_reference, however, I'm facing the issue that it's currently inconsistent across standard libraries. While for some it'll print "0/1", for others "false/true".

That's currently happening in practice for #2319, where the approval tests are giving different output for Clang on Mac, so I'm forced to use some replacement for std::vector. I could also add a specialization for StringMaker<vector<bool>::const_reference> to the test itself, but I guess that could in the future lead to ODR violations.

@horenmar
Copy link
Member

For #2319 you can put the problematic tests into their own TEST_CASE with the [approvals] tag. We are already doing this for tests that cannot have cross-platform output no matter what we do, e.g. REQUIRE( errno == 0 ) changes between platforms due to errno being a macro.

@schallerr schallerr closed this Jul 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants