From ba49d39b20cc5358da28af2ac82bd336028780bc Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Mon, 25 Jul 2022 18:54:32 +0200 Subject: [PATCH] Use `` with MSVC and C++ and use fallback only for C. It fixes the isssue with clang-cl: ``` #include #include #ifdef __cplusplus #include 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 `` has many macros to built-in functions. ``` #define atomic_thread_fence(order) __c11_atomic_thread_fence(order) ``` and MSVC `` has real functions. and the built-in functions are redefined. Reviewed By: #libc, aaron.ballman, Mordante Differential Revision: https://reviews.llvm.org/D130419 --- clang/docs/ReleaseNotes.rst | 2 ++ clang/lib/Headers/stdatomic.h | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 317fd250b19333..ab2f6387492b79 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -196,6 +196,8 @@ Bug Fixes used in comparison operators. Fixes `Issue 56560 `_. - Fix that ``if consteval`` could evaluate to ``true`` at runtime because it was incorrectly constant folded. Fixes `Issue 55638 `_. +- Fixed incompatibility of Clang's ```` with MSVC ````. + Fixes `MSVC STL Issue 2862 `_. Improvements to Clang's diagnostics ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Headers/stdatomic.h b/clang/lib/Headers/stdatomic.h index 3a0b9cc056bef0..318c7ca56e418b 100644 --- a/clang/lib/Headers/stdatomic.h +++ b/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() && !defined(_MSC_VER) +#if __STDC_HOSTED__ && \ + __has_include_next() && !(defined(_MSC_VER) && !defined(__cplusplus)) # include_next #else