Index: test/std/numerics/c.math/abs.fail.cpp =================================================================== --- /dev/null +++ test/std/numerics/c.math/abs.fail.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include + +#include "test_macros.h" + +int main(int, char**) +{ + unsigned int ui = -5; + std::abs(ui); // expected-error {{call to 'abs' is ambiguous}} + + unsigned char uc = -5; + std::abs(uc); // expected-error {{call to 'abs' is ambiguous}} + + unsigned short us = -5; + std::abs(us); // expected-error {{call to 'abs' is ambiguous}} + + unsigned long ul = -5; + std::abs(ul); // expected-error {{call to 'abs' is ambiguous}} + + unsigned long long ull = -5; + std::abs(ull); // expected-error {{call to 'abs' is ambiguous}} + + return 0; +} + Index: test/std/numerics/c.math/abs.pass.cpp =================================================================== --- /dev/null +++ test/std/numerics/c.math/abs.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include +#include +#include +#include + +#include "test_macros.h" + +template +void test_abs() +{ + T neg_val = -5; + T pos_val = 5; + R res = 5; + + ASSERT_SAME_TYPE(decltype(std::abs(neg_val)), R); + + assert(std::abs(neg_val) == res); + assert(std::abs(pos_val) == res); +} + +void test_big() +{ + long long int big_value = std::numeric_limits::max(); // a value to big for ints to store + long long int negative_big_value = -big_value; + assert(std::abs(negative_big_value) == big_value); // make sure it doesnt get casted to a smaller type +} + +int main(int, char**) +{ + test_abs(); + test_abs(); + test_abs(); + test_abs::value, char, signed char + >::type, int>(); // sometimes chars are unsigned + + test_abs(); + test_abs(); + test_abs(); + + test_abs(); + test_abs(); + test_abs(); + test_abs(); + + test_abs(); + test_abs(); + test_abs(); + + test_big(); + + return 0; +} + Index: www/cxx1z_status.html =================================================================== --- www/cxx1z_status.html +++ www/cxx1z_status.html @@ -415,7 +415,7 @@ 2729Missing SFINAE on std::pair::operator=Issaquah 2732Questionable specification of path::operator/= and path::appendIssaquahComplete 2733[fund.ts.v2] gcd / lcm and boolIssaquahComplete - 2735std::abs(short), std::abs(signed char) and others should return int instead of double in order to be compatible with C++98 and CIssaquah + 2735std::abs(short), std::abs(signed char) and others should return int instead of double in order to be compatible with C++98 and CIssaquahComplete 2736nullopt_t insufficiently constrainedIssaquahComplete 2738is_constructible with void typesIssaquahComplete 2739Issue with time_point non-member subtraction with an unsigned durationIssaquahComplete