Skip to content

Commit 8060dc4

Browse files
authored
Throw runtime error for range with last == numeric_limits<T>::max() (#1181)
1 parent 4159905 commit 8060dc4

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

include/cpp2util.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,8 +2307,15 @@ class range
23072307
, last{ l }
23082308
{
23092309
// Represent all ranges as half-open; after this we can forget the flag
2310-
if (include_last) {
2311-
++last;
2310+
if (include_last) {
2311+
if constexpr (std::integral<TT>) {
2312+
if (last == std::numeric_limits<TT>::max()) {
2313+
throw std::runtime_error(
2314+
"range with last == numeric_limits<T>::max() will "
2315+
"overflow");
2316+
}
2317+
}
2318+
++last;
23122319
}
23132320
}
23142321

0 commit comments

Comments
 (0)