[libcxx-commits] [libcxx] r356376 - [libc++] Add a test for PR40977

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Mar 18 08:40:49 PDT 2019


Author: ldionne
Date: Mon Mar 18 08:40:49 2019
New Revision: 356376

URL: http://llvm.org/viewvc/llvm-project?rev=356376&view=rev
Log:
[libc++] Add a test for PR40977

Even though the header makes the exact same check since https://llvm.org/D59063,
the headers could conceivably change in the future and introduce a bug.

Added:
    libcxx/trunk/test/libcxx/atomics/atomics.order/
    libcxx/trunk/test/libcxx/atomics/atomics.order/memory_order.underlying_type.pass.cpp

Added: libcxx/trunk/test/libcxx/atomics/atomics.order/memory_order.underlying_type.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/atomics/atomics.order/memory_order.underlying_type.pass.cpp?rev=356376&view=auto
==============================================================================
--- libcxx/trunk/test/libcxx/atomics/atomics.order/memory_order.underlying_type.pass.cpp (added)
+++ libcxx/trunk/test/libcxx/atomics/atomics.order/memory_order.underlying_type.pass.cpp Mon Mar 18 08:40:49 2019
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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: libcpp-has-no-threads
+
+// This test ensures that std::memory_order has the same size under all
+// standard versions to make sure we're not breaking the ABI. This is
+// relevant because std::memory_order is a scoped enumeration in C++20,
+// but an unscoped enumeration pre-C++20.
+//
+// See PR40977 for details.
+
+#include <atomic>
+#include <type_traits>
+
+
+enum cpp17_memory_order {
+  cpp17_memory_order_relaxed, cpp17_memory_order_consume, cpp17_memory_order_acquire,
+  cpp17_memory_order_release, cpp17_memory_order_acq_rel, cpp17_memory_order_seq_cst
+};
+
+static_assert((std::is_same<std::underlying_type<cpp17_memory_order>::type,
+                            std::underlying_type<std::memory_order>::type>::value),
+  "std::memory_order should have the same underlying type as a corresponding "
+  "unscoped enumeration would. Otherwise, our ABI changes from C++17 to C++20.");
+
+int main(int, char**) {
+  return 0;
+}




More information about the libcxx-commits mailing list