Skip to content

Commit 5c135a1

Browse files
committed
Update abs test
1 parent 119292c commit 5c135a1

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

libcxx/test/std/numerics/c.math/abs.pass.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,29 @@ struct correct_size_int {
2020
};
2121

2222
template <class Source, class Result>
23-
void test_abs() {
24-
Source neg_val = -5;
25-
Source pos_val = 5;
26-
Result res = 5;
23+
TEST_CONSTEXPR_CXX23 void test_abs() {
24+
TEST_CONSTEXPR_CXX23 Source neg_val = -5;
25+
TEST_CONSTEXPR_CXX23 Source pos_val = 5;
26+
TEST_CONSTEXPR_CXX23 Result res = 5;
2727

2828
ASSERT_SAME_TYPE(decltype(std::abs(neg_val)), Result);
29-
30-
assert(std::abs(neg_val) == res);
31-
assert(std::abs(pos_val) == res);
29+
#if TEST_STD_VER >= 23
30+
static_assert(std::abs(neg_val) == res);
31+
static_assert(std::abs(pos_val) == res);
32+
#else
33+
assert(std::abs(neg_val) == res);
34+
assert(std::abs(pos_val) == res);
35+
#endif
3236
}
3337

34-
void test_big() {
35-
long long int big_value = std::numeric_limits<long long int>::max(); // a value too big for ints to store
36-
long long int negative_big_value = -big_value;
37-
assert(std::abs(negative_big_value) == big_value); // make sure it doesn't get casted to a smaller type
38+
TEST_CONSTEXPR_CXX23 void test_big() {
39+
TEST_CONSTEXPR_CXX23 long long int big_value = std::numeric_limits<long long int>::max(); // a value too big for ints to store
40+
TEST_CONSTEXPR_CXX23 long long int negative_big_value = -big_value;
41+
#if TEST_STD_VER >= 23
42+
static_assert(std::abs(negative_big_value) == big_value); // make sure it doesn't get casted to a smaller type
43+
#else
44+
assert(std::abs(negative_big_value) == big_value); // make sure it doesn't get casted to a smaller type
45+
#endif
3846
}
3947

4048
// The following is helpful to keep in mind:

0 commit comments

Comments
 (0)