diff --git a/libcxx/test/std/numerics/complex.number/complex/bit_cast.pass.cpp b/libcxx/test/std/numerics/complex.number/complex/bit_cast.pass.cpp new file mode 100644 index 00000000000000..c35d4d6c632955 --- /dev/null +++ b/libcxx/test/std/numerics/complex.number/complex/bit_cast.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// Make sure that std::bit_cast works with std::complex. Test case extracted from +// https://github.com/llvm/llvm-project/issues/94620. + +#include +#include + +template +constexpr void test() { + using Complex = std::complex; + unsigned char data[sizeof(Complex)] = {0}; + + [[maybe_unused]] Complex c = std::bit_cast(data); +} + +constexpr bool test_all() { + test(); + test(); + test(); + return true; +} + +int main(int, char**) { + test_all(); + static_assert(test_all()); + return 0; +}