]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/26_numerics/headers/cmath/dr2192.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 26_numerics / headers / cmath / dr2192.cc
CommitLineData
8d9254fc 1// Copyright (C) 2016-2020 Free Software Foundation, Inc.
37b204de
JW
2//
3// This file is part of the GNU ISO C++ Library. This library is free
4// software; you can redistribute it and/or modify it under the
5// terms of the GNU General Public License as published by the
6// Free Software Foundation; either version 3, or (at your option)
7// any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License along
15// with this library; see the file COPYING3. If not see
16// <http://www.gnu.org/licenses/>.
17
18// { dg-do compile { target c++11 } }
19
20// NB: Don't include any other headers in this file.
21// LWG 2192 requires <cmath> to declare overloads for integral types.
22#include <cmath>
23
24template<typename, typename> struct is_same { enum { value = 0 }; };
25template<typename T> struct is_same<T, T> { enum { value = 1 }; };
26
27template<typename T, typename U = T>
28 constexpr bool check(T val) {
29 return is_same<decltype(std::abs(val)), U>::value;
30 }
31
32// Unsigned arguments that promote to int are valid:
33static_assert( check<short, int>(1), "abs((short)1) returns int" );
34static_assert( check<unsigned short, int>(1),
35 "abs((unsigned short)1) returns int" );
36
37static_assert( check(1), "abs(1) returns int" );
38static_assert( check(1l), "abs(1l) returns long" );
39static_assert( check(1ll), "abs(1ll) returns long long" );