| 1 | // Copyright (C) 2020-2025 Free Software Foundation, Inc. |
| 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 | // expensive: * [1-9] * * |
| 19 | #include "bits/main.h" |
| 20 | |
| 21 | enum unscoped_enum |
| 22 | { foo }; |
| 23 | |
| 24 | enum class scoped_enum |
| 25 | { bar }; |
| 26 | |
| 27 | struct convertible |
| 28 | { |
| 29 | operator int(); |
| 30 | operator float(); |
| 31 | }; |
| 32 | |
| 33 | template <typename V> |
| 34 | void |
| 35 | test() |
| 36 | { |
| 37 | using T = typename V::value_type; |
| 38 | VERIFY(std::experimental::is_simd_v<V>); |
| 39 | VERIFY(std::experimental::is_abi_tag_v<typename V::abi_type>); |
| 40 | |
| 41 | { |
| 42 | V x; // not initialized |
| 43 | x = V{}; // default broadcasts 0 |
| 44 | COMPARE(x, V(0)); |
| 45 | COMPARE(x, V()); |
| 46 | COMPARE(x, V{}); |
| 47 | x = V(); // default broadcasts 0 |
| 48 | COMPARE(x, V(0)); |
| 49 | COMPARE(x, V()); |
| 50 | COMPARE(x, V{}); |
| 51 | x = 0; |
| 52 | COMPARE(x, V(0)); |
| 53 | COMPARE(x, V()); |
| 54 | COMPARE(x, V{}); |
| 55 | |
| 56 | for (std::size_t i = 0; i < V::size(); ++i) |
| 57 | { |
| 58 | COMPARE(T(x[i]), T(0)) << "i = " << i; |
| 59 | COMPARE(x[i], T(0)) << "i = " << i; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | V x = 3; |
| 64 | V y = T(0); |
| 65 | for (std::size_t i = 0; i < V::size(); ++i) |
| 66 | { |
| 67 | COMPARE(x[i], T(3)) << "i = " << i; |
| 68 | COMPARE(y[i], T(0)) << "i = " << i; |
| 69 | } |
| 70 | y = 3; |
| 71 | COMPARE(x, y); |
| 72 | |
| 73 | VERIFY(!(is_substitution_failure<V&, unscoped_enum, assignment>) ); |
| 74 | VERIFY((is_substitution_failure<V&, scoped_enum, assignment>) ); |
| 75 | COMPARE((is_substitution_failure<V&, convertible, assignment>), |
| 76 | (!std::is_convertible<convertible, T>::value)); |
| 77 | COMPARE((is_substitution_failure<V&, long double, assignment>), |
| 78 | (sizeof(long double) > sizeof(T) || std::is_integral<T>::value)); |
| 79 | COMPARE((is_substitution_failure<V&, double, assignment>), |
| 80 | (sizeof(double) > sizeof(T) || std::is_integral<T>::value)); |
| 81 | COMPARE((is_substitution_failure<V&, float, assignment>), |
| 82 | (sizeof(float) > sizeof(T) || std::is_integral<T>::value)); |
| 83 | COMPARE((is_substitution_failure<V&, long long, assignment>), |
| 84 | (has_less_bits<T, long long>() || std::is_unsigned<T>::value)); |
| 85 | COMPARE((is_substitution_failure<V&, unsigned long long, assignment>), |
| 86 | (has_less_bits<T, unsigned long long>())); |
| 87 | COMPARE((is_substitution_failure<V&, long, assignment>), |
| 88 | (has_less_bits<T, long>() || std::is_unsigned<T>::value)); |
| 89 | COMPARE((is_substitution_failure<V&, unsigned long, assignment>), |
| 90 | (has_less_bits<T, unsigned long>())); |
| 91 | // int broadcast *always* works: |
| 92 | VERIFY(!(is_substitution_failure<V&, int, assignment>) ); |
| 93 | // uint broadcast works for any unsigned T: |
| 94 | COMPARE((is_substitution_failure<V&, unsigned int, assignment>), |
| 95 | (!std::is_unsigned<T>::value && has_less_bits<T, unsigned int>())); |
| 96 | COMPARE((is_substitution_failure<V&, short, assignment>), |
| 97 | (has_less_bits<T, short>() || std::is_unsigned<T>::value)); |
| 98 | COMPARE((is_substitution_failure<V&, unsigned short, assignment>), |
| 99 | (has_less_bits<T, unsigned short>())); |
| 100 | COMPARE((is_substitution_failure<V&, signed char, assignment>), |
| 101 | (has_less_bits<T, signed char>() || std::is_unsigned<T>::value)); |
| 102 | COMPARE((is_substitution_failure<V&, unsigned char, assignment>), |
| 103 | (has_less_bits<T, unsigned char>())); |
| 104 | } |