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 // This test ensures that std::memory_order has the same size under all
10 // standard versions to make sure we're not breaking the ABI. This is
11 // relevant because std::memory_order is a scoped enumeration in C++20,
12 // but an unscoped enumeration pre-C++20.
13 //
14 // See PR40977 for details.
15 
16 #include <atomic>
17 #include <type_traits>
18 
19 #include "test_macros.h"
20 
21 
22 enum cpp17_memory_order {
23   cpp17_memory_order_relaxed, cpp17_memory_order_consume, cpp17_memory_order_acquire,
24   cpp17_memory_order_release, cpp17_memory_order_acq_rel, cpp17_memory_order_seq_cst
25 };
26 
27 static_assert((std::is_same<std::underlying_type<cpp17_memory_order>::type,
28                             std::underlying_type<std::memory_order>::type>::value),
29   "std::memory_order should have the same underlying type as a corresponding "
30   "unscoped enumeration would. Otherwise, our ABI changes from C++17 to C++20.");
31 
main(int,char **)32 int main(int, char**) {
33   return 0;
34 }
35