Skip to content

Commit c83fbfd

Browse files
<vector>: Avoid a compiler warning with Defect Report P2280R4 (#5550)
1 parent fa1448d commit c83fbfd

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

stl/inc/vector

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3195,7 +3195,10 @@ public:
31953195
_NODISCARD _CONSTEXPR20 size_type max_size() const noexcept {
31963196
constexpr auto _Diff_max = static_cast<size_type>(_STD _Max_limit<difference_type>());
31973197
const size_type _Ints_max = this->_Myvec.max_size();
3198-
if (_Ints_max > _Diff_max / _VBITS) { // max_size bound by difference_type limits
3198+
3199+
// Use a const bool to avoid warning C4127 "conditional expression is constant" with Defect Report P2280R4
3200+
const bool _Would_overflow = _Ints_max > _Diff_max / _VBITS;
3201+
if (_Would_overflow) { // max_size bound by difference_type limits
31993202
return _Diff_max;
32003203
}
32013204

0 commit comments

Comments
 (0)