xref: /llvm-project/libcxx/test/std/numerics/complex.number/complex.tuple/get.verify.cpp (revision 2ea5d167ae43bed5a511d5d819ae7c52cc76ec5c)
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 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
10 
11 // <complex>
12 
13 //   template<size_t I, class T>
14 //     constexpr T& get(complex<T>&) noexcept;
15 //   template<size_t I, class T>
16 //     constexpr T&& get(complex<T>&&) noexcept;
17 //   template<size_t I, class T>
18 //     constexpr const T& get(const complex<T>&) noexcept;
19 //   template<size_t I, class T>
20 //     constexpr const T&& get(const complex<T>&&) noexcept;
21 
22 #include <cassert>
23 #include <complex>
24 #include <utility>
25 
26 template <typename T>
test()27 void test() {
28   using C = std::complex<T>;
29 
30   // &
31   {
32     C c{T{27}, T{28}};
33     // expected-error-re@*:* 3{{static assertion failed {{.*}}Index value is out of range.}}
34     std::get<3>(c);
35   }
36   // &&
37   {
38     C c{T{27}, T{28}};
39     // expected-error-re@*:* 3 {{static assertion failed {{.*}}Index value is out of range.}}
40     std::get<3>(std::move(c));
41   }
42   // const &
43   {
44     const C c{T{27}, T{28}};
45     // expected-error-re@*:* 3 {{static assertion failed {{.*}}Index value is out of range.}}
46     std::get<3>(c);
47   }
48   // const &&
49   {
50     const C c{T{27}, T{28}};
51     // expected-error-re@*:* 3 {{static assertion failed {{.*}}Index value is out of range.}}
52     std::get<3>(std::move(c));
53   }
54 }
55 
test()56 void test() {
57   test<float>();
58   test<double>();
59   test<long double>();
60 }
61