<vector>: Avoid a compiler warning with Defect Report P2280R4#5550
<vector>: Avoid a compiler warning with Defect Report P2280R4#5550StephanTLavavej merged 3 commits intomicrosoft:mainfrom
<vector>: Avoid a compiler warning with Defect Report P2280R4#5550Conversation
|
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. |
davidmrdavid
left a comment
There was a problem hiding this comment.
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 asconstand that causes "trial evaluation" to happen. With WG21-P2280R4,_Ints_maxis 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 booland 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.)