[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / SemaCXX / complex-folding.cpp
blob8c56cf0e5d984b0581abf218611d1874bf635f80
1 // RUN: %clang_cc1 %s -std=c++1z -fsyntax-only -verify
2 //
3 // Test the constant folding of builtin complex numbers.
5 static_assert((0.0 + 0.0j) == (0.0 + 0.0j));
6 static_assert((0.0 + 0.0j) != (0.0 + 0.0j)); // expected-error {{static assertion}}
8 static_assert((0.0 + 0.0j) == 0.0);
9 static_assert(0.0 == (0.0 + 0.0j));
10 static_assert(0.0 == 0.0j);
11 static_assert((0.0 + 1.0j) != 0.0);
12 static_assert(1.0 != (0.0 + 0.0j));
13 static_assert(0.0 != 1.0j);
15 // Walk around the complex plane stepping between angular differences and
16 // equality.
17 static_assert((1.0 + 0.0j) == (0.0 + 0.0j)); // expected-error {{static assertion}}
18 static_assert((1.0 + 0.0j) == (1.0 + 0.0j));
19 static_assert((1.0 + 1.0j) == (1.0 + 0.0j)); // expected-error {{static assertion}}
20 static_assert((1.0 + 1.0j) == (1.0 + 1.0j));
21 static_assert((0.0 + 1.0j) == (1.0 + 1.0j)); // expected-error {{static assertion}}
22 static_assert((0.0 + 1.0j) == (0.0 + 1.0j));
23 static_assert((-1.0 + 1.0j) == (0.0 + 1.0j)); // expected-error {{static assertion}}
24 static_assert((-1.0 + 1.0j) == (-1.0 + 1.0j));
25 static_assert((-1.0 + 0.0j) == (-1.0 + 1.0j)); // expected-error {{static assertion}}
26 static_assert((-1.0 + 0.0j) == (-1.0 + 0.0j));
27 static_assert((-1.0 - 1.0j) == (-1.0 + 0.0j)); // expected-error {{static assertion}}
28 static_assert((-1.0 - 1.0j) == (-1.0 - 1.0j));
29 static_assert((0.0 - 1.0j) == (-1.0 - 1.0j)); // expected-error {{static assertion}}
30 static_assert((0.0 - 1.0j) == (0.0 - 1.0j));
31 static_assert((1.0 - 1.0j) == (0.0 - 1.0j)); // expected-error {{static assertion}}
32 static_assert((1.0 - 1.0j) == (1.0 - 1.0j));
34 // Test basic mathematical folding of both complex and real operands.
35 static_assert(((1.0 + 0.5j) + (0.25 - 0.75j)) == (1.25 - 0.25j));
36 static_assert(((1.0 + 0.5j) + 0.25) == (1.25 + 0.5j));
37 static_assert((1.0 + (0.25 - 0.75j)) == (1.25 - 0.75j));
39 static_assert(((1.0 + 0.5j) - (0.25 - 0.75j)) == (0.75 + 1.25j));
40 static_assert(((1.0 + 0.5j) - 0.25) == (0.75 + 0.5j));
41 static_assert((1.0 - (0.25 - 0.75j)) == (0.75 + 0.75j));
43 static_assert(((1.25 + 0.5j) * (0.25 - 0.75j)) == (0.6875 - 0.8125j));
44 static_assert(((1.25 + 0.5j) * 0.25) == (0.3125 + 0.125j));
45 static_assert((1.25 * (0.25 - 0.75j)) == (0.3125 - 0.9375j));
47 static_assert(((1.25 + 0.5j) / (0.25 - 0.75j)) == (-0.1 + 1.7j));
48 static_assert(((1.25 + 0.5j) / 0.25) == (5.0 + 2.0j));
49 static_assert((1.25 / (0.25 - 0.75j)) == (0.5 + 1.5j));
51 // Test that infinities are preserved, don't turn into NaNs, and do form zeros
52 // when the divisor.
53 static_assert(__builtin_isinf_sign(__real__((__builtin_inf() + 1.0j) * 1.0)) == 1);
54 static_assert(__builtin_isinf_sign(__imag__((1.0 + __builtin_inf() * 1.0j) * 1.0)) == 1);
55 static_assert(__builtin_isinf_sign(__real__(1.0 * (__builtin_inf() + 1.0j))) == 1);
56 static_assert(__builtin_isinf_sign(__imag__(1.0 * (1.0 + __builtin_inf() * 1.0j))) == 1);
58 static_assert(__builtin_isinf_sign(__real__((__builtin_inf() + 1.0j) * (1.0 + 1.0j))) == 1);
59 static_assert(__builtin_isinf_sign(__real__((1.0 + 1.0j) * (__builtin_inf() + 1.0j))) == 1);
60 static_assert(__builtin_isinf_sign(__real__((__builtin_inf() + 1.0j) * (__builtin_inf() + 1.0j))) == 1);
62 static_assert(__builtin_isinf_sign(__real__((1.0 + __builtin_inf() * 1.0j) * (1.0 + 1.0j))) == -1);
63 static_assert(__builtin_isinf_sign(__imag__((1.0 + __builtin_inf() * 1.0j) * (1.0 + 1.0j))) == 1);
64 static_assert(__builtin_isinf_sign(__real__((1.0 + 1.0j) * (1.0 + __builtin_inf() * 1.0j))) == -1);
65 static_assert(__builtin_isinf_sign(__imag__((1.0 + 1.0j) * (1.0 + __builtin_inf() * 1.0j))) == 1);
67 static_assert(__builtin_isinf_sign(__real__((1.0 + __builtin_inf() * 1.0j) * (1.0 + __builtin_inf() * 1.0j))) == -1);
68 static_assert(__builtin_isinf_sign(__real__((__builtin_inf() + __builtin_inf() * 1.0j) * (__builtin_inf() + __builtin_inf() * 1.0j))) == -1);
70 static_assert(__builtin_isinf_sign(__real__((__builtin_inf() + 1.0j) / (1.0 + 1.0j))) == 1);
71 static_assert(__builtin_isinf_sign(__imag__(1.0 + (__builtin_inf() * 1.0j) / (1.0 + 1.0j))) == 1);
72 static_assert(__builtin_isinf_sign(__imag__((__builtin_inf() + __builtin_inf() * 1.0j) / (1.0 + 1.0j))) == 1);
73 static_assert(__builtin_isinf_sign(__real__((__builtin_inf() + 1.0j) / 1.0)) == 1);
74 static_assert(__builtin_isinf_sign(__imag__(1.0 + (__builtin_inf() * 1.0j) / 1.0)) == 1);
75 static_assert(__builtin_isinf_sign(__imag__((__builtin_inf() + __builtin_inf() * 1.0j) / 1.0)) == 1);
77 static_assert(((1.0 + 1.0j) / (__builtin_inf() + 1.0j)) == (0.0 + 0.0j));
78 static_assert(((1.0 + 1.0j) / (1.0 + __builtin_inf() * 1.0j)) == (0.0 + 0.0j));
79 static_assert(((1.0 + 1.0j) / (__builtin_inf() + __builtin_inf() * 1.0j)) == (0.0 + 0.0j));
80 static_assert(((1.0 + 1.0j) / __builtin_inf()) == (0.0 + 0.0j));
82 static_assert(__builtin_isinf_sign(__real__((1.0 + 1.0j) / (0.0 + 0.0j))) == 1);
83 static_assert(__builtin_isinf_sign(__real__((1.0 + 1.0j) / 0.0)) == 1);
85 static_assert(__builtin_isinf_sign(__real__((__builtin_inf() + 1.0j) / (0.0 + 0.0j))) == 1);
86 static_assert(__builtin_isinf_sign(__imag__((1.0 + __builtin_inf() * 1.0j) / (0.0 + 0.0j))) == 1);
87 static_assert(__builtin_isinf_sign(__imag__((__builtin_inf() + __builtin_inf() * 1.0j) / (0.0 + 0.0j))) == 1);
88 static_assert(__builtin_isinf_sign(__real__((__builtin_inf() + 1.0j) / 0.0)) == 1);
89 static_assert(__builtin_isinf_sign(__imag__((1.0 + __builtin_inf() * 1.0j) / 0.0)) == 1);
90 static_assert(__builtin_isinf_sign(__imag__((__builtin_inf() + __builtin_inf() * 1.0j) / 0.0)) == 1);