Use _STL_INTERNAL_STATIC_ASSERT(false)
when appropriate
#4624
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Followup to #4591.
This was prompted by VSO-2045281 "[RWC][prod/fe][Regression] Taichi and Root failed with error G030630B7: static assertion failed: Unexpected size", although it doesn't attempt to completely fix those failures in our Real World Code test suite. (It appears that these projects are using unsupported compilers - i.e. non-MSVC/Clang/CUDA/IntelliSense - to parse our STL headers, and these compilers haven't implemented CWG-2518.)
Some occurrences of
static_assert(false, "message")
are enforcing requirements for users, providing nice messages (ideally with Standard citations). However, many occurrences were checking for "can't happen" scenarios, i.e. damaged logic in the STL itself. We should use_STL_INTERNAL_STATIC_ASSERT
for such checks, as this clearly distinguishes "user was a bad kitty" from "STL was a bad kitty". (Also,_STL_INTERNAL_STATIC_ASSERT
is active only within our test suites, so it results in a microscopic throughput improvement for users.)I reviewed all of the following occurrences (i.e. not an unthinking search-and-replace):
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected size
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected strategy
byteswap()
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected size
~_Mini_ptr()
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected strategy
vector::_Construct_n()
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected number of arguments
_Float_put_desired_precision()
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected type; shouldn't be float
_Chrono_formatter::_Is_valid_type()
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected type
chrono::clock_cast()
_STL_INTERNAL_STATIC_ASSERT(false); // unexpected strategy
I performed a couple of targeted cleanups along the way (we try to avoid mixing major changes with cleanups, but these aren't entangled, and they are in the same area):
static_assert
messages and add citations inuses_allocator_construction_args()
.static_assert(condition)
in one branch andstatic_assert(false)
in the other isn't super consistent.tuple
/variant
"occur exactly once" messages consistently, to avoid wrappingstatic_assert(false
.static_assert(false)
since it improves the error messages, even though other functions usestatic_assert(condition)
.