[PATCH] D130419: Use `<stdatomic.h>` with MSVC and C++
Igor Zhukov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 23 04:44:13 PDT 2022
fsb4000 created this revision.
fsb4000 added a project: clang.
Herald added a project: All.
fsb4000 requested review of this revision.
Herald added a subscriber: cfe-commits.
and use fallback only for C.
It fixes the isssue with clang-cl:
#include <stdatomic.h>
#include <stdbool.h>
#ifdef __cplusplus
#include <atomic>
using namespace std;
#endif
int main() {
atomic_bool b = true;
}
$ clang-cl /TC main.cpp
# works
$ clang-cl /TP /std:c++20 main.cpp
stdatomic.h(70,6): error: conflicting types for 'atomic_thread_fence'
void atomic_thread_fence(memory_order);
^
atomic(166,24): note: previous definition is here
extern "C" inline void atomic_thread_fence(const memory_order _Order) noexcept {
...
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
Many errors but
`<stdatomic.h>` has many macros to built-in functions.
#define atomic_thread_fence(order) __c11_atomic_thread_fence(order)
and MSVC `<atomic>` has real functions.
and the built-in functions are redefined.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D130419
Files:
clang/lib/Headers/stdatomic.h
Index: clang/lib/Headers/stdatomic.h
===================================================================
--- clang/lib/Headers/stdatomic.h
+++ clang/lib/Headers/stdatomic.h
@@ -17,7 +17,8 @@
* explicitly disallows `stdatomic.h` in the C mode via an `#error`. Fallback
* to the clang resource header until that is fully supported.
*/
-#if __STDC_HOSTED__ && __has_include_next(<stdatomic.h>) && !defined(_MSC_VER)
+#if __STDC_HOSTED__ && \
+ __has_include_next(<stdatomic.h>) && !(defined(_MSC_VER) && !defined(__cplusplus))
# include_next <stdatomic.h>
#else
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130419.447055.patch
Type: text/x-patch
Size: 629 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220723/ddde0a6f/attachment.bin>
More information about the cfe-commits
mailing list