You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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.)
I believe that extracting the condition to a const bool would avoid the warning, since there's a special case to avoid emitting it for if (variable), but that wouldn't allow us to upgrade the branch to if constexpr, because (AFAICT) there is no actual requirement that a user allocator has a constexpr max_size() (and pre-C++11 user allocators wouldn't).
Per WG21-P2280R4, IIUC we can determine whether the max_size returns an instance-unrelated constant and use if constexpr in some cases. But such determination is a bit arcane.
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.
@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 asconst
and that causes "trial evaluation" to happen. With WG21-P2280R4,_Ints_max
is recognized as a compile-time constant, causing theif
-statement below to emit the warning.Unfortunately, the underlying
vector
'smax_size()
has to be implemented in terms of the allocator'smax_size()
, and there's no requirement that it be a compile-time constant. So we can't just boil this whole thing down to anif 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.)