Skip to content

Commit df7ef23

Browse files
committed
refactor: work around sign compare warning
1 parent 52a2798 commit df7ef23

File tree

6 files changed

+16
-4
lines changed

6 files changed

+16
-4
lines changed

include/cpp2util.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,15 +398,16 @@ auto assert_not_null(auto&& p CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> declty
398398
//
399399
auto assert_in_bounds(auto&& x, auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto)
400400
requires (std::is_integral_v<CPP2_TYPEOF(arg)> &&
401-
requires { std::ssize(x); x[arg]; std::begin(x) + 2; })
401+
requires { std::size(x); std::ssize(x); x[arg]; std::begin(x) + 2; })
402402
{
403-
Bounds.expects(0 <= arg && arg < std::ssize(x), "out of bounds access attempt detected" CPP2_SOURCE_LOCATION_ARG);
403+
Bounds.expects(0 <= arg && arg < [&]() -> auto {
404+
if constexpr (std::is_signed_v<CPP2_TYPEOF(arg)>) { return std::ssize(x); }
405+
else { return std::size(x); }
406+
}(), "out of bounds access attempt detected" CPP2_SOURCE_LOCATION_ARG);
404407
return CPP2_FORWARD(x) [ CPP2_FORWARD(arg) ];
405408
}
406409

407410
auto assert_in_bounds(auto&& x, auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto)
408-
requires (!(std::is_integral_v<CPP2_TYPEOF(arg)> &&
409-
requires { std::ssize(x); x[arg]; std::begin(x) + 2; }))
410411
{
411412
return CPP2_FORWARD(x) [ CPP2_FORWARD(arg) ];
412413
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
clang version 16.0.6 (https://github.com/llvm/llvm-project.git 7cbf1a2591520c2491aa35339f227775f4d3adf6)
2+
Target: x86_64-pc-linux-gnu
3+
Thread model: posix
4+
InstalledDir: /home/johel/root/clang/bin
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Bounds safety violation: out of bounds access attempt detected
2+
libc++abi: terminating
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Bounds safety violation
2+
libc++abi: terminating
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Contract violation: fill: value must contain at least count elements
2+
libc++abi: terminating
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello Fred with UFCS!

0 commit comments

Comments
 (0)