-
Notifications
You must be signed in to change notification settings - Fork 1.6k
<vector>
: Avoid a compiler warning with Defect Report P2280R4
#5550
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
<vector>
: Avoid a compiler warning with Defect Report P2280R4
#5550
Conversation
Can the usual way work: extract condition to |
I believe that extracting the condition to a |
I think it is still both cleaner way to avoid the warning, at it is almost idiomatic way to do so, and better debug codegen |
I've pushed that change, since I agree that it's clearer. However, I don't see how this will affect debug codegen. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, soft suggestion to improve comment
Please see: https://godbolt.org/z/exKhPY5KP |
Yes I was wrong. The codegen is worse! |
Per WG21-P2280R4, IIUC we can determine whether the |
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
@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.)