Skip to content

Commit b7cec2d

Browse files
chrisncllvmbot
authored andcommitted
[clang] Define ATOMIC_FLAG_INIT correctly for C++. (llvm#97534)
(cherry picked from commit 4bb3a1e)
1 parent 518cef7 commit b7cec2d

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

clang/docs/ReleaseNotes.rst

+3
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,9 @@ Bug Fixes in This Version
891891
- Fixed an assertion failure when a template non-type parameter contains
892892
an invalid expression.
893893

894+
- Fixed the definition of ``ATOMIC_FLAG_INIT`` in ``<stdatomic.h>`` so it can
895+
be used in C++.
896+
894897
Bug Fixes to Compiler Builtins
895898
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
896899

clang/lib/Headers/stdatomic.h

+4
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,11 @@ typedef _Atomic(uintmax_t) atomic_uintmax_t;
172172

173173
typedef struct atomic_flag { atomic_bool _Value; } atomic_flag;
174174

175+
#ifdef __cplusplus
176+
#define ATOMIC_FLAG_INIT {false}
177+
#else
175178
#define ATOMIC_FLAG_INIT { 0 }
179+
#endif
176180

177181
/* These should be provided by the libc implementation. */
178182
#ifdef __cplusplus

clang/test/Headers/stdatomic.c

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// RUN: %clang_cc1 -std=c11 -E %s | FileCheck %s
22
// RUN: %clang_cc1 -std=c11 -fms-compatibility -E %s | FileCheck %s
3+
// RUN: %clang_cc1 -std=c11 %s -verify
4+
// RUN: %clang_cc1 -x c++ -std=c++11 %s -verify
5+
// expected-no-diagnostics
36
#include <stdatomic.h>
47

58
int bool_lock_free = ATOMIC_BOOL_LOCK_FREE;
@@ -31,3 +34,5 @@ int llong_lock_free = ATOMIC_LLONG_LOCK_FREE;
3134

3235
int pointer_lock_free = ATOMIC_POINTER_LOCK_FREE;
3336
// CHECK: pointer_lock_free = {{ *[012] *;}}
37+
38+
atomic_flag f = ATOMIC_FLAG_INIT;

0 commit comments

Comments
 (0)