[libcxx-commits] [libcxx] 8ab82a2 - [libc++] Add a test case for std::bit_cast with std::complex (#97751)

via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jul 8 13:19:28 PDT 2024


Author: Louis Dionne
Date: 2024-07-08T16:19:24-04:00
New Revision: 8ab82a2dc308c27fbdd0a87b5be7dddc623f1b0e

URL: https://github.com/llvm/llvm-project/commit/8ab82a2dc308c27fbdd0a87b5be7dddc623f1b0e
DIFF: https://github.com/llvm/llvm-project/commit/8ab82a2dc308c27fbdd0a87b5be7dddc623f1b0e.diff

LOG: [libc++] Add a test case for std::bit_cast with std::complex (#97751)

This is extracted from #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.

Added: 
    libcxx/test/std/numerics/complex.number/complex/bit_cast.pass.cpp

Modified: 
    

Removed: 
    


################################################################################
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 <bit>
+#include <complex>
+
+template <class T>
+constexpr void test() {
+  using Complex                       = std::complex<T>;
+  unsigned char data[sizeof(Complex)] = {0};
+
+  [[maybe_unused]] Complex c = std::bit_cast<Complex>(data);
+}
+
+constexpr bool test_all() {
+  test<float>();
+  test<double>();
+  test<long double>();
+  return true;
+}
+
+int main(int, char**) {
+  test_all();
+  static_assert(test_all());
+  return 0;
+}


        


More information about the libcxx-commits mailing list