Headers: tweak inclusion condition for stdatomic.h
authorSaleem Abdulrasool <compnerd@compnerd.org>
Thu, 15 Dec 2022 20:34:04 +0000 (20:34 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Thu, 15 Dec 2022 21:50:28 +0000 (21:50 +0000)
MSVC requires that C++23 be available (_HAS_CXX23) else the entire
content is elided. Conditionalise the inclusion properly so that C/C++
code using stdatomic.h for memory_order_* constants are able to do
so without changing the C++ standard. This repairs builds of Swift and
libdispatch after ba49d39b20cc5358da28af2ac82bd336028780bc.

Differential Revision: https://reviews.llvm.org/D139266
Reviewed By: aaron.ballman, Mordante, fsb4000

clang/docs/ReleaseNotes.rst
clang/lib/Headers/stdatomic.h

index 0da79fc1a2a9a5e448d3834cd40391c3beb8d7f6..d9b44b629220d2b41e9c79a3ed84365bdcff4072 100644 (file)
@@ -199,6 +199,8 @@ Major New Features
 
 Bug Fixes
 ---------
+- ``stdatomic.h`` will use the internal declarations when targeting pre-C++-23
+  on Windows platforms as the MSVC support requires newer C++ standard.
 - Correct ``_Static_assert`` to accept the same set of extended integer
   constant expressions as is accpted in other contexts that accept them.
   This fixes `Issue 57687 <https://github.com/llvm/llvm-project/issues/57687>`_.
index 648af44f2a64174857f11ceb0ec1390d2f51948d..9093851b76cfc57b968f33a7b498838a48cb749c 100644 (file)
  *
  * Exclude the MSVC path as well as the MSVC header as of the 14.31.30818
  * explicitly disallows `stdatomic.h` in the C mode via an `#error`.  Fallback
- * to the clang resource header until that is fully supported.
+ * to the clang resource header until that is fully supported.  The
+ * `stdatomic.h` header requires C++ 23 or newer.
  */
 #if __STDC_HOSTED__ &&                                                         \
-    __has_include_next(<stdatomic.h>) && !(defined(_MSC_VER) && !defined(__cplusplus))
+    __has_include_next(<stdatomic.h>) &&                                       \
+    !(defined(_MSC_VER) && defined(__cplusplus) && __cplusplus < 202002L)
 # include_next <stdatomic.h>
 #else