| 1 |
// { dg-do compile { target c++20 } } |
| 2 |
|
| 3 |
// Copyright (C) 2018-2025 Free Software Foundation, Inc. |
| 4 |
// |
| 5 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 6 |
// software; you can redistribute it and/or modify it under the |
| 7 |
// terms of the GNU General Public License as published by the |
| 8 |
// Free Software Foundation; either version 3, or (at your option) |
| 9 |
// any later version. |
| 10 |
|
| 11 |
// This library is distributed in the hope that it will be useful, |
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
// GNU General Public License for more details. |
| 15 |
|
| 16 |
// You should have received a copy of the GNU General Public License along |
| 17 |
// with this library; see the file COPYING3. If not see |
| 18 |
// <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
#include <complex> |
| 21 |
#include <testsuite_common_types.h> |
| 22 |
|
| 23 |
namespace __gnu_test |
| 24 |
{ |
| 25 |
// Test constexpr symmetric complex @ real, real @ complex, complex @ complex. |
| 26 |
template<typename _Tp> |
| 27 |
void |
| 28 |
test_operators() |
| 29 |
{ |
| 30 |
constexpr std::complex<_Tp> a{1, 2}; |
| 31 |
constexpr std::complex<_Tp> b{3, 4}; |
| 32 |
constexpr _Tp c = 5; |
| 33 |
|
| 34 |
constexpr auto w [[maybe_unused]] = +a; |
| 35 |
constexpr auto z [[maybe_unused]] = -a; |
| 36 |
|
| 37 |
constexpr auto apc [[maybe_unused]] = a + c; |
| 38 |
constexpr auto amc [[maybe_unused]] = a - c; |
| 39 |
constexpr auto atc [[maybe_unused]] = a * c; |
| 40 |
constexpr auto adc [[maybe_unused]] = a / c; |
| 41 |
|
| 42 |
constexpr auto cpa [[maybe_unused]] = c + a; |
| 43 |
constexpr auto cma [[maybe_unused]] = c - a; |
| 44 |
constexpr auto cta [[maybe_unused]] = c * a; |
| 45 |
constexpr auto cda [[maybe_unused]] = c / a; |
| 46 |
|
| 47 |
constexpr auto apb [[maybe_unused]] = a + b; |
| 48 |
constexpr auto amb [[maybe_unused]] = a - b; |
| 49 |
constexpr auto atb [[maybe_unused]] = a * b; |
| 50 |
constexpr auto adb [[maybe_unused]] = a / b; |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
int main() |
| 55 |
{ |
| 56 |
__gnu_test::test_operators<float>(); |
| 57 |
__gnu_test::test_operators<double>(); |
| 58 |
#ifndef __LONG_DOUBLE_IBM128__ // IBM128 format is not constexpr foldable |
| 59 |
__gnu_test::test_operators<long double>(); |
| 60 |
#endif |
| 61 |
|
| 62 |
return 0; |
| 63 |
} |