[libcxx-commits] [PATCH] D97044: [libc++] [C++2b] [P0943] Add stdatomic.h header.

Hubert Tong via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Feb 7 20:51:47 PST 2022


hubert.reinterpretcast added inline comments.


================
Comment at: libcxx/include/stdatomic.h:223-231
+#endif // defined(__cplusplus) && _LIBCPP_STD_VER > 20
+
+// If we are not being compiled as C++, we include the next <stdatomic.h> on the path
+// to avoid hijacking the header when compiling as C11.
+#if !defined(__cplusplus)
+# if __has_include_next(<stdatomic.h>)
+#   include_next <stdatomic.h>
----------------
This is what I meant (since it reflects the status quo where Clang has a `stdatomic.h` that "works" in C++ mode (except that `<atomic>` and anything that uses it cannot be used after the `stdatomic.h` inclusion).

Maybe the message should be updated:
```
#ifdef kill_dependency
# error C++ standard library is incompatible with <stdatomic.h>
#endif
```

Aside: The `#else` comment style above is not my usual preference (I like using the negation), but it seems to be the more common style in libc++ (although there are examples of both styles).


================
Comment at: libcxx/include/stdatomic.h:124
+
+#ifdef __cplusplus
+
----------------
ldionne wrote:
> hubert.reinterpretcast wrote:
> > Please see thread re: unintended consequences of enabling C++ `stdatomic.h` for applications currently using the C one with Clang:
> > https://llvm.discourse.group/t/compiling-with-built-in-stdatomic-vs-stdatomic-h/6225
> After reading the thread, I assume what you mean is that we should be `#include_next`ing the platform `<stdatomic.h>` if we're in C++ < 23?
Yes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97044/new/

https://reviews.llvm.org/D97044



More information about the libcxx-commits mailing list