Skip to content

Commit 8ab82a2

Browse files
authored
[libc++] Add a test case for std::bit_cast with std::complex (llvm#97751)
This is extracted from llvm#94620. While libc++ doesn't have the problem described in that issue, a test case is a good idea to ensure that we don't regress this behavior in the future. This could happen for example if we decide to use `_Complex` in the implementation of `std::complex` while Clang doesn't handle bit_cast with _Complex yet.
1 parent 4b53cbb commit 8ab82a2

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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
10+
11+
// Make sure that std::bit_cast works with std::complex. Test case extracted from
12+
// https://github.com/llvm/llvm-project/issues/94620.
13+
14+
#include <bit>
15+
#include <complex>
16+
17+
template <class T>
18+
constexpr void test() {
19+
using Complex = std::complex<T>;
20+
unsigned char data[sizeof(Complex)] = {0};
21+
22+
[[maybe_unused]] Complex c = std::bit_cast<Complex>(data);
23+
}
24+
25+
constexpr bool test_all() {
26+
test<float>();
27+
test<double>();
28+
test<long double>();
29+
return true;
30+
}
31+
32+
int main(int, char**) {
33+
test_all();
34+
static_assert(test_all());
35+
return 0;
36+
}

0 commit comments

Comments
 (0)