Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <complex> |
| 10 | |
| 11 | #include <complex> |
| 12 | #include <cassert> |
| 13 | |
Marshall Clow | 7fc6a55 | 2019-05-31 18:35:30 +0000 | [diff] [blame] | 14 | #include "test_macros.h" |
| 15 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 16 | template <class T> |
| 17 | void |
| 18 | test() |
| 19 | { |
| 20 | std::complex<T> z; |
| 21 | T* a = (T*)&z; |
| 22 | assert(0 == z.real()); |
| 23 | assert(0 == z.imag()); |
| 24 | assert(a[0] == z.real()); |
| 25 | assert(a[1] == z.imag()); |
| 26 | a[0] = 5; |
| 27 | a[1] = 6; |
| 28 | assert(a[0] == z.real()); |
| 29 | assert(a[1] == z.imag()); |
| 30 | } |
| 31 | |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 32 | int main(int, char**) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 33 | { |
| 34 | test<float>(); |
| 35 | test<double>(); |
| 36 | test<long double>(); |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 37 | |
| 38 | return 0; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 39 | } |