<vector>
: Avoid a compiler warning with Defect Report P2280R4 by StephanTLavavej · Pull Request #5550 · microsoft/STL (original) (raw)
@Codiferous is implementing WG21-P2280R4 in MSVC. With this Defect Report implemented, MSVC emits its (extremely annoying) warning C4127 "conditional expression is constant" for vector<bool>::max_size()
, because we marked a local variable as const
and that causes "trial evaluation" to happen. With WG21-P2280R4, _Ints_max
is recognized as a compile-time constant, causing the if
-statement below to emit the warning.
Unfortunately, the underlying vector
's max_size()
has to be implemented in terms of the allocator's max_size()
, and there's no requirement that it be a compile-time constant. So we can't just boil this whole thing down to an if constexpr
.
To avoid this, we can extract the condition into a const bool
and add a comment why. C4127 has a special case to avoid warnings when a single variable is being tested.
(I am somewhat tempted to globally suppress C4127 in STL headers, but it hasn't been quite enough of a nuisance to resort to that... yet.)