1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <complex>
10 
11 // complex& operator+=(const complex& rhs);
12 
13 #include <complex>
14 #include <cassert>
15 
16 #include "test_macros.h"
17 
18 template <class T>
19 void
test()20 test()
21 {
22     std::complex<T> c;
23     const std::complex<T> c2(1.5, 2.5);
24     assert(c.real() == 0);
25     assert(c.imag() == 0);
26     c += c2;
27     assert(c.real() == 1.5);
28     assert(c.imag() == 2.5);
29     c += c2;
30     assert(c.real() == 3);
31     assert(c.imag() == 5);
32 
33     std::complex<T> c3;
34 
35     c3 = c;
36     std::complex<int> ic (1,1);
37     c3 += ic;
38     assert(c3.real() == 4);
39     assert(c3.imag() == 6);
40 
41     c3 = c;
42     std::complex<float> fc (1,1);
43     c3 += fc;
44     assert(c3.real() == 4);
45     assert(c3.imag() == 6);
46 }
47 
main(int,char **)48 int main(int, char**)
49 {
50     test<float>();
51     test<double>();
52     test<long double>();
53 
54   return 0;
55 }
56